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. 异常处理与MiniDump详解(4) MiniDump

    http://blog.csdn.net/vagrxie/article/details/4398721 异常处理与MiniDump详解(4) MiniDump 分类:             [Wi ...

  2. 利用sqlserver日志恢复数据

    如果你已经急的焦头烂额,看到这篇文章的时候,请你换个坐姿,深呼吸几次,静下心来将这篇文章读完,也许你的问题迎刃而解. 我遇 到的情况是这样的,网站被植入木马,盗取了我的web.config文件,web ...

  3. 应用github pages创建自己的个人博客

    首先你需要注册自己的github账号 1.登录或者注册github,登录之后点击右上角的“+”号,选择“New repository”菜单,创建仓库,用于存储和博客相关的源文件. 2.跳转页面将填写域 ...

  4. Error executing aapt: Return code -1073741819

    在做andrid项目的时候,本来想把a项目中的a功能模块复制到b项目中,但是复制过程中出现xml文件id的问题, Error executing aapt: Return code -10737418 ...

  5. 图算法(一)——基本图算法(BFS,DFS及其应用)(1)

    1)BFS 广度优先搜索:给定源节点s,生成广度优先搜索树广度优先搜索树中从节点s到节点v的简单路径对应的就是s到v的最短路径(边数最少的路径)广度优先:将已发现节点与未发现节点之间的边界(灰色节点) ...

  6. QTextCodec::makeDecoder函数,plugins需要是动态链接库

    QT中的QString内容使用Unicode作为文本编码.但是实际系统中通常采用的是其他编码,例如GBK,utf8等.为了便于兼容这些格式,QT中还设置了两个字符串类型: QCString类: C类型 ...

  7. Sql server中左连接语句

    数据库中学生表和课程表如下: 左连接sql语句: select a.studentName,a.studentAge,b.courseName from student a left join cou ...

  8. Task+http请求

    Task+http请求  这个算是一个简单的事例吧

  9. Java实现热替换

    package test; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.nio. ...

  10. C#事务相关

    之前在程序中用到事务时,都是在存储过程中创建事务来对数据进行控制,其实在C#中也有事务类. 1.DbTransaction类对数据库访问添加事务,它是对数据库事务操作的基类,继承此类的有:   Sys ...