Rank of Tetris

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 1811
64-bit integer IO format: %I64d      Java class name: Main

 
 
自从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

Source

 
解题:并查集。。。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int A[maxn],B[maxn],uf[maxn],n,m;
char op[maxn][];
vector<int>next[];
int pre[],sum;
int Find(int x){
if(x != uf[x]) uf[x] = Find(uf[x]);
return uf[x];
}
void top_sort(){
bool uncertain = false;
queue<int>q;
for(int i = ; i < n; i++){
if(!pre[i] && Find(i) == i) q.push(i);
}
while(!q.empty()){
if(q.size() > ) uncertain = true;
int now = q.front();
q.pop();
sum--;
for(int i = ; i < next[now].size(); i++){
if(--pre[next[now][i]] == ) q.push(next[now][i]);
}
}
if(sum > ) puts("CONFLICT");
else if(uncertain) puts("UNCERTAIN");
else puts("OK");
}
int main() {
int i,j;
while(~scanf("%d %d", &n,&m)){
for(i = ; i <= n; i++){
uf[i] = i;
next[i].clear();
pre[i] = ;
}
sum = n;
for(i = ; i < m; i++){
scanf("%d %s %d",A+i,op[i],B+i);
int tx = Find(A[i]);
int ty = Find(B[i]);
if(op[i][] == '='){
if(tx != ty) {uf[tx] = ty;sum--;}
}
}
for(i = ; i < m; i++){
if(op[i][] == '=') continue;
int tx = Find(A[i]);
int ty = Find(B[i]);
if(op[i][] == '>'){
pre[ty]++;
next[tx].push_back(ty);
}else if(op[i][] == '<'){
pre[tx]++;
next[ty].push_back(tx);
}
}
top_sort();
}
return ;
}

BNUOJ 5966 Rank of Tetris的更多相关文章

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

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

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

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

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

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

  4. Rank of Tetris HDU--1881

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

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

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

  6. Rank of Tetris

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

  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 (拓扑 & 并查集)

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

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

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

随机推荐

  1. Ubuntu搭建Eclipse+JDK+SDK的Android (转载)

    转自:http://blog.csdn.net/ithomer/article/details/6960989 今晚重装Ubuntu系统,重新安装了一套eclipse+jdk+SDK的Android开 ...

  2. bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店【高精度+完全背包】

    居然要用高精度! 懒得operator了,转移是裸的完全背包 #include<iostream> #include<cstdio> using namespace std; ...

  3. lower_bound和upper_bound函数

    lower_bound(ForwardIter first,ForwardIter last,const_TP & val) upper_bound(ForwardIter first,For ...

  4. DFS POJ 3087 Shuffle'm Up

    题目传送门 /* 题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子 DFS:直接模拟搜索,用map记录该字符串是否被搜过.读懂题目是关键. */ ...

  5. [译]Cookies Without Chocolate Chips

    Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...

  6. java 对readLine扩展添加行号样式

    java 的流的使用中,在字符缓冲输入流中,有一个每次读取一行数据的方法:readLine(): 在这里使用简单的继承方法对其继续扩展,使得返回每行前面添加序号 //需要导入的一些包 import j ...

  7. javascript 到将来某个时间(2020-5-20)的倒计时

    function countDown(dateStr){ var end = +new Date(dateStr), start = +new Date(), during = Math.floor( ...

  8. 添加telnet命令

    打开控制面板,打开程序和功能,看到左边有个“打开或关闭Windows功能 ,打开找到telnet客户端,把这2项都勾选上,然后确定就可以了 注意,如果只要telnet别人的话,就选telnet客户端. ...

  9. 2017-12-04HTML table布局

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  10. Android中 string.xml资源 如何添加参数?

    在android 开发,我们通常会用string.xml资源去设置textview等控件的字符串.而值一般是与程序的运行结果无关的. 但有时需要根据运行的结果来显示到控件中,这时字符串资源就不能写死了 ...