hdu 1811 Rank of Tetris
http://acm.hdu.edu.cn/showproblem.php?pid=1811
拓扑排序和并差集
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
#define maxn 10010
using namespace std;
int n,m,c;
int f[maxn],in[maxn];
vector<int>g[maxn];
struct node
{
int x,y;
char ch;
}p[maxn*];
void inti()
{
for(int i=; i<=n; i++)
{
f[i]=i; in[i]=;
g[i].clear();
}
} int find1(int x)
{
if(x==f[x]) return x;
return f[x]=find1(f[x]);
} void merge1(int a,int b)
{
int fa=find1(a);
int fb=find1(b);
if(fa!=fb)
{
f[fb]=fa;
}
} int topp()
{
int flag=;
queue<int>q;
for(int i=; i<n; i++)
{
if(!in[i]&&find1(i)==i) q.push(i);
}
int cnt=;
while(!q.empty())
{
if(q.size()>=) flag=-;
int x=q.front(); q.pop();
cnt++;
for(int i=; i<(int)g[x].size(); i++)
{
if((--in[g[x][i]])==) q.push(g[x][i]);
}
}
if(cnt<c) return ;
return flag;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
inti();
c=n;
for(int i=; i<m; i++)
{
scanf("%d%*c%c%*c%d",&p[i].x,&p[i].ch,&p[i].y);
if(p[i].ch=='=')
{
merge1(p[i].x,p[i].y); c--;
}
}
bool flag=false;
for(int i=; i<m; i++)
{
if(p[i].ch=='=')
{
continue;
}
int x1=find1(p[i].x); int y1=find1(p[i].y);
if(x1==y1) flag=true;
if(p[i].ch=='<')
{
if(find(g[x1].begin(),g[x1].end(),y1)==g[x1].end())
{
g[x1].push_back(y1);
in[y1]++;
}
}
else if(p[i].ch=='>')
{
if(find(g[y1].begin(),g[y1].end(),x1)==g[y1].end())
{
g[y1].push_back(x1);
in[x1]++;
}
}
}
bool flag1=false;
if(!flag)
{
int cc=topp();
if(cc==) flag=true;
else if(cc==-) flag1=true;
}
if(flag)
{
printf("CONFLICT\n");
}
else if(flag1)
{
printf("UNCERTAIN\n");
}
else printf("OK\n");
}
return ;
}
hdu 1811 Rank of Tetris的更多相关文章
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 1811 Rank of Tetris(拓扑排序+并查集)
题目链接: 传送门 Rank of Tetris Time Limit: 1000MS Memory Limit: 32768 K Description 自从Lele开发了Rating系统, ...
- hdu 1811 Rank of Tetris (并查集+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1811 Rank of Tetris 拓补排序+并查集
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [ ...
- HDU 1811 Rank of Tetris(并查集+拓扑排序 非常经典)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1811 Rank of Tetris (拓扑 & 并查集)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- HDU 1811 Rank of Tetris 【拓扑排序 + 并查集】
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
随机推荐
- url中的jsessionid解释
(1) 这是一个保险措施 因为Session默认是需要Cookie支持的 但有些客户浏览器是关闭Cookie的 这个时候就需要在URL中指定服务器上的session标识,也就是5F4771183629 ...
- linux下串口的阻塞和非阻塞操作
有两个可以进行控制串口阻塞性(同时控制read和write):一个是在打开串口的时候,open函数是否带O_NDELAY:第二个是可以在打开串口之后通过fcntl()函数进行控制. 阻塞的定义: 对于 ...
- Codeforces Round #322 (Div. 2) —— F. Zublicanes and Mumocrates
It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The ...
- 轻量级开源嵌入式关系数据库sqlite基本使用及接口初识
preface,先闲来扯下蛋: 嵌入式数据库,NoSQL的是BerkeleyDB和InnoDB,leveDb.TC(个人较不熟悉),关系型嵌入式是SQLite; 服务器性质的NoSQL服务器,如Red ...
- 关于static静态
静态属性与方法可以在不实例化类的情况下调用,直接使用类名::方法名的方式进行调用.静态属性不允许对象使用->操作符调用. class Car { private static $speed = ...
- PHP常用魔术方法(__set、__get魔术方法:)
__set.__get魔术方法: //文件名:Object.php <?phpnamespace IMooc;class Object{ protected $array = array(); ...
- Android studio无法更新 提示网络连接失败
Android studio 更新时,提示网络问题 “Connection failed. Please check your network connection and try again” 在默 ...
- [Javascript] Task queue & Event loop.
Javascript with Chorme v8 engine works like this : For Chorme engine, v8, it has call stack. And all ...
- Winform 无边框随意拖动【转载】
本篇技术内容转载自:http://www.cnblogs.com/ap0606122/archive/2012/10/23/2734964.html using System; using Syste ...
- Geodatabase - 判断是否处于编辑状态
Engine中提供IDatasetEdit来判断数据是否处于编辑状态,我们知道,在ArcMap中,进行编辑的不一定都是要素类,也可以是表,网络几何等.以下能在ArcMap中进行编辑的数据都实现了 ID ...