题意:

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

解析:

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

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <sstream>
  4. #include <cstring>
  5. #include <map>
  6. #include <cctype>
  7. #include <set>
  8. #include <vector>
  9. #include <stack>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <bitset>
  14. #define rap(i, a, n) for(int i=a; i<=n; i++)
  15. #define rep(i, a, n) for(int i=a; i<n; i++)
  16. #define lap(i, a, n) for(int i=n; i>=a; i--)
  17. #define lep(i, a, n) for(int i=n; i>a; i--)
  18. #define rd(a) scanf("%d", &a)
  19. #define rlld(a) scanf("%lld", &a)
  20. #define rc(a) scanf("%c", &a)
  21. #define rs(a) scanf("%s", a)
  22. #define pd(a) printf("%d\n", a);
  23. #define plld(a) printf("%lld\n", a);
  24. #define pc(a) printf("%c\n", a);
  25. #define ps(a) printf("%s\n", a);
  26. #define MOD 2018
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define Pair pair<int, int>
  30. #define mem(a, b) memset(a, b, sizeof(a))
  31. #define _ ios_base::sync_with_stdio(0),cin.tie(0)
  32. //freopen("1.txt", "r", stdin);
  33. using namespace std;
  34. const int maxn = 1e5 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
  35. int n, m;
  36. int a[maxn];
  37. vector<int> G[maxn];
  38. int sccno[maxn], vis[maxn], low[maxn], scc_clock, scc_cnt;
  39. stack<int> S;
  40. void init()
  41. {
  42. mem(sccno, );
  43. mem(vis, );
  44. mem(low, );
  45. scc_clock = scc_cnt = ;
  46. for(int i = ; i < maxn; i++) G[i].clear();
  47. }
  48.  
  49. void dfs(int u)
  50. {
  51. low[u] = vis[u] = ++scc_clock;
  52. S.push(u);
  53. for(int i = ; i < G[u].size(); i++)
  54. {
  55. int v = G[u][i];
  56. if(!vis[v])
  57. {
  58. dfs(v);
  59. low[u] = min(low[u], low[v]);
  60. }
  61. else if(!sccno[v])
  62. {
  63. low[u] = min(low[u], vis[v]);
  64. }
  65. }
  66. if(low[u] == vis[u])
  67. {
  68. scc_cnt++;
  69. for(;;)
  70. {
  71. int x = S.top(); S.pop();
  72. sccno[x] = scc_cnt;
  73. if(x == u) break;
  74. }
  75. }
  76. }
  77.  
  78. bool check()
  79. {
  80. for(int i = ; i < n * ; i += )
  81. if(sccno[i] == sccno[i + ])
  82. {
  83. return false;
  84. }
  85. return true;
  86. }
  87.  
  88. int main()
  89. {
  90. int T, kase = ;
  91. cin >> T;
  92. while(T--)
  93. {
  94. init();
  95. int u, v, w;
  96. cin >> n >> m;
  97. for(int i = ; i < n; i++)
  98. cin >> a[i];
  99. for(int i = ; i <= m; i++)
  100. {
  101. cin >> u >> v >> w;
  102. u--, v--;
  103. int x = a[u], y = a[v];
  104. if(w == )
  105. {
  106. if(x == y)
  107. {
  108. G[u << ].push_back(v << | );
  109. G[v << | ].push_back(u << );
  110. G[u << | ].push_back(v << );
  111. G[v << ].push_back(u << | );
  112. }
  113. else if(x != y)
  114. {
  115. if(x == && y == || y == && x == )
  116. {
  117. if(y == && x == )
  118. swap(u, v);
  119. G[u << | ].push_back(v << | ), G[v << ].push_back(u << );
  120. }
  121. else if(x == && y == || y == && x == )
  122. {
  123. if(y == && x == )
  124. swap(u, v);
  125. G[v << | ].push_back(u << | ), G[u << ].push_back(v << );
  126. }
  127. else if(x == && y == || x == && y == )
  128. {
  129. if(x == && y == )
  130. swap(u, v);
  131. G[u << | ].push_back(v << | ), G[v << ].push_back(u << );
  132. }
  133. }
  134. }
  135. else
  136. {
  137. if(x == y)
  138. {
  139. G[u << ].push_back(v << ), G[u << | ].push_back(v << | );
  140. G[v << ].push_back(u << ), G[v << | ].push_back(u << | );
  141. }
  142. else
  143. {
  144. if(x == && y == || x == && y == )
  145. {
  146. if(x == && y == ) swap(u, v);
  147. G[u << | ].push_back(v << ), G[v << ].push_back(u << | );
  148. G[u << ].push_back(u << | ), G[v << | ].push_back(v << );
  149. }
  150. else if(x == && y == || x == && y == )
  151. {
  152. if(x == && y == ) swap(u, v);
  153. G[u << ].push_back(v << | ), G[v << | ].push_back(u << );
  154. G[u << | ].push_back(u << ), G[v << ].push_back(v << | );
  155. }
  156. else if(x == && y == || y == && x == )
  157. {
  158. if(y == && x == ) swap(u, v);
  159. G[u << | ].push_back(v << ), G[v << ].push_back(u << | );
  160. G[u << ].push_back(u << | ), G[v << | ].push_back(v << );
  161. }
  162. }
  163. }
  164. }
  165. for(int i = ; i < n * ; i++)
  166. if(!vis[i]) dfs(i);
  167. printf("Case #%d: ", ++kase);
  168. if(check())
  169. {
  170. cout << "yes" << endl;
  171. }
  172. else cout << "no" << endl;
  173. }
  174.  
  175. return ;
  176. }

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. Final Destination II -- 矩阵快速幂模板题

    求f[n]=f[n-1]+f[n-2]+f[n-3] 我们知道 f[n] f[n-1] f[n-2]         f[n-1]  f[n-2]  f[n-3]         1    1    ...

  2. Linux—vim常用命令

    vim常用命令: 1. 键入i进入编辑模式2. esc进入命令模式3. a,进入编辑模式3. b,光标移动到单词前,end,光标移动到行尾4. home光标移动到行首5. cc,删除当前行,并进入编辑 ...

  3. redis的应用场景 为什么用redis

    一.不是万能的菲关系系数据库redis 在面试的时候,常被问比较下Redis与Memcache的优缺点,个人觉得这二者并不适合一起比较,redis:是非关系型数据库不仅可以做缓存还能干其它事情,Mem ...

  4. 软件工程(FZU2015) 赛季得分榜,第七回合

    SE_FZU目录:1 2 3 4 5 6 7 8 9 10 11 12 13 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分=团队得分+个人贡献分 个人贡献分: 个人 ...

  5. PAT L2-007 家庭房产

    https://pintia.cn/problem-sets/994805046380707840/problems/994805068539215872 给定每个人的家庭成员和其自己名下的房产,请你 ...

  6. CRM系统设计方案

    CRM系统设计方案 - 百度文库https://wenku.baidu.com/view/a34eebeb0242a8956bece473.html 服务支持http://www.uf-crm.com ...

  7. Pseudo Registers

    Pseudoregister Description @ERR Last error value; the same value returned by the GetLastError() API ...

  8. 简述nginx(1)

    Nginx能做什么 1.反向代理 2.负载均衡 3.HTTP服务器(包含动静分离) 4.正向代理 反向代理 反向代理应该是Nginx做的最多的一件事了,什么是反向代理呢,以下是百度百科的说法:反向代理 ...

  9. php常用方法

    在日常开发中,经常我们使用系统方法或者是自己封装的方法进行项目的开发.再此总结一下!!! 一.对于字符串截取 1.使用mbstring扩展  (注意编码的设置) mb_substr($str,2,5, ...

  10. vue 短信验证

    直接贴代码: HTML <div class="phone"> <div class="number"> <p class=&qu ...