hdu 1811 Rank of Tetris
http://acm.hdu.edu.cn/showproblem.php?pid=1811
拓扑排序和并差集
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
#define maxn 10010
using namespace std;
int n,m,c;
int f[maxn],in[maxn];
vector<int>g[maxn];
struct node
{
int x,y;
char ch;
}p[maxn*];
void inti()
{
for(int i=; i<=n; i++)
{
f[i]=i; in[i]=;
g[i].clear();
}
} int find1(int x)
{
if(x==f[x]) return x;
return f[x]=find1(f[x]);
} void merge1(int a,int b)
{
int fa=find1(a);
int fb=find1(b);
if(fa!=fb)
{
f[fb]=fa;
}
} int topp()
{
int flag=;
queue<int>q;
for(int i=; i<n; i++)
{
if(!in[i]&&find1(i)==i) q.push(i);
}
int cnt=;
while(!q.empty())
{
if(q.size()>=) flag=-;
int x=q.front(); q.pop();
cnt++;
for(int i=; i<(int)g[x].size(); i++)
{
if((--in[g[x][i]])==) q.push(g[x][i]);
}
}
if(cnt<c) return ;
return flag;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
inti();
c=n;
for(int i=; i<m; i++)
{
scanf("%d%*c%c%*c%d",&p[i].x,&p[i].ch,&p[i].y);
if(p[i].ch=='=')
{
merge1(p[i].x,p[i].y); c--;
}
}
bool flag=false;
for(int i=; i<m; i++)
{
if(p[i].ch=='=')
{
continue;
}
int x1=find1(p[i].x); int y1=find1(p[i].y);
if(x1==y1) flag=true;
if(p[i].ch=='<')
{
if(find(g[x1].begin(),g[x1].end(),y1)==g[x1].end())
{
g[x1].push_back(y1);
in[y1]++;
}
}
else if(p[i].ch=='>')
{
if(find(g[y1].begin(),g[y1].end(),x1)==g[y1].end())
{
g[y1].push_back(x1);
in[x1]++;
}
}
}
bool flag1=false;
if(!flag)
{
int cc=topp();
if(cc==) flag=true;
else if(cc==-) flag1=true;
}
if(flag)
{
printf("CONFLICT\n");
}
else if(flag1)
{
printf("UNCERTAIN\n");
}
else printf("OK\n");
}
return ;
}
hdu 1811 Rank of Tetris的更多相关文章
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 1811 Rank of Tetris(拓扑排序+并查集)
题目链接: 传送门 Rank of Tetris Time Limit: 1000MS Memory Limit: 32768 K Description 自从Lele开发了Rating系统, ...
- hdu 1811 Rank of Tetris (并查集+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1811 Rank of Tetris 拓补排序+并查集
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [ ...
- HDU 1811 Rank of Tetris(并查集+拓扑排序 非常经典)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1811 Rank of Tetris (拓扑 & 并查集)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- HDU 1811 Rank of Tetris 【拓扑排序 + 并查集】
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
随机推荐
- cf B. Fence
http://codeforces.com/contest/363/problem/B #include <cstdio> #include <cstring> #includ ...
- 数字积分法DDA(DDA(Digital Differential Analyzer)
数字积分法DDA(DDA(Digital Differential Analyzer) 数字积分法又称数字微分分析法DDA(Digital differential Analyzer),是在数字 ...
- fdm_search_info_w_book_chain
数据知识管理平台-元数据管理-fdm_search_info_w_book_chain-详细信息 fdm_search_info_w_book_chain
- 用Nginx实现Session共享的均衡负载
前言 大学三年多,也做个几个网站和APP后端,老是被人问到,如果用户多了服务器会不会挂,总是很尴尬的回答:“哈哈,我们的用户还少,到了服务器撑不住的时候,估计都上市了吧”.说是这么说,但是对于有强迫症 ...
- 关于bootstrap--表单(水平表单)
在Bootstrap框架中要实现水平表单效果,必须满足以下两个条件:1.在<form>元素是使用类名“form-horizontal”.2.配合Bootstrap框架的网格系统.(网格布局 ...
- hdu 4135 Co-prime(容斥)
Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- Mysql 时间操作
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度) 1 . 查看当天日期 select current_date(); 2. 查看当天时间 select current_time(); ...
- NetAnalyzer笔记 之 九 使用C#对HTTP数据还原
[创建时间:2016-05-12 00:19:00] NetAnalyzer下载地址 在NetAnalyzer2016中加入了一个HTTP分析功能,很过用户对此都很感兴趣,那么今天写一下具体的实现方式 ...
- 执行eclipse,迅速failed to create the java virtual machine。
它们必须在一排,否则会出现The Eclipse executable launcher was unable to locate its companion shared library的错误 打开 ...
- idmap_ad — Samba's idmap_ad Backend for Winbind《转载》
Name idmap_ad — Samba's idmap_ad Backend for Winbind DESCRIPTION The idmap_ad plugin provides a way ...