题意:略

分析:排序先按rating,若相同,则按rp。考虑到每个人的rp均不同,所以rating相同的人必然可以排序。那么只需要考虑rating不同的集合了。

    大小关系可以用有向边表示,而大小关系的传递可以用拓扑排序来呈现。

    接着就要分析,三种结果对应的情况了。

    很明显,ok要求拓扑出来的必须是一条链,一旦有分支,分支处的两个(或多个)点的大小关系就不明确,也就是条件不足=>uncertain。

    而矛盾conflict有两种情况:1、更改关系0=1,0>1;2、自相矛盾,即成环,0>1,0<1。

注意:在条件不足和矛盾同时发生时,要求输出的是矛盾conflict。

    这里要注意,拓扑排序是可以判环的:只要完成拓扑后,发现还有点没有加入队列,那么就说明他们之间成环。若不成环,必然可以把所有点加入队列。

    学习了vector的find函数

 #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; const int MAXN=; struct Edge{
int x,y;
char op;
}edge[MAXN<<]; vector<int>G[MAXN];
queue<int>q;
int in[MAXN],f[MAXN];
int inq[MAXN]; void init(int n)
{
for(int i=;i<n;i++)
f[i]=i; memset(in,,sizeof(in)); for(int i=;i<n;i++)
G[i].clear();
} int Find(int x)
{
return f[x]==x?x:f[x]=Find(f[x]);
} int top(int n)
{
int flog=;
while(!q.empty())
q.pop();
memset(inq,,sizeof(inq));//判入队 for(int i=;i<n;i++)
{
int x=Find(i);
if(x!=i)//忽略所有集合中除根以外的点
inq[i]=;
else if(in[x]==){
q.push(x);
inq[x]=;
}
}
if(q.empty())//队空,成环,冲突
return -;
while(!q.empty())
{
if(q.size()>=)//多叉,不分先后,条件不足
flog=; int u=q.front();q.pop();
int sz=G[u].size();
for(int i=;i<sz;i++)
{
int v=G[u][i];
in[v]--;
if(in[v]==){
if(inq[v])//成环,冲突
return -;
else {
q.push(v);
inq[v]=;
}
}
}
}
for(int i=;i<n;i++)
if(!inq[i])//不能全部拓扑,成环,冲突
return -;
return flog;
} int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int flog=;
init(n);
for(int i=;i<m;i++)
{
scanf("%d %c %d",&edge[i].x,&edge[i].op,&edge[i].y);
if(edge[i].op=='='){
int a=Find(edge[i].x);
int b=Find(edge[i].y);
f[a]=b;
}
}
for(int i=;i<m;i++)
{
if(edge[i].op=='=')
continue; int a=Find(edge[i].x);//所有处理都是对集合的根做操作
int b=Find(edge[i].y);
if(a==b)
flog=-;
if(flog==-)
break; if(edge[i].op=='<'){
if(find(G[b].begin(),G[b].end(),a)==G[b].end()){//去重,长知识了
G[b].push_back(a);
in[a]++;
}
}else{
if(find(G[a].begin(),G[a].end(),b)==G[a].end()){
G[a].push_back(b);
in[b]++;
}
}
}
if(flog==-){
printf("CONFLICT\n");
continue;
}
flog=top(n);
if(flog==-)
printf("CONFLICT\n");
else if(flog==)
printf("UNCERTAIN\n");
else
printf("OK\n");
}
return ;
}
/*
4 3
0 < 1
1 < 2
2 < 0 4 3
0 > 1
1 < 2
0 > 2 4 3
1 = 2
0 < 1
3 > 2 4 3
1 = 2
0 < 1
0 > 2 3 3
1 = 2
2 = 0
1 > 2 3 1
1 < 2
*/

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)To ...

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

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

  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. ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线

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

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

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

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

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

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

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

  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 【拓扑排序】+【并查集】

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

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

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

随机推荐

  1. Codeforces 897 B.Chtholly's request-思维题(处理前一半)

      B. Chtholly's request   time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. LA 3026 Period

    这只是蓝书上的一道KMP水题...然后对于最长前缀的循环证明我就不说了... #include<iostream> #include<cstring> #include< ...

  3. POJ 3470 Walls(线段树+扫描线)

    [题目链接] http://poj.org/problem?id=3470 [题目大意] 给出几面墙,均垂直于x轴或者y轴,给出一些鸟的位置(二维坐标点), 鸟只会垂直x轴或者y轴飞行,并且会撞上最近 ...

  4. Systemd入门教程:命令篇(转)

    作者: 阮一峰 日期: 2016年3月 7日 Systemd 是 Linux 系统工具,用来启动守护进程,已成为大多数发行版的标准配置. 本文介绍它的基本用法,分为上下两篇.今天介绍它的主要命令,下一 ...

  5. java实现点选汉字验证码(自己修改后的)

    参考:http://blog.csdn.net/qq_26680031/article/details/51168527 package com.rd.p2p.web; import java.awt ...

  6. JAVA中几种常见集合的使用实例

    Java.util.ArrayList(类): *;import java.util.*;public class CollectionTest{//List是一个能包含重复元素的已排序的Collec ...

  7. autocomplete属性在谷歌浏览器不起作用

    大家都知道autocomplete属性是表单字段中的HTML5新属性,该属性有两种状态值,分别为"on" 和 "off",该属性可省略:省略属性值后默认值为&q ...

  8. Tomcat 启动或者发布项目时提示Publishing failed:Resource /xxxx does not exist

    解决方法: 刷新一下项目,有可能是磁盘文件和Eclipse项目中文件不一致造成的. 重新启动eclipse 删除tomcat server 重新发布下即可

  9. [Functional Programming] Define Discrete State Transitions using the State ADT

    We build our first state transactions as two discrete transactions, each working on a specific porti ...

  10. [Angular] ViewChild 'read' option

    It is not clear in the Docs about {read: xx} option for @ViewChild. Based on the Source code, @ViewC ...