Rank of Tetris

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4323    Accepted Submission(s): 1220

Problem Description
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球。

为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜,定时更新,名堂要比福布斯富豪榜还响。关于如何排名,这个不用说都知道是根据Rating从高到低来排,如果两个人具有相同的Rating,那就按这几个人的RP从高到低来排。

终于,Lele要开始行动了,对N个人进行排名。为了方便起见,每个人都已经被编号,分别从0到N-1,并且编号越大,RP就越高。
同时Lele从狗仔队里取得一些(M个)关于Rating的信息。这些信息可能有三种情况,分别是"A > B","A = B","A < B",分别表示A的Rating高于B,等于B,小于B。

现在Lele并不是让你来帮他制作这个高手榜,他只是想知道,根据这些信息是否能够确定出这个高手榜,是的话就输出"OK"。否则就请你判断出错的原因,到底是因为信息不完全(输出"UNCERTAIN"),还是因为这些信息中包含冲突(输出"CONFLICT")。
注意,如果信息中同时包含冲突且信息不完全,就输出"CONFLICT"。

 
Input
本题目包含多组测试,请处理到文件结束。
每组测试第一行包含两个整数N,M(0<=N<=10000,0<=M<=20000),分别表示要排名的人数以及得到的关系数。
接下来有M行,分别表示这些关系
 
Output
对于每组测试,在一行里按题目要求输出
 
Sample Input
3 3
0 > 1
1 < 2
0 > 2
4 4
1 = 2
1 > 3
2 > 0
0 > 1
3 3
1 > 0
1 > 2
2 < 1
 
Sample Output
OK
CONFLICT
UNCERTAIN
 
Author
linle
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1198 1829 1558 1325 1213 
 
 //62MS    744K    1657 B    G++
/* 拓扑排序+并查集:
题意比较明了,就是要排序,'='号用并查集处理,先处理完再
进行拓扑排序。 */
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
vector<int>next[];
int in[],a[],b[];
char c[];
int set[];
int n,m,sum; //sum最后不为0则表示有环,排名矛盾
int find(int x)
{
if(x==set[x]) return x;
return find(set[x]);
}
int merge(int a,int b)
{
int x=find(a);
int y=find(b);
if(x==y) return ;
if(x>y) set[x]=y;
else set[y]=x;
return ;
}
void topo()
{
int uncertain=;
queue<int>Q;
for(int i=;i<n;i++)
if(in[i]== && find(i)==i){
Q.push(i);
}
while(!Q.empty()){
if(Q.size()>) uncertain=; //队列同时存在多个元素,则排名不明确
int u=Q.front();
Q.pop();
sum--;
for(int i=;i<next[u].size();i++)
if(--in[next[u][i]]==)
Q.push(next[u][i]);
}
if(sum>) puts("CONFLICT");
else if(uncertain) puts("UNCERTAIN");
else puts("OK");
}
int main(void)
{
while(scanf("%d%d",&n,&m)!=EOF)
{
sum=n;
for(int i=;i<=n;i++){
next[i].clear();
in[i]=;
set[i]=i;
}
for(int i=;i<m;i++){
scanf("%d %c %d",&a[i],&c[i],&b[i]);
if(c[i]=='='){
if(merge(a[i],b[i])) sum--;
}
}
for(int i=;i<m;i++){
int x=find(a[i]);
int y=find(b[i]);
if(c[i]=='>'){
next[x].push_back(y);
in[y]++;
}
if(c[i]=='<'){
next[y].push_back(x);
in[x]++;
}
}
topo();
}
return ;
}

hdu 1811 Rank of Tetris (拓扑 & 并查集)的更多相关文章

  1. HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. HDU 1811 Rank of Tetris(并查集+拓扑排序 非常经典)

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线

    hdu 1811 Rank of Tetris Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  4. hdu 1811 Rank of Tetris - 拓扑排序 - 并查集

    自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...

  5. HDU 1811:Rank of Tetris(并查集+拓扑排序)

    http://acm.hdu.edu.cn/showproblem.php?pid=1811 Rank of Tetris Problem Description   自从Lele开发了Rating系 ...

  6. HDU 1811 Rank of Tetris(拓扑排序+并查集)

    题目链接: 传送门 Rank of Tetris Time Limit: 1000MS     Memory Limit: 32768 K Description 自从Lele开发了Rating系统, ...

  7. hdu 1811 Rank of Tetris (并查集+拓扑排序)

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. HDU 1811 Rank of Tetris 【拓扑排序】+【并查集】

    <题目链接> 题目大意: 给你N个点(编号从0到N-1)和M个关系,要你判断这个图的所有点的顺序是否可以全部确定.不过对于任意点的关系可能存在A>B或A<B或A=B三种情况,如 ...

  9. HDU 1811 Rank of Tetris 拓补排序+并查集

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [ ...

随机推荐

  1. 《阿里巴巴Java开发手册》阅读笔记

    1.抽象类命名使用 Abstract 或 Base 开头: 异常类命名使用 Exception 结尾: 测试类命名以它要测试的类的名称开始,以 Test 结尾. 2.POJO 类中布尔类型的变量,都不 ...

  2. 使用JavaScript动态的绑定、解绑 a 标签的onclick事件,防止重复点击

    页面上的 a 标签如下: <a class="more" style="cursor: pointer;" id="commentMore&qu ...

  3. go get超时解决办法

    go get gopkg.in/yaml.v2超时,发现被墙了,解决办法如下: 1.安装golang.org/x/net $ mkdir -p $GOPATH/src/golang.org/x/ $ ...

  4. ES6笔记03-Set和Map数据结构

    ES6提供了新的数据结构Set.它类似于数组,但是成员的值都是唯一的,没有重复的值.Set本身是一个构造函数,用来生成Set数据结构. var s = new Set(); [2, 3, 5, 4, ...

  5. The Road to learn React书籍学习笔记(第一章)

    react灵活的生态圈 Small Application Boilerplate: create-react-app Utility: JavaScript ES6 and beyond Styli ...

  6. 2,Python常用库之二:Pandas

    Pandas是用于数据操纵和分析,建立在Numpy之上的.Pandas为Python带来了两种新的数据结构:Pandas Series和Pandas DataFrame,借助这两种数据结构,我们能够轻 ...

  7. ansible-2

    软件相关模块 rpm 和yum 的区别: rpm: redhat package manager :yum可以解决依赖关系 yum 源配置: cat /etc/yum.repos.d/epel.rep ...

  8. JS:关于JS字面量及其容易忽略的12个小问题

    简要 问题1:不能使用typeof判断一个null对象的数据类型 问题2:用双等号判断两个一样的变量,可能返回false 问题3:对于非十进制,如果超出了数值范围,则会报错 问题4:JS浮点数并不精确 ...

  9. ZOJ 3329 Problem Set (期望dp)

    One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...

  10. Reverse Word in a String(翻转字符串)&字符串最后一个单词的长度

    1.题目: Given an input string, reverse the string word by word. For example,Given s = "the sky is ...