n<=10000局剪刀石头布,对面第i局出Ai,m<=10000种对你出什么提出的要求:Xi Yi Wi 表示第Xi局和第Yi局,Wi=1:必须不同;Wi=0:必须相同,问是否存在你一局都不能输的可行解。

一开始对面就把你每局的选择减成2个了,又是一个2-SAT问题。至于建图一定要考虑周全!注意一个条件对Xi和Yi带来的影响都要考虑!

A和B必须不同:

A和B必须相同:错误!未考虑清楚“必须相同”的含义,就是说,如果B没有一样的,那么A这个就不能选!

那么还要把这些不能选的点删掉吗?看了大神博客,发现神奇姿势:这样A1和B3就永远不可能选了,因为一旦选立刻出现矛盾。

注意事项:由于建边过程繁琐,中途思路混乱WA了一次。注意检查!!!

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
//#include<iostream>
using namespace std; int n,m,T;
#define maxn 10011*2
#define maxe 10011*4
struct Edge{int to,next;};
struct Graph
{
Edge edge[maxe];int le;
int first[maxn],vis[maxn];
void clear()
{
le=;
memset(first,,sizeof(first));
}
void insert(int x,int y)
{
edge[le].to=y;
edge[le].next=first[x];
first[x]=le++;
}
int sta[maxn],top;
bool dfs(int x)
{
if (vis[x^]) return ;
if (vis[x]) return ;
vis[x]=;
sta[++top]=x;
for (int i=first[x];i;i=edge[i].next)
if (!dfs(edge[i].to)) return ;
return ;
}
bool twosat()
{
memset(vis,,sizeof(vis));
for (int i=;i<=n;i++)
if (!vis[i*] && !vis[i*+])
{
top=;
if (!dfs(i*))
{
for (;top;top--) vis[sta[top]]=;
if (!dfs(i*+)) return ;
}
}
return ;
}
}G;
struct Point
{
int a,b;
}game[maxn];
int x,y,w;
int main()
{
scanf("%d",&T);
for (int t=;t<=T;t++)
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d",&x);
if (x==) {game[i].a=;game[i].b=;}
if (x==) {game[i].a=;game[i].b=;}
if (x==) {game[i].a=;game[i].b=;}
}
G.clear();
for (int i=;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&w);
if (w)
{
if (game[x].a==game[y].a)
{
G.insert(x*,y*+);
G.insert(y*,x*+);
}
if (game[x].a==game[y].b)
{
G.insert(x*,y*);
G.insert(y*+,x*+);
}
if (game[x].b==game[y].a)
{
G.insert(x*+,y*+);
G.insert(y*,x*);
}
if (game[x].b==game[y].b)
{
G.insert(x*+,y*);
G.insert(y*+,x*);
}
}
else
{
if (game[x].a==game[y].a)
{
G.insert(x*,y*);
G.insert(y*,x*);
}
else if (game[x].a==game[y].b)
{
G.insert(x*,y*+);
G.insert(y*+,x*);
}
else G.insert(x*,x*+);
if (game[x].b==game[y].a)
{
G.insert(x*+,y*);
G.insert(y*,x*+);
}
else if (game[x].b==game[y].b)
{
G.insert(x*+,y*+);
G.insert(y*+,x*+);
}
else G.insert(x*+,x*);
if (game[y].a!=game[x].a && game[y].a!=game[x].b)
G.insert(y*,y*+);
if (game[y].b!=game[x].a && game[y].b!=game[x].b)
G.insert(y*+,y*);
}
}
printf("Case #%d: ",t);
if (G.twosat()) printf("yes");else printf("no");
puts("");
}
return ;
}

hdu4115:Eliminate the Conflict的更多相关文章

  1. hdu4115 Eliminate the Conflict

    Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

  2. hdu 4115 Eliminate the Conflict ( 2-sat )

    Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  3. 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 ...

  4. HDU 4115 Eliminate the Conflict(2-sat)

    HDU 4115 Eliminate the Conflict pid=4115">题目链接 题意:Alice和Bob这对狗男女在玩剪刀石头布.已知Bob每轮要出什么,然后Bob给Al ...

  5. 图论--2-SAT--HDU/HDOJ 4115 Eliminate the Conflict

    Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...

  6. HDU-4115 Eliminate the Conflict 2sat

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4115 题意:Alice和Bob玩猜拳游戏,Alice知道Bob每次会出什么,为了游戏公平,Bob对Al ...

  7. 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轮的策略不一 ...

  8. HDU 4115 Eliminate the Conflict

    2-SAT,拆成六个点. #include<cstdio> #include<cstring> #include<cmath> #include<stack& ...

  9. 2-sat(石头、剪刀、布)hdu4115

    Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

随机推荐

  1. 利用贝塞尔曲线绘制(UIBezierPath)自定义iOS动态速度表,可以自定义刻度,刻度值,进度条样式

    GitHub的Demo下载地址 使用UIBezierPath画图步骤: 创建一个UIBezierPath对象 调用-moveToPoint:设置初始线段的起点 添加线或者曲线去定义一个或者多个子路径 ...

  2. ES6学习笔记(4)----正则的扩展

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 正则的扩展 ES6新增的正则表达式修饰符 u修饰符a.能够更准确地匹配unicode大于\uFF ...

  3. HV000184: ParameterMessageInterpolator has been chosen, EL interpolation will not be supported问题解决

    今天创建springboot项目的时候添加完依赖启动出现了这个错误 -- :: --- [ main] o.h.v.m.ParameterMessageInterpolator : HV000184: ...

  4. Kali 2017.3开启VNC远程桌面登录

    通过启用屏幕共享来开启远程桌面登录,开启后需要关闭encryption,否则会出现无法连接的情况.关闭encryption可以使用系统配置工具dconf来完成.所以先安装dconf-editor. 更 ...

  5. python_使用qrcode生成二维码

    1.功能 使用qrcode生成二维码 2.代码 #生成二维码: import qrcode #根据url生成二维码 def qrcodeWithUrl(url): img = qrcode.make( ...

  6. WPF知识点全攻略00- 目录

    知识点目录如下: 1.WPF相对WinFrom的优缺点 2.WPF体系结构 3.XAML 4.XAML页面布局 5.XAML内容控件 6.WPF中的“树” 7.Binding 8.依赖属性 9.附加属 ...

  7. this.treeData = JSON.parse(JSON.stringify(this.d)) 树的序列化反序列化

    this.treeData = JSON.parse(JSON.stringify(this.d))

  8. MySQL丨02丨忘记root用户密码怎么办?

    软件:Mysql 版本:8.0.13 1. 先暂停mysql的服务,方法是在cmd里输入如下代码: net stop mysql 2. 在安装文件夹下创建一个文件:mysql-ini.txt (我的安 ...

  9. python基础(一)—— 核心数据类型

    Hello World程序 [root@mysql ~]# python3 Python 3.6.5 (default, Jul  8 2018, 11:41:23) [GCC 4.4.7 20120 ...

  10. Go:sync.Once 实现单例模式

    代码: package main import ( "fmt" "sync" ) type Singleton struct{} var singleton * ...