题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4115

  题意:Alice和Bob玩猜拳游戏,Alice知道Bob每次会出什么,为了游戏公平,Bob对Alice的出法做出了一定限制,限制为Alice的第 i 次和第 j 次的出法相同或者不同。在n轮游戏汇总,如果Alice输了一次,那么Alice是loser。

  Alice每次只有两种选择,要么赢,要么平局,建立2sat模型,然后分情况建立边,分Bob第 i 次和第 j 次的拳不相等和相等两种,然后在这两种里面分对Alice的限制为相同和不相同。

 //STATUS:C++_AC_15MS_464KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int w[N];
int first[N*],next[N*],vis[N*],S[N*];
int T,n,m,mt,cnt; struct Edge{
int u,v;
}e[N*]; void adde(int a,int b)
{
e[mt].u=a,e[mt].v=b;
next[mt]=first[a];first[a]=mt++;
} int dfs(int u)
{
if(vis[u^])return ;
if(vis[u])return ;
int i;
vis[u]=;
S[cnt++]=u;
for(i=first[u];i!=-;i=next[i]){
if(!dfs(e[i].v))return ;
}
return ;
} int Twosat()
{
int i,j;
mem(vis,);
for(i=;i<n;i+=){
if(vis[i] || vis[i^])continue;
cnt=;
if(!dfs(i)){
while(cnt)vis[S[--cnt]]=;
if(!dfs(i^))return ;
}
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,b,c,x,y,ca=;
scanf("%d",&T);
while(T--)
{
mem(first,-);mt=;
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%d",&w[i]);
n<<=;
while(m--){
scanf("%d%d%d",&a,&b,&c);
a--,b--;
x=w[a],y=w[b];
a<<=;b<<=;
if(x==y){
if(c){
adde(a,b^);
adde(a^,b);
adde(b,a^);
adde(b^,a);
}
else {
adde(a,b);
adde(a^,b^);
adde(b,a);
adde(b^,a^);
}
}
else {
if((x== || y==) && x<y)swap(a,b);
else if(x!= && y!= && x>y)swap(a,b);
if(c){
adde(a^,b^);
adde(b,a);
}
else {
adde(a,a^);
adde(b^,b);
}
}
} printf("Case #%d: %s\n",ca++,Twosat()?"yes":"no");
}
return ;
}

HDU-4115 Eliminate the Conflict 2sat的更多相关文章

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

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

  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,拆成六个点. #include<cstdio> #include<cstring> #include<cmath> #include<stack& ...

  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. hdu4115 Eliminate the Conflict

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

  7. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

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

  9. hdu 4115 2-SAT判定

    思路:将每个回合的平手和赢最为一对对立状态.那么后面就是2-SAT判断了. #include<iostream> #include<cstdio> #include<al ...

随机推荐

  1. Project not selected to build for this solution configuration.

    Project not selected to build for this solution configuration.   When you upgrade your older solutio ...

  2. hihocode 第九十二周 数论一·Miller-Rabin质数测试

    题目链接 检测n是否为素数,数据范围为2 <= n <= 10^18; 思路:Miller_Rabin素数检测模板题,原理:在Fetmat定理的基础之上,再利用二次探测定理: 对于任意的正 ...

  3. 自定义MVC路由配置

    首先我用MVC4新增一个订单查看的功能 1.创建控制器OrderController namespace MvcApplication3.Controllers { public class Orde ...

  4. ECshop Strict Standards: Only variables should be passed by reference in解决办法

    本文章来给各位同学介绍关于ECshop Strict Standards: Only variables should be passed by reference in解决办法,希望此教程 对各位同 ...

  5. Nginx完整配置说明

    http://blog.csdn.net/marising/article/details/3979493 可以参考如下的完整例子 http://wiki.codemongers.com/NginxF ...

  6. 接口 --- Java

    package com.test2; public class Test { public static void main(String[] args) { // TODO Auto-generat ...

  7. ANDROID_MARS学习笔记_S01原始版_004_TableLayout

    1.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android ...

  8. mysql select count(filed) 问题(where条件没有数据匹配的话也有数据返回)。

    问题: SELECT count(*),user_id FROM tb_rp_logintrace WHERE id=-1 返回结果: count(*), user_id 0             ...

  9. linux模块安装卸载命令

    lsmod   查看系统安装了那些模块 insmod 安装模块 rmmod 卸载模块 modprobe可安装模块,也可卸载模块 modprobe [-acdlrtvV][--help][模块文件][符 ...

  10. shutdown,init,halt,poweroff,reboot的区别和联系, pkill -kill -t tty7注销

    前言 最近这些天,每天晚上关机前,都会在osc上发一条动弹,“我要init 0了,各位晚安啊”,这是一件再正常不过的事情了. 看似很平常的一件事情,不过在昨晚就被一位同学的回复给难住了,到底是什么样的 ...