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的更多相关文章

  1. 2013年山东省赛F题 Mountain Subsequences

    2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...

  2. 2013年省赛H题

    2013年省赛H题你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4.想法真的是非常巧妙啊N=100000构造两个数组,f1[N],间隔为Af2[1e4]间隔为A^N,中 ...

  3. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  4. 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 ...

  5. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. 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 ...

  7. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 2013杭州现场赛B题-Rabbit Kingdom

    杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...

  9. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. 解决ssh连接linux服务器速度慢

    服务器端sshd配置文件 /etc/ssh/sshd_config 看是否有如下的两条配置条目 GSSAPIAuthentication no UseDNS no 如果前面带#,请把#删掉,或者新添加 ...

  2. hive 时间函数

    使用时发现:1.datediff可以传入timestamp类型参数     官网文档: Date Functions The following built-in date functions are ...

  3. VMware 安装 Mac OS 注意事项

    Ø  简介 本文主要介绍使用 VMware 安装 Mac OS 的注意事项,主要包括一下内容: 1.   安装参考 2.   使用 VMware 运行 Mac OS 虚拟机注意事项 3.   解决 M ...

  4. jmeter和loadrunner关于分布式部署测试计划的优缺点

    1.都可以实现分布式负载,相对来说loadrunner更强大一些 2.都支持在windows和linux环境的负载生成器,控制台方面,jmeter跨平台,而loadrunner不是 3.loadrun ...

  5. [译]Ocelot - Caching

    原文 Ocelot支持基本的缓存,目前Ocelot的缓存是通过CacheManager project实现的. 下面的示例展示了如何启用缓存: s.AddOcelot() .AddCacheManag ...

  6. matlab 常用函数

    Matlab常用函数 Matlab的内部常数  eps   浮点相对精度  pi  圆周率  exp  自然对数的底数e  i 或j  虚数单位  Inf或 inf  无穷大 Matlab概率密度函数 ...

  7. Mybatis-Plus入门

    1 Mybatis-Plus简介 1.1 什么是Mybatis-Plus MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化 ...

  8. luogu P5304 [GXOI/GZOI2019]旅行者

    传送门 所以这个\(5s\)是SMG 暴力是枚举每一个点跑最短路,然后有一个很拿衣服幼稚的想法,就是把所有给出的关键点当出发点,都丢到队列里,求最短路的时候如果当前点\(x\)某个相邻的点\(y\)是 ...

  9. JSP+MySQL验证登录的实现方式

    用IDEA连接MySQL验证登录实现方式核心部分代码 用setString的方法对从数据库中的提取的信息经行比对: try { Class.forName("com.mysql.jdbc.D ...

  10. Flask 之东方不败一

    1,flask的初始 flask是Python的一个轻量级的web框架,相当于django而言. 知识点Python 三大主流web框架的对比 1.Django 主要特点是大而全,集成了很多组件,例如 ...