题意:

  石头剪刀布 分别为1、2、3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一样,如果又一轮小B输了,那整个就输了,求小B能否战胜小A

解析:

  写出来矛盾的情况  建图就好啦

可能我建的麻烦了。。。不过。。我喜欢 hhhhh

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e5 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m;
int a[maxn];
vector<int> G[maxn];
int sccno[maxn], vis[maxn], low[maxn], scc_clock, scc_cnt;
stack<int> S;
void init()
{
mem(sccno, );
mem(vis, );
mem(low, );
scc_clock = scc_cnt = ;
for(int i = ; i < maxn; i++) G[i].clear();
} void dfs(int u)
{
low[u] = vis[u] = ++scc_clock;
S.push(u);
for(int i = ; i < G[u].size(); i++)
{
int v = G[u][i];
if(!vis[v])
{
dfs(v);
low[u] = min(low[u], low[v]);
}
else if(!sccno[v])
{
low[u] = min(low[u], vis[v]);
}
}
if(low[u] == vis[u])
{
scc_cnt++;
for(;;)
{
int x = S.top(); S.pop();
sccno[x] = scc_cnt;
if(x == u) break;
}
}
} bool check()
{
for(int i = ; i < n * ; i += )
if(sccno[i] == sccno[i + ])
{
return false;
}
return true;
} int main()
{
int T, kase = ;
cin >> T;
while(T--)
{
init();
int u, v, w;
cin >> n >> m;
for(int i = ; i < n; i++)
cin >> a[i];
for(int i = ; i <= m; i++)
{
cin >> u >> v >> w;
u--, v--;
int x = a[u], y = a[v];
if(w == )
{
if(x == y)
{
G[u << ].push_back(v << | );
G[v << | ].push_back(u << );
G[u << | ].push_back(v << );
G[v << ].push_back(u << | );
}
else if(x != y)
{
if(x == && y == || y == && x == )
{
if(y == && x == )
swap(u, v);
G[u << | ].push_back(v << | ), G[v << ].push_back(u << );
}
else if(x == && y == || y == && x == )
{
if(y == && x == )
swap(u, v);
G[v << | ].push_back(u << | ), G[u << ].push_back(v << );
}
else if(x == && y == || x == && y == )
{
if(x == && y == )
swap(u, v);
G[u << | ].push_back(v << | ), G[v << ].push_back(u << );
}
}
}
else
{
if(x == y)
{
G[u << ].push_back(v << ), G[u << | ].push_back(v << | );
G[v << ].push_back(u << ), G[v << | ].push_back(u << | );
}
else
{
if(x == && y == || x == && y == )
{
if(x == && y == ) swap(u, v);
G[u << | ].push_back(v << ), G[v << ].push_back(u << | );
G[u << ].push_back(u << | ), G[v << | ].push_back(v << );
}
else if(x == && y == || x == && y == )
{
if(x == && y == ) swap(u, v);
G[u << ].push_back(v << | ), G[v << | ].push_back(u << );
G[u << | ].push_back(u << ), G[v << ].push_back(v << | );
}
else if(x == && y == || y == && x == )
{
if(y == && x == ) swap(u, v);
G[u << | ].push_back(v << ), G[v << ].push_back(u << | );
G[u << ].push_back(u << | ), G[v << | ].push_back(v << );
}
}
}
}
for(int i = ; i < n * ; i++)
if(!vis[i]) dfs(i);
printf("Case #%d: ", ++kase);
if(check())
{
cout << "yes" << endl;
}
else cout << "no" << endl;
} return ;
}

Eliminate the Conflict HDU - 4115(2-sat 建图 hhh)的更多相关文章

  1. Meeting HDU - 5521 虚点建图

    Problem Description Bessie and her friend Elsie decide to have a meeting. However, after Farmer John ...

  2. HDU 4292 Food (建图思维 + 最大流)

    (点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...

  3. 逃生 HDU 4857(反向建图 + 拓扑排序)

    逃生 链接 Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必 ...

  4. hdu 4115 (2—SAT)

    题意:两个人石头剪刀布,一个人的出法已确定,另一个人的出法有一定约束,某两次要相同或者不同,问你第二个人能否全部都不失败. 思路:根据Bob出的情况,我们可以确定每次Alice有两种方案. R与P,S ...

  5. hdu 4568 Hunter bfs建图+TSP状压DP

    想AC的人请跳过这一段... 题目应该都能读懂.但是个人觉得这题出的很烂,意思太模糊了. 首先,进出次数只能是一次!!这个居然在题目中没有明确说明,让我在当时看到题目的时候无从下手. 因为我想到了这几 ...

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

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

  7. hdu 4115 Eliminate the Conflict ( 2-sat )

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

  8. 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 ...

  9. 图论--2-SAT--HDU/HDOJ 4115 Eliminate the Conflict

    Problem Description Conflicts are everywhere in the world, from the young to the elderly, from famil ...

随机推荐

  1. 语法设计——基于LL(1)文法的预测分析表法

    实验二.语法设计--基于LL(1)文法的预测分析表法 一.实验目的 通过实验教学,加深学生对所学的关于编译的理论知识的理解,增强学生对所学知识的综合应用能力,并通过实践达到对所学的知识进行验证.通过对 ...

  2. Python_每日习题_0005_三数排序

    # 题目: # 输入三个整数x,y,z,请把这三个数由大到小输出. # 程序分析: 练练手就随便找个排序算法实现一下,偷懒就直接调用函数. #方法一:排序 raw = [] for i in rang ...

  3. Minesweeper

    你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统.游戏的目标是找到所有地雷在M x N场中的位置.游戏在一个正方形中显示一个数字,它告诉你在这个正方形附近有 多少个地雷.每个方块最多有八 ...

  4. c++入门之初话结构体

    结构体是一种具有一定数据结构思想的数据类型,我们在对待结构体的时候,用该从数据结构的思想去审视结构体.下面给出结构体的定义 struct mystruct {]; int score; double ...

  5. (第十三周)Final阶段用户调查报告

    项目名:食物链教学工具 组名:奋斗吧兄弟 组长:黄兴 组员:李俞寰.杜桥.栾骄阳.王东涵 用户调查报告 调查时间:2016年12月1日  21:00——2016年12月3日  12:00 项目分享链接 ...

  6. Django lazy load 懒加载 倒序查询

    Django orm默认懒加载   Django orm默认使用的懒加载,即使用的时候才去访问数据库,且每次默认取最少的数据,当然这样有好处也有坏处... 坏处: 会导致频繁的查询数据库,如涉及到外键 ...

  7. openstack-KVM-vCPU

    一.KVM基础功能 (1)支持 硬件支持 VT-x VT-d 系统支持 kernel > 3.5 (2)计算机系统的子系统 CPU 处理器 Memory 内存 Storage 存储 Networ ...

  8. 现代程序设计 homework-10

    经过大半学期的学习和练习, 我们把学到的东西综合起来. 通过<现代程序设计>这门课,自己的确学到了好多东西.其实并不是说讲课有多棒,一是因为讲课的次数其实并不多,二是讲课的内容其实感觉并没 ...

  9. Python3练习题 021:递归方法求阶乘

    利用递归方法求5!. 方法一 f = 1 for i in range(1,6):     f = f * i print(f)   方法二 import functools print(functo ...

  10. css中如何做到容器按比例缩放

    需求: 一般在响应式中,我们会要求视频的宽高比为16:9或4:3,这么一来就比较头大了.当用户改变浏览器宽度的时候(改变高度不考虑),视频的宽度变了,那么高度也得根据我们要求的16:9或4:3改变. ...