sdutoj 2604 Thrall’s Dream
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?
输入
输出
示例输入
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
提示
来源
示例程序
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的更多相关文章
- 2013年省赛I题 Thrall’s Dream
2013年省赛I题判断单向联通,用bfs剪枝:从小到大跑,如果遇到之前跑过的点(也就是编号小于当前点的点),就o(n)传递关系. bfs #include<iostream> #inclu ...
- Thrall’s Dream 第四届山东省省赛 (直接暴力DFS)
题目链接:题目 AC代码: #include<iostream> #include<algorithm> #include<vector> #include< ...
- 山东省第四届ACM省赛
排名:http://acm.sdut.edu.cn/sd2012/2013.htm 解题报告:http://www.tuicool.com/articles/FnEZJb A.Rescue The P ...
- 2013山东省ICPC结题报告
A.Rescue The Princess 已知一个等边三角形的两个顶点A.B,求第三个顶点C,A.B.C成逆时针方向. 常规的解题思路就是用已知的两个点列出x,y方程,但这样求出方程的解的表达式比较 ...
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
- 山东省第四届acm解题报告(部分)
Rescue The PrincessCrawling in process... Crawling failed Description Several days ago, a beast ca ...
- 山东省第四届ACM程序设计竞赛部分题解
A : Rescue The Princess 题意: 给你平面上的两个点A,B,求点C使得A,B,C逆时针成等边三角形. 思路: http://www.cnblogs.com/E-star/arch ...
- [ACM]2013山东省“浪潮杯”省赛 解题报告
题目地址:http://acm.upc.edu.cn/problemset.php?page=13 2217~2226 A.Rescue The Princess 一个等边三角形告诉前2个点,求逆时 ...
- PK淘宝BUY+,京东推出AR购物应用JD Dream
今年双十一淘宝推出了虚拟现实VR购物"BUY+",用户可以在虚拟环境中选购商品.那作为竞争对手的京东将使出什么绝招呢?在近日上海举办的谷歌开发者大会上得到了答案.会上京东推 ...
随机推荐
- JS中基本window对象操作
---恢复内容开始--- 一.使用window中的属性时 window.属性,直接跟属性名.而调用window的函数时 window.hanshu(): 要在其函数名后面加括号. 二.windo ...
- AES加密时抛出 Illegal key size or default parameters
使用AES加密时,当密钥大于128时,代码会抛出java.security.InvalidKeyException: Illegal key size or default parameters Il ...
- Bluetooth ATT介绍
目录 1 介绍 2 详细内容 2.1 Attribute Type 2.2 Attribute Handle 2.3 Attribute Handle Grouping 2.4 Attribute V ...
- 在windows下创建一个Mongo服务
首先需要下载mongo的安装包 cmd.exe 这个需要用管理员权限打开 进入到mongo的安装目录 首先到C盘根据下面的命令手动创建一个 Data 文件夹 在Data 里面创建一个db文件夹一个lo ...
- Android项目框架升级尝鲜OkHttp
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 随着项目日趋稳定,需求不再总是变化,那么是时间来整理下项目了.先简单介绍下,本项目最初使用loop4 ...
- RequestContextListener有什么用
问题: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request att ...
- android Listview item 中有button,item就不响应触摸事件
为button设置 beanButton.getButton().setFocusable(false); beanButton.getButton().setFocusableInTouchMode ...
- 1011 最大公约数GCD
1011 最大公约数GCD 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最大公约数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...
- [LeetCode]题解(python):092 Reverse Linked List II
题目来源 https://leetcode.com/problems/reverse-linked-list-ii/ Reverse a linked list from position m to ...
- JS-001-单选复选按钮操作
此文主要针对 web 页面中常见元素(例如:单选按钮.复选按钮)的 JavaScript 操作,进行简单的源码示例演示,敬请小主们参阅.若有不足之处,敬请大神指正,不胜感激! 话不多言了,直接上码: ...