http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2604

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?

输入

   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

提示

 

来源

2013年山东省第四届ACM大学生程序设计竞赛

示例程序

AC代码:

 #include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int a[],b[],c[];
int main()
{
int T,cnt=;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d %d",&n,&m);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
if(n<)
{
printf("Case %d: Kalimdor is just ahead\n",cnt++);
}
else
{
int x,y;
while(m--)
{
scanf("%d %d",&x,&y);
a[x]--;
a[y]++;
c[x]=;
c[y]=;
}
int flag=,t=;
for(int i=;i<=n;i++)
{
if(!c[i])
{
flag=;
break;
}
if(a[i]!=)
t++;
}
if(!flag)
printf("Case %d: The Burning Shadow consume us all\n",cnt++);
else
{
if(t<=)
printf("Case %d: Kalimdor is just ahead\n",cnt++);
else
printf("Case %d: The Burning Shadow consume us all\n",cnt++);
}
}
}
return ;
}

官方代码:

 #include <cstdio>
#include <cstring> const int maxn = ;
const int maxm = ; struct TOPO
{
int net[maxn], in[maxn], ans[maxn];
int nv, size;
struct edge
{
int v, next;
edge(){}
edge(int a, int b){v = a; next = b;}
}E[maxm];
inline void init(int n)
{
memset(in, , sizeof(in));
memset(net, -, sizeof(net));
nv = n;
size = ;
}
inline void add_edge(int u, int v)
{
E[size] = edge(v, net[u]);
net[u] = size++;
in[v]++;
}
bool toposort()
{
int num; for(int i = ; i <= nv; i++)
{
int j = ;
num = ;
for(int k = ; k <= nv; k++)
if(!in[k])
num++;
if(num > )
return false;
while(in[j] != )
j++;
in[j] = -;
ans[i] = j;
for(int k = net[j]; k != -; k = E[k].next)
in[E[k].v]--;
}
return true;
}
}T; struct SCC
{
int net[maxn], dfn[maxn], low[maxn], s[maxn], belong[maxn];
int count, ans, top, size, nv;
bool ins[maxn];
struct edge
{
int v, next;
edge(){}
edge(int a, int b){v = a; next = b;}
}E[maxm];
inline void init(int n)
{
memset(dfn, -, sizeof(dfn));
memset(net, -, sizeof(net));
memset(ins, false, sizeof(ins));
count = ans = size = ;
top = -;
nv = n;
}
inline void add_edge(int u, int v)
{
E[size] = edge(v, net[u]);
net[u] = size++;
}
void dfs(int u)
{
int v; dfn[u] = low[u] = ++count;
ins[u] = true;
s[++top] = u;
for(int i = net[u]; i != -; i = E[i].next)
{
v = E[i].v;
if(dfn[v] == -)
{
dfs(v);
if(low[v] < low[u])
low[u] = low[v];
}
else if(ins[v] && dfn[v] < low[u])
low[u] = dfn[v];
}
if(dfn[u] == low[u])
{
ans++;
do
{
v = s[top--];
belong[v] = ans;
ins[v] = false;
}while(u != v);
}
}
bool tarjan()
{
for(int i = ; i <= nv; i++)
if(dfn[i] == -)
dfs(i);
T.init(ans);
for(int i = ; i <= nv; i++)
for(int j = net[i]; j != -; j = E[j].next)
{
int v = E[j].v;
if(belong[i] != belong[v])
T.add_edge(belong[i], belong[v]);
}
return T.toposort();
}
}S; int main()
{
int t, n, m, a, b, cnt = ; scanf("%d", &t);
while(t--)
{
scanf("%d %d", &n, &m);
S.init(n);
while(m--)
{
scanf("%d %d", &a, &b);
S.add_edge(a, b);
}
if(S.tarjan())
printf("Case %d: Kalimdor is just ahead\n", ++cnt);
else
printf("Case %d: The Burning Shadow consume us all\n", ++cnt);
}
return ;
}

暴力搜索:

 #include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = ;
int m,n;
bool vis[N][N],vis1[N];
vector< int >mm[N];
void dfs(int m,int x)
{
if(mm[x].size()==) return;
for(int i=;i<mm[x].size();i++)
{
if(vis[m][mm[x][i]] == false)
{
vis[m][mm[x][i]]=true;
int t = mm[x][i];
dfs(m,t);
}
}
}
int main()
{
int T,cas =,x,y;
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&m,&n);
for(int i=;i<=m;i++)
mm[i].clear();
for(int i=; i<n; i++)
{
scanf("%d %d",&x,&y);
mm[x].push_back(y);
}
memset(vis,false,sizeof(vis));
for(int i=;i<=m;i++)
vis[i][i] = true;
for(int i =;i<=m;i++) dfs(i,i);
bool flag = true;
for(int i=;i<=m;i++)
{
for(int j=;j<=m;j++)
{
if(vis[i][j] == false && vis[j][i] == false)
{
flag = false;
goto end;
}
}
}
end: if (flag) printf("Case %d: Kalimdor is just ahead\n",cas++);
else printf("Case %d: The Burning Shadow consume us all\n",cas++);
}
return ;
}

sdutoj 2604 Thrall’s Dream的更多相关文章

  1. 2013年省赛I题 Thrall’s Dream

    2013年省赛I题判断单向联通,用bfs剪枝:从小到大跑,如果遇到之前跑过的点(也就是编号小于当前点的点),就o(n)传递关系. bfs #include<iostream> #inclu ...

  2. Thrall’s Dream 第四届山东省省赛 (直接暴力DFS)

    题目链接:题目 AC代码: #include<iostream> #include<algorithm> #include<vector> #include< ...

  3. 山东省第四届ACM省赛

    排名:http://acm.sdut.edu.cn/sd2012/2013.htm 解题报告:http://www.tuicool.com/articles/FnEZJb A.Rescue The P ...

  4. 2013山东省ICPC结题报告

    A.Rescue The Princess 已知一个等边三角形的两个顶点A.B,求第三个顶点C,A.B.C成逆时针方向. 常规的解题思路就是用已知的两个点列出x,y方程,但这样求出方程的解的表达式比较 ...

  5. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

  6. 山东省第四届acm解题报告(部分)

    Rescue The PrincessCrawling in process... Crawling failed   Description Several days ago, a beast ca ...

  7. 山东省第四届ACM程序设计竞赛部分题解

    A : Rescue The Princess 题意: 给你平面上的两个点A,B,求点C使得A,B,C逆时针成等边三角形. 思路: http://www.cnblogs.com/E-star/arch ...

  8. [ACM]2013山东省“浪潮杯”省赛 解题报告

    题目地址:http://acm.upc.edu.cn/problemset.php?page=13  2217~2226 A.Rescue The Princess 一个等边三角形告诉前2个点,求逆时 ...

  9. PK淘宝BUY+,京东推出AR购物应用JD Dream

        今年双十一淘宝推出了虚拟现实VR购物"BUY+",用户可以在虚拟环境中选购商品.那作为竞争对手的京东将使出什么绝招呢?在近日上海举办的谷歌开发者大会上得到了答案.会上京东推 ...

随机推荐

  1. Tab指示符——Indicator

    先说说我们的思路吧. 其实思路也很简单,就是在咱们的导航下面画一个小矩形,不断的改变这个矩形距离左边的位置. 思路就这么简单,有了思路,接下来就是实现了,看代码: public class Indic ...

  2. 用户登录验证例题用的ajax

    1.登录页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  3. php判断爬虫

    function checkrobot($useragent = ''){ static $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos ...

  4. HashSet HashTable HashMap的区别

    (1)HashSet是set的一个实现类,hashMap是Map的一个实现类,同时hashMap是hashTable的替代品(为什么后面会讲到). (2)HashSet以对象作为元素,而HashMap ...

  5. pointer-events:none;穿透属性

    从属性字面上看可以理解为:手势时间无效. 当我们在ios下想复制一段文字是,不知道原因导致一些莫名的怪异现象:总是无法复制文字,却意外的发现无论怎么着复制的始终都是图片时, 当我们在一个半透明遮罩上想 ...

  6. iOS获取的NSDate date时间与实际相差8个小时

    NSDate *startDate = [NSDate date];NSTimeZone *zone = [NSTimeZone systemTimeZone];NSInteger interval ...

  7. Unofficial Windows Binaries for Python Extension Packages

    http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

  8. vb和php 基于socket通信

    php代码(页面代码非cmd命令脚本) <?php $server = '127.0.0.1'; $port = 8888; $socket = socket_create(AF_INET, S ...

  9. SQL把表中的数据复制到另一个数据库中

    1 删除整张表的数据,并还原自增长值TRUNCATE TABLE TbWeixinActivity 2 3张表左连接select a.ID,c.Name,b.nickname,a.CreateDate ...

  10. C# --通过枚举获取系统颜色

    public static System.Drawing.Color GetSystemColor(int i) { Array Colors = System.Enum.GetValues(type ...