并查集+拓扑排序。使用并查集解决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. Objective-C:内存管理

    1 传统内存管理 Objective-C对象的生命周期可以分为:创建.存在.消亡. 1.1 引用计数 类似Java,Objective-C采用引用计算(reference counting)技术来管理 ...

  2. VS2015+TFS2015源代码管理

    使用Visual Studio连接TFS

  3. RedHat7搭建MongoDB集群

    下载RPM安装包# wget -c -r -N -np -nd -L -nH https://repo.mongodb.org/yum/redhat/7/mongodb-org/stable/x86_ ...

  4. Android源码编译过程之九鼎开发板

    build_kernel() { # 进入源码顶层目录 cd ${BS_DIR_KERNEL} || # 编译配置文件 make ${BS_CONFIG_KERNEL} ARCH=arm CROSS_ ...

  5. Spring 注解回顾

    [copy] 参考资料 赵蒙

  6. PS之放射背景

    效果图 素材 新建图层,填充颜色 新建图层,矩形工具画条形 滤镜-扭曲-极坐标 合并图层,效果如下 新建图层,画一个适当的圆 滤镜-模糊-高斯模糊 将素材人物抠出来放在中间

  7. 第三部分 关于HHibernate中关键字ID的配置

    实体类映射中,必须配置一个关键字,对应着数据表的关键字,大多数的实体类也都有一个属性表示类的唯一性,在实体类配置文件(.hbm.xml)中,<id>元素的就是这个作用. 一个完整的ID配置 ...

  8. js获取UserControl (<uc1>)控件ID

    ASPX: <table> <tr> <td> <uc1:uccalendar id="ucXudaxia" runat="se ...

  9. java_设计模式_状态模式_State Pattern(2016-08-16)

    定义: 当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类. 类图: 状态模式所涉及到的角色有: ● 环境(Context)角色,也成上下文:定义客户端所感兴趣的接口,同时维护一个 ...

  10. mysql修改字符集 转载

    查看编码:    show variables like 'collation_%';    show variables like 'character_set_%';    修改:    MySQ ...