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 ...
随机推荐
- Android里的 ART、JIT、AOT、Dalvik之间有什么关系?
ART.JIT.AOT.Dalvik之间有什么关系? JIT与Dalvik JIT是"Just In Time Compiler"的缩写,就是"即时编译技术", ...
- kde framework概述(KDE Framework译文)
KDE Frameworks 基于QT框架,提供简单实用的类(例如那些KCoreAddons里的类)去为桌面应用的日常需要整合出解决方案(例如KNewStuff用于在应用中获取可下载的附加内容,或者那 ...
- 【数据分析 R语言实战】学习笔记 第六章 参数估计与R实现(下)
6.3两正态总体的区间估计 (1)两个总体的方差已知 在R中编写计算置信区间的函数twosample.ci()如下,输入参数为样本x, y,置信度α和两个样本的标准差. > twosample. ...
- mac及windows下安装ss实现***
官网下载shadowsock(mac/windows都是下面地址,页面会根据当前系统自动判断所下载的包) https://sourceforge.net/projects/shadowsocksgui ...
- MyBatis学习(三)
前言 感觉学习进度还是比较慢啊,一整天的学习效率不是很高,一会看电视,一会喝茶,对自己的要求不严格...今天就说说关联表数据的插入以及别名的使用. 正文 1.关联插入 之前,我在数据库中已经创建了一张 ...
- 诊断Java代码中常见的数据库性能热点问题应该这么做!
“你的Java应用程序的性能是怎样诊断和优化的?不妨看看这两位西医的方子.如果你有更好疗效的药方,也欢迎在评论区告诉我们. 当我在帮助一些开发者或架构师分析及优化Java应用程序的性能时,关键往往不在 ...
- EOS Dawn 3.0 智能合约 -- 新格式
1.简介 随着EOS Dawn 3.0发布,智能合约的坑又要重新踩了o(╥﹏╥)o:3.0不仅将原来本身就在链里的基础合约独立出来,简单的介绍见3.0合约改变,合约的书写方式也有巨大变化,相比之前更加 ...
- Python3简明教程(六)—— 数据结构
简单的来说,数据结构(data structure)是计算机中存储.组织数据的方式.比如我们之前使用过的列表就是一种数据结构,在这里我们还会深入学习它.之前也有简单的介绍. 列表 >>&g ...
- SQL 中 NOT IN 查询不到数据
一.问题 用以下sql语句查询数据,结果为空 SELECT a.ID , a.Sub_Project_Name , a.Sub_Project_Type FROM TB_KYSubProject a ...
- ZOJ - 1655 Transport Goods(单源最长路+迪杰斯特拉算法)
题目: 有N-1个城市给首都(第N个城市)支援物资,有M条路,走每条路要耗费一定百分比(相对于这条路的起点的物资)的物资.问给定N-1个城市将要提供的物资,和每条路的消耗百分比.求能送到首都的最多的物 ...