Rank of Tetris

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

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

思路:

此题花了我好长时间,一开始以为rating相同的点就直接比较rp然后建图,后来想想不对,因为这样发现不了冲突。后来一想对于rating相同的点可以不用排序,因为对于这些点,他们的rp必然不相同,也就是说在这些点的内部必然存在唯一的且合理的排序,因此只需将要将这些点合并成一个点即可,需要用到并查集的知识。

把所有点按上述方法处理后就会得到一些点(暂且称为“有效点”),对于这些有效点再进行拓扑排序即可。

冲突情形:到最后存在环,或者出现a > b,b > c 且 c >a;

不确定情形:同一层中不止一个点入度为0;

确定情形:除以上两种情形;

AC代码:

 #include<stdio.h>
#include<string.h>
typedef struct
{
int to;
int next;
}EdgeNode;
int cnt;
char str[];
EdgeNode Edge[];
int father[],depth[];
int L[],M[],R[];
int head[],indegree[];
int vis[],node[],temp[];
void init(int n)
{
int i;
cnt = ;
memset(vis,,sizeof(vis));
memset(head,-,sizeof(head));
memset(indegree,,sizeof(indegree));
for(i = ;i < n;i ++)
{
father[i] = i;
depth[i] = ;
}
} int find(int x)
{
if(x == father[x])
return x;
return father[x] = find(father[x]);
} void uint(int x,int y)
{
x = find(x);
y = find(y);
if(x == y)
return ;
if(depth[x] < depth[y])
father[x] = y;
else
{
if(depth[x] > depth[y])
father[y] = x;
else
{
father[x] = y;
depth[y]++;
}
}
return ;
} void add_edge(int n,int m)
{
Edge[cnt].to = m;
Edge[cnt].next = head[n];
head[n] = cnt++;
} int main(void)
{
int a,b,n,m,i,j,k;
int sum,flag_U,flag_C;
while(~scanf("%d %d",&n,&m))
{
init(n);
flag_U = flag_C = ;
for(i = ;i <= m;i ++)
{
scanf("%d %c %d",&L[i],&M[i],&R[i]);
if(M[i] == '=')
{
uint(L[i],R[i]);
}
}
for(i = ;i <= m;i ++)
{
if(M[i] == '=')
continue ;
a = find(L[i]);
b = find(R[i]);
if(a == b)
{
flag_C = ;
break ;
}
else
{
if(M[i] == '>')
{
add_edge(b+,a+);
indegree[a+]++;
}
else
{
add_edge(a+,b+);
indegree[b+]++;
}
}
}
for(i = ;i <= n;i ++)
{
sum = ;
for(j = ;j <= n;j ++)
{
if(indegree[j] == && vis[j] == && father[j-] == j-)
temp[sum++] = j;
}
if(sum > )
flag_U = ;
for(j = ;j < sum;j ++)
{
vis[temp[j]] = ;
for(k = head[temp[j]];k != -;k = Edge[k].next)
{
if(!vis[Edge[k].to])
indegree[Edge[k].to]--;
}
}
}
for(i = ;i <= n;i ++)
{
if(indegree[i] && father[i-] == i-)
{
flag_C = ;
break ;
}
}
if(!(flag_C+flag_U))
printf("OK\n");
if(flag_C)
printf("CONFLICT\n");
if(flag_U && !flag_C)
printf("UNCERTAIN\n");
}
return ;
}

Rank of Tetris HDU--1881的更多相关文章

  1. Day4 - J - Rank of Tetris HDU - 1811

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

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

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

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

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

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

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

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

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

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

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

  10. BNUOJ 5966 Rank of Tetris

    Rank of Tetris Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...

随机推荐

  1. jira汉化,破解,升级

    交给我这个任务,我先在网络上查了,好些资料,先实验的是6.3.6版本的,这个安装包我是从csdn上下载的.tar.gz的安装,汉化过程也都没有问题.但是在运行过程中不显示下拉菜单,于是我又在官网下载的 ...

  2. ubuntu server修改时区

    公司用的是ubuntu server 服务器在美国亚马逊VPS 现在要修改时区 执行:tzselect 或直接修改 /etc/timezone 文件,我是改成(America/Los_Angeles) ...

  3. 构建 struts2 spring3 mybatis 的maven项目 构建 pom.xml

    学习maven项目时 搭建个ssm项目 算是给自己留个备份吧 环境说明: MyEclipse10 Maven   3.2.3 框架: struts2    2.3.24.1 spring3    3. ...

  4. .net ajax式上传文件

    今天在这里介绍一下ajax上传文件.其实也不算是真的使用xmlhttprequest上传,只是使用了iframe实现了无刷新上传而已,最多也只算 是仿ajax上传文件.然而网上关于使用xmlhttpr ...

  5. An easy way to syncTime using C#

    /* * Created by SharpDevelop. * User: Administrator * Date: 2013/10/23 * Time: 8:57 * author zibet * ...

  6. Google v8 - Hello world

    OS:Window 7 1.下载v8 zip:https://github.com/v8/v8,解压zip,重命名v8-master文件夹为v8. 2.下载安装svn:http://tortoises ...

  7. PHP下拉框选择的实现方法

    实现 第一种PHP下拉框实现方法: < ?php //提交下拉框; //直接饱触发onchange事件的结果 $id=$_GET['myselect']; // myselect 为locati ...

  8. 向OC类中添加默认的协议实现(ProtocolKit)

    以forkingdog的PorotocolKit举例 举例 ProtocolKit Protocol extension for Objective-C Usage Your protocol: @p ...

  9. 【转载】db blocks gets & consistent gets

    LOGIC IO(逻辑读次数)= db block gets + consistent gets consistent get : 在一致读模式下所读的快数,包括从回滚段读的快数. db block ...

  10. Xcode报错 - 1

    1. xcode在真机调试的时候出现"The identity used to sign the executable is no longer valid" 解析: 是由于.pr ...