Thrall’s Dream(山东省第四届ACM大学生程序设计竞赛 )
来源:互联网 发布:信息技术网络研修总结 编辑:程序博客网 时间:2024/06/06 10:46
Problem Description
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?
Input
Output
Example Input
23 21 21 33 21 22 3
Example Output
Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead
题意:给定n个点和m条有向边,对于图中任意两个点,看都能是否能联通;
思路:bfs搜索一遍,把能联通的点用lin二维数组记录一下;
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <cmath>#include <algorithm>#include <vector>#include <map>#include <string>#include <stack>#define LL long long#define INF 0x7fffffff#define MAX 200010#define PI 3.1415926535897932#define E 2.718281828459045using namespace std;int n,m,T;int vis[2010];int lin[2010][2010];vector <int> edge[2010];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(); q.pop(); for(int i=0; i<edge[first].size(); i++) { int next=edge[first][i]; if(vis[next]) continue; lin[s][next]=1; vis[next]=1; q.push(next); } }}int main(){ scanf("%d",&T); int t=1; while(T--) { scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) edge[i].clear(); memset(lin,0,sizeof(lin)); for(int i=1; i<=m; i++) { int a,b; scanf("%d%d",&a,&b); edge[a].push_back(b); } for(int i=1; i<=n; i++) { BFS(i); } int flag=1; for(int i=1; i<=n; i++) { for(int j=i+1; j<=n; j++) { if(!lin[i][j] && !lin[j][i]) { flag=0; break; } } if (flag==0) break; } if(flag) printf("Case %d: Kalimdor is just ahead\n",t++); else printf("Case %d: The Burning Shadow consume us all\n",t++); }}
- 山东省第四届ACM大学生程序设计竞赛 Thrall’s Dream(单源强连通分量)
- Thrall’s Dream(山东省第四届ACM大学生程序设计竞赛 )
- 2013年山东省第四届ACM大学生程序设计竞赛 Problem I Thrall’s Dream 图,2n遍dfs
- 第四届山东省赛 Thrall’s Dream(BFS+vector)
- 第四届 山东省ACM大学生程序设计竞赛
- Mountain Subsequences(山东省第四届ACM大学生程序设计竞赛)
- 第四届 山东省ACM B Thrall’s Dream(连通图 OR BFS)
- 2013年山东省第四届ACM大学生程序设计竞赛
- 山东省第四届ACM大学生程序设计竞赛 Rescue The Princess
- 山东省第四届ACM大学生程序设计竞赛 Mountain Subsequences dp
- 山东省第四届ACM大学生程序设计竞赛Mountain Subsequences
- 山东省第四届ACM大学生程序设计竞赛 Alice and Bob
- 山东省第四届ACM大学生程序设计竞赛 Rescue The Princess
- 山东省第三届ACM省赛题——Thrall’s Dream(DFS)
- 2013年山东省第四届ACM大学生程序设计竞赛-Alice and Bob (找规律+二进制)
- 山东省第四届ACM大学生程序设计竞赛-Rescue The Princess(计算几何)
- 山东省第四届ACM大学生程序设计竞赛-Contest Print Server(模拟)
- 山东省第四届ACM大学生程序设计竞赛-Alice and Bob(二进制&&找规律)
- 特殊图案
- Struts 2拦截器
- VS2013下制作和使用静态库和动态库
- CSU 1113 Updating a Dictionary (湖南省第八届大学生计算机程序设计竞赛)
- GPU性能——Overdraw功能
- Thrall’s Dream(山东省第四届ACM大学生程序设计竞赛 )
- Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path
- 引用类型之RegExp类型
- Unity手游性能测评报告——MOBA篇
- 进程同步-生产者消费者问题
- JavaScript 数组 sort,reverse,冒泡排序,乱序
- activiti(2):解读activiti数据表
- 每天一个 Linux 命令(39):grep 命令
- Android自定义View