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. 【学习笔记】彻底理解JS中的this

    首先必须要说的是,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象(这句话有些问题,后面会解释为什么会有问题,虽然 ...

  2. 磁盘格式化mke2fs

    -b 设置每个块的大小,当前支持1024,2048,40963种字节 -i 给一个inode多少容量 -c 检查磁盘错误,仅执行一次-c时候,会进行快速读取测试:-c -c会测试读写,会很慢 -L 后 ...

  3. virtualbox没有64位选项

    今天安装的virtualbox想安装一下sql server 测试一下 在安装系统的时候发现没有64位系统的选项,在网上找了一下 发现是  在BIOS里面有一个选项没有开启, 是 Intel virt ...

  4. PHP实现远程图片下载

    /** * 文件下载 * @param string $url */ public function download() { $url = $this->input->get_post( ...

  5. x86和i386

    x86: 1 9 7 8年6月,I n t e l公司推出了8 0 8 6,一个1 6位微处理器,它可访问的存储空间达到1 M B. Intel x86家族继续发展,1 9 8 5年出现了3 2位的3 ...

  6. vue 高度 动态更新计算 calcHeight watch $route

    vue 高度 动态更新计算 calcHeight () { // this.tableHeight = window.innerHeight - 210 } }, mounted () { // co ...

  7. Asp.Net Core 入门(四)—— Model、View、Controller

    和我们学习Asp.Net MVC一样,Asp.Net Core MVC的Model.View.Controller也和我们熟悉的Asp.Net MVC中的相似.不同的是我们在使用Asp.Net Cor ...

  8. reciting

    When I was seventeen, I read a quote that went something like, '' if you live your each day as if it ...

  9. vue与node和npm关系

    (1)node功能 准确的说是使用vue-cli 脚手架搭建项目的时候需要nodejs.也可以用script标签引入vue.min.js这样的,在js里实例化vue也行. 使用node有几件事,打包部 ...

  10. 数据库课程设计 PHP web实现

    纪念一下自己写的东西.. 都说很垃圾就是了 直接用XAMPP做的 菜鸟网上学的PHP和HTML <!DOCTYPE html> <html> <head> < ...