大意: 给定有向图, 初始点S, 两个人轮流移动, 谁不能移动则输, 但后手睡着了, 先手可以控制后手操作, 求最后先手结果.

刚开始看错了, 还以为后手也是最优策略.... 实际上判断是否有偶数个节点的路径即可, 每个点拆成奇数跟偶数, 这样图就是一个DAG, 可以DP求出路径, 若不存在的话找一下是否有环, 有环则平局, 无环则输.

  1. #include <iostream>
  2. #include <sstream>
  3. #include <algorithm>
  4. #include <cstdio>
  5. #include <math.h>
  6. #include <set>
  7. #include <map>
  8. #include <queue>
  9. #include <string>
  10. #include <string.h>
  11. #include <bitset>
  12. #define REP(i,a,n) for(int i=a;i<=n;++i)
  13. #define PER(i,a,n) for(int i=n;i>=a;--i)
  14. #define hr putchar(10)
  15. #define pb push_back
  16. #define lc (o<<1)
  17. #define rc (lc|1)
  18. #define mid ((l+r)>>1)
  19. #define ls lc,l,mid
  20. #define rs rc,mid+1,r
  21. #define x first
  22. #define y second
  23. #define io std::ios::sync_with_stdio(false)
  24. #define endl '\n'
  25. #define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
  26. using namespace std;
  27. typedef long long ll;
  28. typedef pair<int,int> pii;
  29. const int P = 1e9+7, INF = 0x3f3f3f3f;
  30. ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
  31. ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
  32. ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
  33. inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
  34. //head
  35.  
  36. #ifdef ONLINE_JUDGE
  37. const int N = 1e6+10;
  38. #else
  39. const int N = 111;
  40. #endif
  41.  
  42. int n, m, ok, dp[2][N], fa[2][N], inq[N];
  43. vector<int> g[N];
  44.  
  45. int dfs(int tp, int x) {
  46. if (ok) return 0;
  47. if (g[x].empty()&&tp==0) return ok=1;
  48. if (dp[tp][x]) return 0;
  49. dp[tp][x] = 1;
  50. for (int y:g[x]) if (dfs(tp^1,y)) return fa[tp][x]=y;
  51. return 0;
  52. }
  53. int dfs(int x) {
  54. inq[x] = 1;
  55. for (int y:g[x]) if (inq[y]||dfs(y)) return inq[x]=0,1;
  56. return inq[x] = 0;
  57. }
  58.  
  59. int main() {
  60. scanf("%d%d", &n, &m);
  61. REP(i,1,n) {
  62. int k, t;
  63. scanf("%d", &k);
  64. REP(j,1,k) scanf("%d", &t),g[i].pb(t);
  65. }
  66. int s;
  67. scanf("%d", &s);
  68. if (dfs(1,s)) {
  69. puts("Win");
  70. int now = 1;
  71. while (s) printf("%d ", s), s=fa[now][s],now^=1;
  72. return hr,0;
  73. }
  74. puts(dfs(s)?"Draw":"Lose");
  75. }

Sleepy Game CodeForces - 936B的更多相关文章

  1. Codeforces 936B

    题意略. 思路: 图论里掺杂了一些动态规划. 有几个注意点: 1.dp时状态的设计:因为我们要寻求的是出度为0并且可以从起点走奇数步抵达的点,由于同一个点可以通过多种方式到达. 并且我们在获得奇数步点 ...

  2. CodeForces 937D 936B Sleepy Game 有向图判环,拆点,DFS

    题意: 一种游戏,2个人轮流控制棋子在一块有向图上移动,每次移动一条边,不能移动的人为输,无限循环则为平局,棋子初始位置为$S$ 现在有一个人可以同时控制两个玩家,问是否能使得第一个人必胜,并输出一个 ...

  3. Codeforces 937D - Sleepy Game

    937D - Sleepy Game 思路: dfs. vis[u][0]==1表示u这个点能从s点偶数路径到达 vis[u][1]==1表示u这个点能从s点奇数路径到达 这个样就能保证dfs时每个点 ...

  4. Codeforces 937 D. Sleepy Game(DFS 判断环)

    题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...

  5. Codeforces 937.D Sleepy Game

    D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Round #467 (Div. 1) B. Sleepy Game

    我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...

  7. Codeforces 390A( 模拟题)

    Inna and Alarm Clock Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64 ...

  8. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

  9. Codeforces Round #467 (div.2)

    Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...

随机推荐

  1. kafka 性能测试脚本

    [参考文章]:Kafka自带的性能测试脚本 1. 生产消息压测脚本 1.1 脚本及参数 bin/kafka-producer-perf-test.sh  --topic kafka-test-0 -- ...

  2. IDEA找回Run Dashboard

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  3. 定时任务-Quartz(热部署、冷部署)

    一.配置Quartz.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context ...

  4. linux常用查看系统操作的linux命令

    系统# uname -a # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue # 查看操作系统版本# cat /proc/cpuinfo # 查看CPU信息# hostna ...

  5. hotspot 线程状态

  6. pid稳态控制

    https://blog.csdn.net/qq_25352981/article/details/81007075

  7. 百度AI接口---身份证识别Demo

    题记:自己是做java web的,但是本人以前接触并学习很多图像的知识,所以对图像很敏感.下面以百度的一个接口,实现身份证识别案例 1.需要百度开发者AppID.SecretKey .API Key. ...

  8. 在smarty模板中截取指定长度的字符串

    在smarty模板中截取指定长度的字符串,可使用truncate这个插件. 用法: {{$data.value|truncate:28:'...'}} 28个字节14个字数输出,多余部分输出...,一 ...

  9. js 中实现 汉字按拼音排序

    let arr = ["贵州省", "江苏省", "江西省", "浙江省", "四川省", &quo ...

  10. JAVA文件上传 ServletFileUpLoad 实例

    1.  jsp <%@ page language="java" contentType="text/html" pageEncoding="u ...