hdu4115 Eliminate the Conflict
Eliminate the Conflict
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1114 Accepted Submission(s): 468
Edward contributes his lifetime to invent a 'Conflict Resolution Terminal' and he has finally succeeded. This magic item has the ability to eliminate all the conflicts. It works like this:
If any two people have conflict, they should simply put their hands into the 'Conflict Resolution Terminal' (which is simply a plastic tube). Then they play 'Rock, Paper and Scissors' in it. After they have decided what they will play, the tube should be opened and no one will have the chance to change. Finally, the winner have the right to rule and the loser should obey it. Conflict Eliminated!
But the game is not that fair, because people may be following some patterns when they play, and if the pattern is founded by others, the others will win definitely.
Alice and Bob always have conflicts with each other so they use the 'Conflict Resolution Terminal' a lot. Sadly for Bob, Alice found his pattern and can predict how Bob plays precisely. She is very kind that doesn't want to take advantage of that. So she tells Bob about it and they come up with a new way of eliminate the conflict:
They will play the 'Rock, Paper and Scissors' for N round. Bob will set up some restricts on Alice.
But the restrict can only be in the form of "you must play the same (or different) on the ith and jth rounds". If Alice loses in any round or break any of the rules she loses, otherwise she wins.
Will Alice have a chance to win?
Each test case contains several lines.
The first line contains two integers N,M(1 <= N <= 10000, 1 <= M <= 10000), representing how many round they will play and how many restricts are there for Alice.
The next line contains N integers B
1,B
2, ...,B
N, where B
i represents what item Bob will play in the i
th round. 1 represents Rock, 2 represents Paper, 3 represents Scissors.
The following M lines each contains three integers A,B,K(1 <= A,B <= N,K = 0 or 1) represent a restrict for Alice. If K equals 0, Alice must play the same on A
th and B
th round. If K equals 1, she must play different items on Ath and Bthround.
3 3
1 1 1
1 2 1
1 3 1
2 3 1
5 5
1 2 3 2 1
1 2 1
1 3 1
1 4 1
1 5 1
2 3 0
Case #2: yes
'Rock, Paper and Scissors' is a game which played by two person. They should play Rock, Paper or Scissors by their hands at the same time.
Rock defeats scissors, scissors defeats paper and paper defeats rock. If two people play the same item, the game is tied..
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<vector>
using namespace std;
#define N 40080 /*顶点总数,包括拆点以后的*/
#define inf 0x4f4f4f4f
vector<int>g[N]; /*邻接表*/
int n, m; /*顶点数,边数*/
int id[N], pre[N], low[N], s[N], stop, cnt, scnt,pa[N],pb[N][2];
bool flag=true;
void tarjan(int v) { /*求强连通分量,vertex: 0 ~ n-1*/
int t, minc = low[v] = pre[v] = cnt++;
s[stop++] = v;
for (int i = 0; i < g[v].size(); i++) {
if (-1 == pre[g[v][i]]) tarjan(g[v][i]);
if (low[g[v][i]] < minc) minc = low[g[v][i]];
}
if (minc < low[v]) { low[v] = minc; return; }
do { t = s[--stop];id[t] = scnt; low[t] = N; } while (t != v);
++scnt; /*联通分量个数*/
}
int _2sat() {
stop = cnt = scnt = 0;
memset(pre, -1, sizeof (pre));
for (int i = 0; i <n+ n; ++i) if (-1 == pre[i]) tarjan(i);
for (int i = 0; i < n; i++) if (id[i] == id[i + n]) return 0;
return 1;
}
void build(int k) { /**/
for(int i=0;i<=n+n;i++)
g[i].clear();
for(int i=0;i<n;i++)
{
scanf("%d",&pa[i]);
if(pa[i]==1)
pb[i][0]=1,pb[i][1]=2;
else if(pa[i]==2)
pb[i][0]=2,pb[i][1]=3;
else if(pa[i]==3)
pb[i][0]=1,pb[i][1]=3;
} for(int i=0;i<k;i++)
{
int u,v,fl;
scanf("%d%d%d",&u,&v,&fl);
u--,v--;
if(fl==1)
{
if(pb[u][0]==pb[v][0])
{
g[u].push_back(v+n);
g[v].push_back(u+n);
}
if(pb[u][0]==pb[v][1])
{
g[u].push_back(v);
g[v+n].push_back(u+n);
}
if(pb[u][1]==pb[v][0])
{
g[u+n].push_back(v+n);
g[v].push_back(u);
}
if(pb[u][1]==pb[v][1])
{
g[u+n].push_back(v);
g[v+n].push_back(u);
}
}
else
{
if(pb[u][0]!=pb[v][0])
{
g[u].push_back(v+n);
g[v].push_back(u+n);
}
if(pb[u][0]!=pb[v][1])
{
g[u].push_back(v);
g[v+n].push_back(u+n);
}
if(pb[u][1]!=pb[v][0])
{
g[u+n].push_back(v+n);
g[v].push_back(u);
}
if(pb[u][1]!=pb[v][1])
{
g[u+n].push_back(v);
g[v+n].push_back(u);
}
}
} }
int main() {
int k,tt=1,tcase;
scanf("%d",&tcase);
while ( tcase--) {
scanf("%d%d", &n, &k); flag=true;
build(k);
int ans = _2sat();
if(ans){ /**/
printf("Case #%d: yes\n",tt++);
}
else{ /**/
printf("Case #%d: no\n",tt++);
}
}
return 0;
}
hdu4115 Eliminate the Conflict的更多相关文章
- HDU-4115 Eliminate the Conflict 2sat
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4115 题意:Alice和Bob玩猜拳游戏,Alice知道Bob每次会出什么,为了游戏公平,Bob对Al ...
- hdu 4115 Eliminate the Conflict ( 2-sat )
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 4115 Eliminate the Conflict(2-SAT)(2011 Asia ChengDu Regional Contest)
Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...
- HDU 4115 Eliminate the Conflict(2-sat)
HDU 4115 Eliminate the Conflict pid=4115">题目链接 题意:Alice和Bob这对狗男女在玩剪刀石头布.已知Bob每轮要出什么,然后Bob给Al ...
- 图论--2-SAT--HDU/HDOJ 4115 Eliminate the Conflict
Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...
- hdu4115:Eliminate the Conflict
n<=10000局剪刀石头布,对面第i局出Ai,m<=10000种对你出什么提出的要求:Xi Yi Wi 表示第Xi局和第Yi局,Wi=1:必须不同:Wi=0:必须相同,问是否存在你一局都 ...
- HDU 4115 Eliminate the Conflict
2-SAT,拆成六个点. #include<cstdio> #include<cstring> #include<cmath> #include<stack& ...
- Eliminate the Conflict HDU - 4115(2-sat 建图 hhh)
题意: 石头剪刀布 分别为1.2.3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一 ...
- 2-sat(石头、剪刀、布)hdu4115
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
随机推荐
- 论文阅读笔记 - YARN : Architecture of Next Generation Apache Hadoop MapReduceFramework
作者:刘旭晖 Raymond 转载请注明出处 Email:colorant at 163.com BLOG:http://blog.csdn.net/colorant/ 更多论文阅读笔记 http:/ ...
- 通过崩溃地址找错误行数之Delphi版
通过崩溃地址找错误行数之Delphi版2009-5-11 17:42:35 来源: 转载 作者:网络 访问:360 次 被顶:2 次 字号:[大 中 小]核心提示:什么是 MAP 文件?简单地讲, M ...
- 我觉得主要靠积累,难度不是问题,主要靠时间积累,以及兴趣带来的学习能力(我觉得至少5年全职Qt开发经验,才能算精通)
顺便想请教一下,你用QT有几年了? 3年不到 那感觉怎么样?是比较难,还是不难但需要时间才能掌握全部? 很多东西真的要拿来做项目了,才会懂.要靠积累.一开始看看理论貌似都很简单. 但是QT和C++本身 ...
- MTU & MSS 详解记录(转)
先学习理解一下帧的封装格式: 需要注意的是,区别两种帧封装格式:802标准帧和以太网帧 1,在802标准定义的帧格式中,长度字段是指它后续数据的字节长度,但不包括C R C检验 ...
- 爬虫总结_java
基于webmagic的爬虫项目经验小结 大概在1个月前,利用webmagic做了一个爬虫项目,下面是该项目的一些个人心得,贴在这里备份: 一.为什么选择webmagic? 说实话,开源的爬虫框架已经很 ...
- awk 正则表达式
awk 正则表达式.正则运算符详细介绍 前言:使用awk作为文本处理工具,正则表达式是少不了的. 要掌握这个工具的正则表达式使用.其实,我们不必单独去学习它的正则表达式.正则表达式就像一门程序语言,有 ...
- Eclipse无提示的解决办法 和 内容辅助技巧
Eclipse无提示的解决办法 和 内容辅助技巧 一.若发现内容辅助失效没有提示 下面是解决办法,现贴出来与大家共享: 1.菜单window->Preferences->Jav ...
- 使用mex进行混合编程的一些注意事项
1.mxGetPr的使用: Use mxGetPr on arrays of type double only. Use mxIsDouble to validate the mxArray type ...
- 什么是防盗链设置中的空Referer
设置防盗链时候指明和不指明空Referer的差别及实现后的效果? 什么是Referer? 这里的 Referer 指的是HTTP头部的一个字段,也称为HTTP来源地址(HTTP Referer).用来 ...
- 与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知
原文:与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知 [索引页][源码下载] 与众不同 windows phone ( ...