本文主要是介绍[ACM] SDUT 2604 Thrall’s Dream,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Thrall’s Dream
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought as we had for generations. Until one day the sky rained fire, and a new enemy came upon us. We stand now upon the brink of destruction, for the Reign of Chaos has come at last.
Thrall, the warchief of the Orcish Horde, all along, he led his tribe live in the fringe of Lordaeron under the human control. In a downpour night, Thrall falls into sleep in a Orc hall at Arathi Highlands, at this moment he heard a voice:
“The sands of time have run out, son of Durotan. The cries of war echo upon the winds, the remnants of the past scar the land which is besieged once again by conflict. Heroes arise to challenge fate, and lead their brethren to battle. As mortal armies rush blindly towards their doom, The Burning Shadow comes to consume us all. You must rally the Horde, and lead your people to their destiny.
I will answer all of your questions in time, young warchief. For now, rally your warriors and prepare to leave this land, cross the sea to the distant land of Kalimdor. We will speak again. ”
Thrall believes the prophesy of Blood Raven Medivh. Three days later, He and Grom Hellscream's Warsong Clan meet in the Lordaeron coast to the distant lands of Kalimdor. But the Goblin Zeppelins they take encountered storms in the middle. Thrall and Grom falling to the islands, they want to find each other and then to Kalimdor.
For the sake of simplicity, we assume that Thrall and Grom may fall into any islands x and y, only by Thrall to find Grom or by Grom to find Thrall. Give you the map of this island, please judge that Thrall and Gtom can meet?
输入
输出
示例输入
23 21 21 33 21 22 3
示例输出
Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead
题意为给定n个点和m条有向边,问能不能任意给出两个点,至少有一条路径可以从a到b。
has[i][j],表示可以从i到达j, 对于每个点s,进行广搜,记录下has[s][ ] .
然后只要判断一下对于任意两个点都满足 has[i][j]==1||has[j][i]==1,就可以了。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
using namespace std;
const int maxn=2010;
vector<int>g[maxn];
bool has[maxn][maxn];
bool vis[maxn];
int n,m;
bool ok;void bfs(int s)
{memset(vis,0,sizeof(vis));vis[s]=1;queue<int>q;q.push(s);while(!q.empty()){int first=q.front();// cout<<"fist"<<first<<endl;q.pop();int len=g[first].size();for(int i=0;i<len;i++){int v=g[first][i];if(vis[v])continue;has[s][v]=1;q.push(v);vis[v]=1;}}
}int main()
{int t,c=1;rd(t);while(t--){ok=1;rd2(n,m);memset(has,0,sizeof(has));for(int i=0;i<maxn;i++)g[i].clear();int u,v;while(m--){rd2(u,v);g[u].push_back(v);}for(int i=1;i<=n;i++){bfs(i);}/*for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)cout<<has[i][j]<<" ";cout<<endl;}*/for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){if(!has[i][j]&&!has[j][i]){ok=0;break;}}if(ok==0)break;}if(ok)printf("Case %d: Kalimdor is just ahead\n",c++);elseprintf("Case %d: The Burning Shadow consume us all\n",c++);}return 0;
}
这篇关于[ACM] SDUT 2604 Thrall’s Dream的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!