hdu4115:Eliminate the Conflict
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的更多相关文章
- hdu4115 Eliminate the Conflict
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 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 ...
- HDU-4115 Eliminate the Conflict 2sat
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4115 题意:Alice和Bob玩猜拳游戏,Alice知道Bob每次会出什么,为了游戏公平,Bob对Al ...
- 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轮的策略不一 ...
- HDU 4115 Eliminate the Conflict
2-SAT,拆成六个点. #include<cstdio> #include<cstring> #include<cmath> #include<stack& ...
- 2-sat(石头、剪刀、布)hdu4115
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
随机推荐
- AJPFX总结线程创建的两种方法
创建线程的第一种方式:继承Thread ,由子类复写run方法.步骤:1,定义类继承Thread类:2,目的是复写run方法,将要让线程运行的代码都存储到run方法中:3,通过创建Thread类的子类 ...
- logging日志过滤和日志文件自动截取
1.日志过滤 import logging class IgnoreFilter(logging.Filter): def filter(self,record): return "girl ...
- html语法第 -2
1 <html> 2 <head> 3 <title>这是第一节课网页标题</title> 4 <meta charset="UTF-8 ...
- 【js数据结构】图的深度优先搜索与广度优先搜索
图类的构建 function Graph(v) {this.vertices = v;this.edges = 0;this.adj = []; for (var i = 0; i < this ...
- ios 设置head请求头,自定义head, read response header
AFHTTPSessionManager *manger = [AFHTTPSessionManager manager]; manger.securityPolicy = [AFSecurityPo ...
- iOS中使用 Reachability 检测网络区分手机网络类型 WiFi 和2 3 4 G
如果你想在iOS程序中提供一仅在wifi网络下使用(Reeder),或者在没有网络状态下提供离线模式(Evernote).那么你会使用到Reachability来实现网络检测. 写本文的目的 了解Re ...
- HTTP协议 处理流程
我们平时在浏览网页的时候都是使用浏览器,输入你要的网址后回车,就会显示出我们所想要的内容,看似这个简单的用户操作行为的背后,Web的工作原理是怎样的呢?到底隐藏了些什么呢? 对于传统的上网流程,系统它 ...
- docker上配置nginx负载均衡
采用ubuntu系统,docker安装自行百度 1.安装tomcat docker run -d -p : tomcat docker run -d -p : tomcat 安装两个实例,端口分别为8 ...
- SQL数据库移植到ARM板步骤
SQL作为一种存储数据的数据结构,具有体积小(能堵存储的数据多),容易移植等优点.例如,在Ubuntu或者ARM开发板上被大量应用.下面就简单说一下SQL移植到ARM板的步骤. 下载源代码 (记得在家 ...
- QT_4_QpushButton的简单使用_对象树
QpushButton的简单使用 1.1 按钮的创建 QPushButton *btn = new QPushButton; 1.2 btn -> setParent(this);设置父窗口 1 ...