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. 【转】android技术栈

    android技术栈-现有使用的进行一个汇总(初稿) 2017年04月24日 16:19:40 阅读数:2004 android技术栈 开发工具 Android studio 开发语言 Java 自动 ...

  2. ES6学习笔记(3)----字符串的扩展

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 字符串的扩展ES6之前只能识别\u0000 - \uFFFF 之间的字符,超过此范围,识别会出错 ...

  3. jsonp对付同源策略

    当 协议不同或者域名/ip不同或者端口号不同 ,  都不算是同源 这时候 源生的ajax 就不能进行数据请求了 JSONP json with padding 在平时的开发中也发现了  ,当我们请求  ...

  4. Bundle的用法

    一.API文档说明 1.介绍 用于不同Activity之间的数据传递 1.重要方法 clear():清除此Bundle映射中的所有保存的数据. clone():克隆当前Bundle containsK ...

  5. iOS开发中的HTML解析

    在进行解析前,先将下面的第三方类添加到工程中: 添加以上三个类必须添加一个库,这个库是:libxml2.2.dylib. 还需要设置一些路径参数这个路径的设置,在 targets中,在build se ...

  6. 洛谷 P1351 联合权值

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  7. css3新增属性:多列(column)

    css3多列能够创建多个列来对文本进行布局,就想报纸那样. 关于多列的相关属性及属性值如下: column-count: number|auto;:指定元素应分为的列数.column-fill: 指定 ...

  8. Maven实战读书笔记(二):Maven坐标与仓库

    2.1 Maven坐标 Maven坐标是Maven用来表示一个组件依赖的标示. Maven通过下面几个元素定义坐标:groupId.artifactId.version.packaging.class ...

  9. ios之UITableView

    今天要分享的是IOS开发中一个使用率非常高的一个控件-------UITableView,这两天正在使用tableview做信息的显示,在写代码时对tableview和tableviewcell的几种 ...

  10. POJ-1328-放置雷达

    这是一道贪心的题目,首先我们要知道,我们放置雷达的话我们可以做一个转换,就是已知岛屿的点坐标的时候,我们可以算一下,这个点以d为半径与x轴交点之间的线段在x轴上的投影,然后我们只需要在这个投影范围内设 ...