并查集+拓扑排序。使用并查集解决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. (转) Spring读书笔记-----部署我的第一个Spring项目

    一.Spring介绍 Spring是一个轻量级的Java EE容器,它也是一种从实际需求出发,着眼于轻便,灵活,易于开发,易测试和易部署的轻量级开发框架.Spring它完成了大量开发中的通用步骤,留给 ...

  2. 无法加载协定为“ServiceReference1.ReportWsSoap”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。

    前言 引用websevice时,有时会出现如下错误: 异常详细信息: System.InvalidOperationException: 无法加载协定为“ServiceReference1.Repor ...

  3. Error parsing XML: not well-formed (invalid token)

    从网络上或别的文件复制粘贴进来的代码有隐含格式,可将内容先粘贴进记事本清除格式,再复制粘贴进工程文件,即可解决此问题 注:1. 要使工程文件全选清空, 2. 若粘贴后刷新仍无效果,可手动输入

  4. A题笔记(7)

    No. 1468 已知三角形的三条边求面积:海伦公式 S=√[p(p-a)(p-b)(p-c)]   p=(a+b+c)/2 #include <cmath> cmath 是 c++ 语言 ...

  5. error: Unable to find vcvarsall.bat while install python library by pip install or python setup.py install.

    Python 2.7 会搜索 Visual Studio 2008. 如果你电脑上没有这个版本的话,比如只有: 1.Visual Studio 2010,在cmd里面执行:SET VS90COMNTO ...

  6. iOS10新增Api详解

    1.SiriKit SiriKit的功能非常强大,支持音频.视频.消息发送接收.搜索照片.预订行程.管理锻炼等等.在用到此服务时,siri会发送Intent对象,里面包括用户的请求和各种数据,可以对这 ...

  7. C# 匿名表达式(Lambda表达式)

    匿名表达式 这次来说说Lambda表达式吧,反正也简单,我也不像其他高手那样强调来强调去,只讲一下方法: 准备条件如下: 第一,匿名表达式必须存在与之对应的委托. 只要存在相对应的委托就可以了.接下来 ...

  8. 【AngularJS】——0.分析

    [引导分析]1.什么是AngularJS? 2.为什么要使用它? 3.应用场合? 4.基本思想? 5.四大核心特征? 6.优缺点是什么? 1.定义:AngularJS是一个用于设计动态web应用的前端 ...

  9. DependencyProperty

    <Window x:Class="DependencyPropertyDemo.MainWindow" xmlns="http://schemas.microsof ...

  10. SGU Volume 1

    SGU 解题报告(持续更新中...Ctrl+A可看题目类型): SGU101.Domino(多米诺骨牌)------------★★★type:图 SGU102.Coprimes(互质的数) SGU1 ...