2013年省赛I题 Thrall’s Dream
2013年省赛I题
判断单向联通,用bfs
剪枝:从小到大跑,如果遇到之前跑过的点(也就是编号小于当前点的点),就o(n)传递关系。
bfs
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int T;
int n,m,cnt;
int x,y;
bool b[][];
struct node{
int n;
node *next;
}*e[]; queue<int>q; void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void push(int x,int y){
node *p;
p=new node();
p->n=y;
if(!e[x])
e[x]=p;
else{
p->next=e[x]->next;
e[x]->next=p;
}
} void bfs(int x){
q.push(x);
while(!q.empty()){
int t=q.front();
q.pop();
if(t<x){
For(i,,n)
if(b[t][i])
b[x][i]=;
}
else{
for(node *i=e[t];i;i=i->next)
if(!b[x][i->n]){
b[x][i->n]=;
q.push(i->n);
}
}
}
} bool judge(){
For(i,,n)
For(j,i+,n)
if(!b[i][j]&&!b[j][i])
return ;
return ;
} void clear(){
memset(b,,sizeof(b));
For(i,,)
e[i]=;
} int main(){
in(T);
while(T--){
clear();
in(n);in(m);
For(i,,m){
in(x);in(y);
push(x,y);
}
For(i,,n)
bfs(i);
printf("Case %d: ",++cnt);
if(judge())
printf("Kalimdor is just ahead\n");
else
printf("The Burning Shadow consume us all\n");
}
return ;
}
dfs更好写,队友比赛的时候不知道为啥T了
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int T;
int n,m,cnt;
int x,y;
bool b[][];
struct node{
int n;
node *next;
}*e[]; queue<int>q; void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void push(int x,int y){
node *p;
p=new node();
p->n=y;
if(e[x]==NULL)
e[x]=p;
else{
p->next=e[x]->next;
e[x]->next=p;
}
} // void bfs(int x){
// q.push(x);
// while(!q.empty()){
// int t=q.front();
// q.pop();
// if(t<x){
// For(i,1,n)
// if(b[t][i])
// b[x][i]=1;
// }
// else{
// for(node *i=e[t];i;i=i->next)
// if(!b[x][i->n]){
// b[x][i->n]=1;
// q.push(i->n);
// }
// }
// }
// } void dfs(int x,int f){
for(node *i=e[x];i;i=i->next)
if(!b[f][i->n]){
b[f][i->n]=;
dfs(i->n,f);
}
} bool judge(){
For(i,,n)
For(j,i+,n)
if(!b[i][j]&&!b[j][i])
return ;
return ;
} void clear(){
memset(b,,sizeof(b));
For(i,,)
e[i]=;
} int main(){
in(T);
while(T--){
clear();
in(n);in(m);
For(i,,m){
in(x);in(y);
push(x,y);
}
For(i,,n)
dfs(i,i);
printf("Case %d: ",++cnt);
if(judge())
printf("Kalimdor is just ahead\n");
else
printf("The Burning Shadow consume us all\n");
}
return ;
}
2013年省赛I题 Thrall’s Dream的更多相关文章
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- 2013年省赛H题
2013年省赛H题你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4.想法真的是非常巧妙啊N=100000构造两个数组,f1[N],间隔为Af2[1e4]间隔为A^N,中 ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 2013杭州现场赛B题-Rabbit Kingdom
杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- hadoop记录-Hadoop参数汇总
Hadoop参数汇总 linux参数 以下参数最好优化一下: 文件描述符ulimit -n 用户最大进程 nproc (hbase需要 hbse book) 关闭swap分区 设置合理的预读取缓冲区 ...
- 自制stm32板子无法烧录程序的问题
自己画的stm32板子一开始出现了无法烧录程序的情况,主要表现为在点击load图标后出现了Stlink connect error!Target dll has been concelled的窗口.在 ...
- 在Windows Server上安装ASP.NET时失败,提示not enough storage is available to process the command
今天在部署ASP.NET网站时出现IIS 500.21错误.环境是Windows Server 2012 +IIS8 于是查找解决方案,发现网上的信息都说是需要重装.NET framerwork4.0 ...
- Java 多线程 - Synchronized关键字
目录 1-Synchronized 关键字概述 2- Synchronized关键字作用域 3- Synchronized 原理(反编译指令解释) 正文 1-Synchronized 关键字概述 由于 ...
- docker保存日志文件到本地
其实很简单 docker logs +你需要添加的额外参数 + 容器id >文件名称 然后查看这个文件就可以了,也可以通过ftp协议下载到本地
- 团队Github实战训练
班级:软件工程1916|W 作业:团队Github实战训练 团队名称:SkyReach Github地址:Github地址 贡献比例表 队员学号 队员姓名 此次活动任务 贡献比例 221600106 ...
- HeatMap
Reprinting From https://blog.csdn.net/JNingWei/article/details/78803669 ColorMap(色度图) 在图像处理中,伪色彩用途广泛 ...
- Python multiprocessing
 推荐教程 官方文档 multiprocess各个模块较详细介绍 廖雪峰教程--推荐 Pool中apply, apply_async的区别联系 (推荐)python多进程的理解 multiproce ...
- neo4j-cypher
cypher查询务必在需要查询的节点上加上标签,否则数据量一大查询就会非常慢(在查询时必须设置实体标签,否则不走索引),另外Neo4j索引做好了查询的优化基本上就完成了80%.需要注意index是建立 ...
- 常用函数php
//随机数 /** * @param int $length 随机数长度 * @param string $num 是否只包含数字 * @return null|string 返回随机字符串 */ f ...