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. sshd服务器搭建管理和防止暴力破解

    1.1 Linux服务前期环境准备,搭建一个RHEL7环境 1.2 sshd服务安装-ssh命令使用方法 1.3 sshd服务配置和管理 1.4 防止SSHD服务暴力破解的几种方式 1.1 Linux ...

  2. Oracle11gR2设置连接数process与会话session值

    近日构建的Web应用用户数量有所上升,后台总是打印无法打开数据库连接的错误信息: 000000a3 SystemOut O 9月 ::, ERROR - msg:打开数据库出错. 经查询发现需要更改数 ...

  3. Android 性能优化(13)网络优化( 9)Determining and Monitoring the Docking State and Type

    Determining and Monitoring the Docking State and Type PreviousNext This lesson teaches you to Determ ...

  4. 网站开发综合技术 第一部分HTML 1.3.2表单

    <form id="" name="" method="post/get" action="负责处理的服务端"&g ...

  5. Python(2)-第二天

    除法 >>> 8 / 5 1 >>> 8 / 5.0 1.6 >>> 8.0 / 5 1.6 >>> 8 // 5.0 1.0 ...

  6. C语言学习(2)-GTK布局

    首先了解下gtk中函数的定义格式: 记住下面几个格式看,下面的代码 声明变量:GtkAbc*abc=gtk_abc_new()声明控件; 赋值:gtk_abc_set_label(controlNam ...

  7. Redis远程连接

    一.打开CMD命令 二.打开Redis客户端安装地址

  8. LR接口测试---Java Vuser之jdbc查询(调试前)

    在eclipse下编写好的代码: import lrapi.lr; import java.sql.Connection; import java.sql.DriverManager; import ...

  9. Android学习笔记(五)Android框架

    一.技术结构图 注:开发者最需要关注的是第三层“Application Framework” 二.基于组件的应用程序开发 1)Activity 一个Activity就是一个界面,负责和用户交互. 2) ...

  10. asp.net MVC 和 webForm的区别

    asp.net MVC请求过程 ASP.NET MVC框架只是给开发者提供了开发web应用程序的一种选择,并不是要取代Webform这两种技术各有优缺点,开发者需要根据实际情况,选择对应的技术有时候, ...