题目大意:给你一个有向图, Bob 和 Alice 在做游戏,每轮他们走一步,当Bob 和 Alice在同一个点或者 Bob无路可走,Bob输,否则Alice输。

思路:因为在Bob赢的时候存在有环的情况, 但是在Bob输的时候的状态是明确的,我们利用Bob输的状态进行必胜比败态推演,

f[ i ][ j ][ k ] 表示Alice在i ,Bob在j 且轮到k走  Bob是必输还是必胜。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int n, m, B, A, deg[N], num[N][N][];
vector<int> edge[N], redge[N];
int f[N][N][], vis[N][N][]; struct node {
node(int x, int y, int d) {
this->x = x;
this->y = y;
this->d = d;
}
int x, y, d;
}; void init() {
for(int i = ; i < N; i++) {
edge[i].clear(); redge[i].clear();
} memset(deg, , sizeof(deg));
memset(vis, , sizeof(vis));
memset(num, , sizeof(num)); for(int i = ; i < N; i++)
for(int j = ; j < N; j++)
f[i][j][] = f[i][j][] = ; } void bfs() {
queue<node> que;
for(int i = ; i <= n; i++) {
for(int j = ; j <= n; j++) {
for(int k = ; k < ; k++) {
if(i == j) {
f[i][j][k] = ;
que.push(node(i, j, k));
vis[i][j][k] = ;
} else if(k == ) {
if(!edge[j].size()) {
f[i][j][k] = ;
que.push(node(i, j, k));
vis[i][j][k] = ;
}
}
}
}
} while(!que.empty()) {
node cur = que.front(); que.pop();
if(!cur.d) {
for(int i = ; i < redge[cur.y].size(); i++) {
int nxy = redge[cur.y][i];
if(vis[cur.x][nxy][]) continue;
num[cur.x][nxy][]++; if(num[cur.x][nxy][] == deg[nxy]) {
f[cur.x][nxy][] = ;
vis[cur.x][nxy][] = ;
que.push(node(cur.x, nxy, ));
} }
} else {
for(int i = ; i < redge[cur.x].size(); i++) {
int nxx = redge[cur.x][i];
if(vis[nxx][cur.y][]) continue; f[nxx][cur.y][] = ;
vis[nxx][cur.y][] = ;
que.push(node(nxx, cur.y, ));
}
}
}
} int main() {
int T; scanf("%d", &T);
for(int cas = ; cas <= T; cas++) {
init(); scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++) {
int u, v; scanf("%d%d", &u, &v);
edge[u].push_back(v);
redge[v].push_back(u);
deg[u]++;
} scanf("%d%d", &B, &A); bfs(); printf("Case #%d: ", cas);
printf("%s\n", f[A][B][] ? "Yes" : "No");
}
return ;
} /*
*/

UVALive - 7042 The Problem to Make You Happy 博弈的更多相关文章

  1. UVALive - 7041 The Problem to Slow Down You (回文树)

    https://vjudge.net/problem/UVALive-7041 题意 给出两个仅包含小写字符的字符串 A 和 B : 求:对于 A 中的每个回文子串,B 中和该子串相同的子串个数的总和 ...

  2. UVAlive 7041 The Problem to Slow Down You(回文树)

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  3. Uvalive 7037 The Problem Needs 3D Arrays(最大密度子图)

    题意:给一段子序列,定义密度:子序列中的逆序对数/子序列的长度 求这个序列的对大密度. 分析:将序列中的每个位置视作点,逆序对\(<i,j>\)之间表示点i与点j之间有一条无向边.所以就转 ...

  4. Guardian of Decency(二分图)

    Guardian of Decency Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  5. 爆零后的感受外加一道强联通分量HDU 4635的题解

    今天又爆零了,又是又,怎么又是又,爆零爆多了,又也就经常挂嘴边了,看到这句话,你一定很想说一句””,弱菜被骂傻,也很正常啦. 如果你不开心,可以考虑往下看. 翻到E(HDU 4635 Strongly ...

  6. bzoj千题计划260:bzoj2940: [Poi2000]条纹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2940 SG 博弈入门推荐张一飞的<由感性认识到理性认识 ——透析一类搏弈游戏的解答过程> ...

  7. POJ2234 Matches Game 尼姆博弈 博弈论

    http://poj.org/problem?id=2234 尼姆博弈(Nimm's Game) 指的是这样一个博弈游戏:有任意堆物品,每堆物品的个数是任意的,双方轮流从中取物品,每一次只能从一堆物品 ...

  8. A Boring Problem UVALive - 7676 (二项式定理+前缀和)

    题目链接: I - A Boring Problem UVALive - 7676 题目大意:就是求给定的式子. 学习的网址:https://blog.csdn.net/weixin_37517391 ...

  9. Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

随机推荐

  1. mybatis的mapper的特殊符号处理

    这种问题在xml处理sql的程序中经常需要我们来进行特殊处理. 其实很简单,我们只需作如下替换即可避免上述的错误: < <= > >= & ' " < ...

  2. c++ string写时复制

    string写时复制:将字符串str1赋值给str2后,除非str1的内容已经被改变,否则str2和str1共享内存.当str1被修改之后,stl才为str2开辟内存空间,并初始化. #include ...

  3. ZooKeeper动态配置(十四)

    概述 在3.5.0发行之前,ZK的全体成员和所有其它的配置参数是静态加载的在启动的时候并且在运行的时候不可变.操作员诉诸于"滚动重启" - 一个手动密集和改变配置文件容易出错的方法 ...

  4. MongoDB入门(7)- SpringDataMongoDB

    入门 本文介绍如何应用SpringDataMongoDB操作实体和数据库,本文只介绍最基本的例子,复杂的例子在后面的文章中介绍. SpringDataMongoDB简介 SpringDataMongo ...

  5. Linux检测硬盘读取速度

    1. 清空缓存 > /proc/sys/vm/drop_caches 2. 测试读取速度 a. 将/dev/zero中数据按1M的数据单位写入testfile,共写512个单位,并不通过缓存 c ...

  6. [Luogu 1533] 可怜的狗狗

    平衡树,我用的SBT. 排一下序尽量减少操作次数. 第K大询问. 以及插入删除. #include <algorithm> #include <cstdio> #include ...

  7. 【BZOJ1975】【SDOI2010】魔法猪学院 [A*搜索]

    魔法猪学院 Time Limit: 10 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description iPig在假期来到了传说中的魔法猪 ...

  8. java 连接MySQL的代码

    1.java connect MySQL as conding. https://www.cnblogs.com/centor/p/6142775.html

  9. bing查询旁站脚本

    #!/usr/bin/env python # -*- coding: UTF-8 -*- #by i3ekr import re,optparse,sys,requests,time,os pars ...

  10. H264协议(转)

    码率(Bitrate).帧率(FPS).分辨率和清晰度的联系与区别:https://blog.csdn.net/pc9319/article/details/79621352 H.264编码原理以及I ...