山东省第三届ACM省赛题——Thrall’s Dream(DFS)
2016-04-14 20:09
417 查看
题目描述
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?
输入
There are multiple test case in the input file, first line is a case number T. Each test case will begin with two integers N (0 <= N < 2001) and M (0 <= M < 10001), where N is the number of islands and M is number of portal. Next M lines each line contains two integers a and b, indicated there is a portal in island a that people can go from a to b by this portal. The island numbered from 1 to N.
输出
For each test case, your output should be in one line with “Kalimdor is just ahead” (without quotes, hereinafter the same) if Thrall and Grom can meet or “The Burning Shadow consume us all” otherwise as indicated in the sample output.
示例输入
2
3 2
1 2
1 3
3 2
1 2
2 3
示例输出
Case 1: The Burning Shadow consume us all
Case 2: Kalimdor is just ahead
给定点的数量,再给几条有向边,求任意两点之间能否互相到达,这里的互相到达是指能从U到V,或能能从V到U,两种情况满足一种就行。
思路是用BFS求出能互相到达的点,然后枚举所有点看是否能满足要求
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?
输入
There are multiple test case in the input file, first line is a case number T. Each test case will begin with two integers N (0 <= N < 2001) and M (0 <= M < 10001), where N is the number of islands and M is number of portal. Next M lines each line contains two integers a and b, indicated there is a portal in island a that people can go from a to b by this portal. The island numbered from 1 to N.
输出
For each test case, your output should be in one line with “Kalimdor is just ahead” (without quotes, hereinafter the same) if Thrall and Grom can meet or “The Burning Shadow consume us all” otherwise as indicated in the sample output.
示例输入
2
3 2
1 2
1 3
3 2
1 2
2 3
示例输出
Case 1: The Burning Shadow consume us all
Case 2: Kalimdor is just ahead
给定点的数量,再给几条有向边,求任意两点之间能否互相到达,这里的互相到达是指能从U到V,或能能从V到U,两种情况满足一种就行。
思路是用BFS求出能互相到达的点,然后枚举所有点看是否能满足要求
#include <iostream> #include <vector> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> using namespace std; const int maxn=2005; typedef long long LL; vector<short> g[maxn]; bool can[maxn][maxn]; int n,m; bool judge() { for(int i=1; i<=n; ++i) for(int j=i+1; j<=n; ++j) if(!can[i][j]&&!can[j][i]) return false; return true; } void bfs(int x) { queue<short> que; que.push(x); while(!que.empty()) { short q=que.front(); que.pop(); if(q<x) { for(int i=1; i<=n; ++i) if(can[q][i]) can[x][i]=true; } else { for(int i=0; i<g[q].size(); ++i) { int y=g[q][i]; if(!can[x][y]) { can[x][y]=true; que.push(y); } } } } } int main() { int T,kase=0; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(int i=1; i<=n; ++i) g[i].clear(); memset(can,0,sizeof(can)); for(int i=1; i<=m; ++i) { int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); } for(int i=1; i<=n; ++i) bfs(i); if(judge()) printf("Case %d: Kalimdor is just ahead\n",++kase); else printf("Case %d: The Burning Shadow consume us all\n",++kase); } return 0; }
相关文章推荐
- c#---读文件
- 关于hashCode方法的作用
- tcp_tw_recycle和tcp_timestamps导致connect失败问题
- POJ1328 Radar Installation (区间选点问题,贪心)
- 一周心得
- Linux手动挂载硬盘且添加到文件
- ubuntu配置静态ip 无法解决上网的解决方案
- Android滑动(三)——scrollTo与scrollBy
- Linux中tty、pty、pts的概念区别
- Kmeans聚类c++实现
- 求两个已排序单链表中相同的数据(C语言)
- POJ1236 Network of Schools
- 不解,排名靠前那么多的人为什么抄袭我的activit博文??
- keil5软件仿真出现unknown signal解决方法
- Objective-C之KVO(键值监听)
- 从贴吧看的逆向网络协议过程逆向校园网客户端
- Qt之图形(QPainter的基本绘图)
- 阻塞队列实现生产者消费者模式
- 单向链表
- NSUserDefaults的使用