并查集+拓扑排序。使用并查集解决a = b的情况。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; #define MAXN 10005 typedef struct ArcNode {
int adjvex;
ArcNode *next;
} ArcNode; typedef struct VNode {
int count;
ArcNode *first;
} VNode; VNode nodes[MAXN];
int pre[MAXN], n;
int srca[MAXN<<],srcb[MAXN<<];
char op[MAXN<<];
bool flag; int find(int x) {
int r = x;
while (r != pre[r])
r = pre[r];
return r;
} void merge(int a, int b) {
int x = find(a);
int y = find(b);
pre[x] = y;
} void Insert(int x, int y) {
ArcNode *p = new ArcNode;
nodes[y].count++;
p->adjvex = y;
p->next = nodes[x].first;
nodes[x].first = p;
} int main() {
int m;
int i, j, x, y; while (scanf("%d %d",&n,&m) != EOF) {
for (i=; i<n; ++i) {
nodes[i].count = ;
nodes[i].first = NULL;
pre[i] = i;
}
for (i=; i<m; ++i) {
scanf("%d %c %d", &srca[i], &op[i], &srcb[i]);
if (op[i] == '=')
merge(srca[i], srcb[i]);
}
flag = false;
for (i=; i<m; ++i) {
if (op[i] == '=')
continue;
x = find(srca[i]);
y = find(srcb[i]);
if (x == y) {
flag = true;
break;
}
if (op[i] == '>')
Insert(x, y);
else
Insert(y, x);
}
if (flag) {
printf("CONFLICT\n");
continue;
}
queue<int> que;
int index;
ArcNode *p;
m = ;
for (i=; i<n; ++i) {
if (i==find(i)) {
++m;
if (nodes[i].count==)
que.push(i);
}
}
while (!que.empty()) {
if (que.size() > )
flag = true;
index = que.front();
que.pop();
p = nodes[index].first;
--m;
while (p != NULL) {
j = p->adjvex;
--nodes[j].count;
if (nodes[j].count == )
que.push(j);
p = p->next;
}
}
if (m)
printf("CONFLICT\n");
else if (flag)
printf("UNCERTAIN\n");
else
printf("OK\n");
} return ;
}

【HDOJ】1811 Rank of Tetris的更多相关文章

  1. 【HDOJ】1813 Escape from Tetris

    bfs预处理一点到边界的最小距离,IDA*求出可行方案.注意按字典序初始化dir数组.并且存在中间点全为1,边界含0的可能性(wa了很多次).此时不输出任何命令. /* 1813 */ #includ ...

  2. 【HDOJ】1760 A New Tetris Game

    博弈,主要是求SG值.终于做出点儿感觉. /* 1760 */ #include <cstdio> #include <cstring> #include <cstdli ...

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

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

  4. HDU 1811 Rank of Tetris 【拓扑排序 + 并查集】

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

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

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

  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)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. mysql 1067 进程意外终止 无法启动

    查看日志 data/XXX.err 发现如下错误 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous ...

  2. 不安装oracle客户端,连接到服务器的oracle (注:针对 odp.net)

    前几天在研究怎样不安装oracle客户端去访问oracle,并把里面的数据同步到本地的Sql Server数据库中. 准备工作:首先你得有如下.dll,我这个是针对oracle10g的,如果是更高的版 ...

  3. Synchronized vs SyncRoot

    我们知道,在.net的一些集合类型中,譬如Hashtable和ArrayList,都有Synchronized静态方法和SyncRoot实例方法,他们之间有联系吗?我怎么才能用好他们呢?我们以Hash ...

  4. BestCoder Round #85 sum

    大晚上的更一道下午的水题吧.(虽然WA了好多次= =,但真实情况是我比较水) 描述 Given a sequence, you're asked whether there exists a cons ...

  5. 设计模式之 Observer Pattern 观察者模式

    1.Subject通过一个容器保存零到多个Observer. 2.Subject通过Add,Delete方法调整Observer. 3.Subject的notifyObservers方法实际是逐个调用 ...

  6. [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法

    最近把一个项目的jQuery升级到最新版,发现有些页面报错Cannot read property ‘msie’ of undefined.上jQuery网站上搜了一下,原因是$.browser这个a ...

  7. 更改input【type=file】样式

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. TCP/IP笔记 应用层(1)——DNS

    1. DNS DNS(Domain Name System ):域名系统,是因特网的一项核心服务,它作为可以将域名和IP地址相互映射的一个分布式数据库,能够使人更方便的访问互联网,而不用去记住能够被机 ...

  9. iOS: 学习笔记, 使用FMDatabase操作sqlite3

    使用FMDatabase操作sqlite3数据库非常简单和方便 // // main.m // iOSDemo0602_sqlite3 // // Created by yao_yu on 14-6- ...

  10. 2016030202 - github中sshkey信息设置

    根据github上面的提示生成ssh秘钥步骤 参考url:https://help.github.com/articles/generating-an-ssh-key/ 1.生成sshkey之前,检查 ...