hdu 1811 Rank of Tetris (并查集+拓扑排序)
Rank of Tetris
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5415 Accepted Submission(s): 1514
为了更好的符合那些爱好者的喜好,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"。
每组测试第一行包含两个整数N,M(0<=N<=10000,0<=M<=20000),分别表示要排名的人数以及得到的关系数。
接下来有M行,分别表示这些关系
CONFLICT
UNCERTAIN
//#define LOCAL
#include<cstdio>
#include<cstring>
#include<vector>
#include<iterator>
#include<queue>
#include<functional>
using namespace std; const int maxn=;
const int nn=; struct path{ int fr,to;
char ss[];
}tt[maxn]; vector<int>aa[nn]; //模拟邻接表
int n,m,num;
int father[nn];
int inde[nn]; //入度 void init(){
for(int i=;i<n;i++)
father[i]=i;
} int fin(int x){
while(x!=father[x])
x=father[x];
return x;
} void unin(int a,int b){
father[b]=a;
} int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif while(scanf("%d%d",&n,&m)!=EOF){
init();
num=n;
for(int i=;i<m;i++){
scanf("%d%s%d",&tt[i].fr,tt[i].ss,&tt[i].to);
if(tt[i].ss[]=='='){
int x=fin(tt[i].fr);
int y=fin(tt[i].to);
if(x!=y){
unin(x,y);
num--;
}
}
} bool err=,fight=;
memset(inde,,sizeof(int)*(n+)); for(int i=;i<n;i++)
aa[i].clear(); for(int i=;i<m;i++)
{
if(tt[i].ss[]!='=')
{
int x=fin(tt[i].fr);
int y=fin(tt[i].to);
if(x==y){
err=; //有矛盾
break;
}
//构建拓扑图
if(tt[i].ss[]=='>'){
aa[x].push_back(y);
inde[y]++;
}
else{
aa[y].push_back(x);
inde[x]++; //记录入读的情况
}
}
} if(err){
printf("CONFLICT\n");
continue;
} queue<int>tuop;
//找出所有入度为0的点。
for(int i=;i<n;i++)
if(inde[i]==&&i==fin(i))
tuop.push(i); while(!tuop.empty()){
if(tuop.size()>){
fight=;
} int gt=tuop.front();
tuop.pop();
num--;
vector<int>::iterator ww;
for(ww=aa[gt].begin(); ww!=aa[gt].end();ww++){
inde[*ww]--;
if(inde[*ww]==)
tuop.push(*ww);
}
}
if(num>){ //成环
printf("CONFLICT\n");
continue;
}
if(!fight) printf("OK\n");
else printf("UNCERTAIN\n");
}
return ;
}
hdu 1811 Rank of Tetris (并查集+拓扑排序)的更多相关文章
- hdu1811 Rank of Tetris 并查集+拓扑排序
#include <stdio.h> #include <string.h> #include <vector> #include <queue> us ...
- hdu 1811Rank of Tetris (并查集 + 拓扑排序)
/* 题意:这些信息可能有三种情况,分别是"A > B","A = B","A < B",分别表示A的Rating高于B,等于B ...
- 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(并查集+拓扑排序)
http://acm.hdu.edu.cn/showproblem.php?pid=1811 Rank of Tetris Problem Description 自从Lele开发了Rating系 ...
- 并查集+拓扑排序 赛码 1009 Exploration
题目传送门 /* 题意:无向图和有向图的混合图判环: 官方题解:首先对于所有的无向边,我们使用并查集将两边的点并起来,若一条边未合并之前, 两端的点已经处于同一个集合了,那么说明必定存在可行的环(因为 ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- 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: 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 ...
随机推荐
- debian hosts文件中的 127.0.1.1 主机地址
有时候/etc/hosts文件会看到127.0.1.1这个地址,这是什么呢? 127.0.0.1这个loopback地址很常见,就是本地接口的回路/回环地址.但有时候/etc/hosts文件中还会出现 ...
- Queue 应用——拓扑排序
1. 拓扑排序 题目描述:对一个有向无环图(Directed Acyclic Graph, DAG)G进行拓扑排序,是将G中所有顶点排成线性序列,是的图中任意一堆顶点u和v,若边(u, v)在E(G) ...
- How to: Update an .edmx File when the Database Changes
https://msdn.microsoft.com/en-us/library/cc716697.aspx In the Model Browser, right-click the .edmx f ...
- JQ将数组转换为Json
var ArrComList; try { //接口传进来的数据格式为 A,B,C,D,这里根据逗号分隔返回数组. ArrComList = WeighControl.GetComList().spl ...
- python_way ,day1 编译安装python3、基础及流程控制
本节内容: 1,Python介绍发展史 2,安装 3,Hello World 4,程序 5,变量,字符编码 6,用户输入 7,模块初识 一.python介绍 python的创始人为吉多·范罗苏姆(Gu ...
- XML约束——Schema约束
XML Schema 也是一种用于定义和描述 XML 文档结构与内容的模式语言,其出现是为了克服 DTD 的局限性 XML Schema VS DTD: •XML Schema符合XML语法结构. • ...
- shift移动变量
1.移动变量 脚本 sh05.sh #!/bin/bash # Program # Program shows the effect of shift function # History: # // ...
- iOS - UIPickerView
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIPickerView : UIView <NSCoding, UITa ...
- python中的最最最基本语法(1)
注意:对于我这个以前用c/c++的同学来说,可能一开始学习pyhon时有点不适应的,为什么呢?因为吧,python中,没有这玩意:{},也不用每句话才用分号分开的.python中通过缩进来分块的,一行 ...
- Longest Common Prefix
Description: Write a function to find the longest common prefix string amongst an array of strings.( ...