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. HLA高级汇编语言基础

    HLA高级汇编语言环境的搭建与设置 我的操作系统:WINDOWS7 需要下载的东西:MASM32:http://www.masm32.com/masmdl.htm  HLA:http://webste ...

  2. java.util.concurrent.CopyOnWriteArrayList

    import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; impo ...

  3. 新建android项目报错,代码中找不到错误

    通过网上资料的引导,做以下操作: 1.进入C:\Documents and Settings\Administrator\.android 删除路径下的debug.keystore及 ddms.cfg ...

  4. Jquery手册

    1.jQuery 选择器: 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" ...

  5. 【转】Swing 与EDT线程

    在Swing程序中,经常能看到如下这种代码: SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { text ...

  6. UML学习

    学习链接:http://blog.csdn.net/wangyongxia921/article/category/1293975 感谢原文作者.

  7. Redis Sentinel高可用配置及C#访问

    本文环境如下: 操作系统:ubuntu-14.04.1-desktop-amd64 Redis:2.8.19 如果使用虚拟机则将每台的网络设置为桥接,否则他们之间能连上,局域网连不上. 系统设计如图: ...

  8. strcpy之代码的健壮性与可维护性

    strcpy   函数的原型是: char * strcpy(char * strDest,const char * strSrc);    功能:把从strSrc地址开始且含有NULL结束符的字符串 ...

  9. MVC在VIEW中动态控制htmlAttributes和routevalues的方法

    在项目中有一个Html.DropDownListFor放在一个分部视图中,然后调用这个分部视图时需要动态控制这个DropDownList的显示方式,比如宽度.是否禁用.是否列表等,这些值的设置都在Ht ...

  10. 遍历ModelState中存储的错误信息

    在服务器端验证中,有时我们添加了一个ModelError,然后还需要将该信息以JS的形式返回到客户端.如: [HttpPost] public ActionResult Index(LogOnMode ...