UVALive - 7042 The Problem to Make You Happy 博弈
题目大意:给你一个有向图, 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 博弈的更多相关文章
- UVALive - 7041 The Problem to Slow Down You (回文树)
https://vjudge.net/problem/UVALive-7041 题意 给出两个仅包含小写字符的字符串 A 和 B : 求:对于 A 中的每个回文子串,B 中和该子串相同的子串个数的总和 ...
- UVAlive 7041 The Problem to Slow Down You(回文树)
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- Uvalive 7037 The Problem Needs 3D Arrays(最大密度子图)
题意:给一段子序列,定义密度:子序列中的逆序对数/子序列的长度 求这个序列的对大密度. 分析:将序列中的每个位置视作点,逆序对\(<i,j>\)之间表示点i与点j之间有一条无向边.所以就转 ...
- Guardian of Decency(二分图)
Guardian of Decency Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- 爆零后的感受外加一道强联通分量HDU 4635的题解
今天又爆零了,又是又,怎么又是又,爆零爆多了,又也就经常挂嘴边了,看到这句话,你一定很想说一句””,弱菜被骂傻,也很正常啦. 如果你不开心,可以考虑往下看. 翻到E(HDU 4635 Strongly ...
- bzoj千题计划260:bzoj2940: [Poi2000]条纹
http://www.lydsy.com/JudgeOnline/problem.php?id=2940 SG 博弈入门推荐张一飞的<由感性认识到理性认识 ——透析一类搏弈游戏的解答过程> ...
- POJ2234 Matches Game 尼姆博弈 博弈论
http://poj.org/problem?id=2234 尼姆博弈(Nimm's Game) 指的是这样一个博弈游戏:有任意堆物品,每堆物品的个数是任意的,双方轮流从中取物品,每一次只能从一堆物品 ...
- A Boring Problem UVALive - 7676 (二项式定理+前缀和)
题目链接: I - A Boring Problem UVALive - 7676 题目大意:就是求给定的式子. 学习的网址:https://blog.csdn.net/weixin_37517391 ...
- 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 ...
随机推荐
- 使用springcloud的feign调用服务时出现的错误:关于实体转换成json错误的介绍
http://blog.csdn.net/java_huashan/article/details/46428971 原因:实体中没有添加无参的构造函数 fastjson的解释: http://www ...
- 题解【bzoj2427 [HAOI2010]软件安装】
Description 现在我们的手头有\(N\)个软件,对于一个软件\(i\),它要占用\(W_i\)的磁盘空间,它的价值为\(V_i\).我们希望从中选择一些软件安装到一台磁盘容量为\(M\)计算 ...
- cas 服务端、客服端详细配置
一.准备 1.下载官方源码 CAS-Server下载地址:https://www.apereo.org/projects/cas/download-cas CAS-Client下载地址:http:// ...
- sumblime快捷键
原文地址:https://blog.csdn.net/shutfuckingup/article/details/23846603 Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的 ...
- 如何使用webpack打包你的项目
webpack是前端开发中比较常用的打包工具之一,另外还有gulp,grunt.之前没有涉及过打包这块,这里介绍一下使用webpack打包的流程. Grunt和Gulp的工作方式是:在一个配置文件中, ...
- C++获取系统时间的方法
//首先是了解这个结构体,_SYSTEMTIME ,然后通过系统函数GetLocalTime往这个结构体的变量中写入当前系统时间typedef struct _SYSTEMTIME { WORD wY ...
- 《Applying Deep Learning to Answer Selection: A Study And an Open Task》文章理解小结
本篇论文是2015年的IBM watson团队的. 论文地址: 这是一篇关于QA问题的一篇论文: 相关论文讲解1.https://www.jianshu.com/p/48024e9f7bb22.htt ...
- Coursera在线学习---第八节.K-means聚类算法与主成分分析(PCA)
一.K-means聚类中心初始化问题. 1)随机初始化各个簇类的中心,进行迭代,直到收敛,并计算代价函数J. 如果k=2~10,可以进行上述步骤100次,并分别计算代价函数J,选取J值最小的一种聚类情 ...
- linux进程管理-定时定期执行任务
0.计划任务的命令: at 安排作业在某一时刻执行 batch 安排作业在系统负载不重时执行 crontab 安排周期性运行的作业 1.at命令用法: 安排命令或者多个命令在指定的时间运行一次 语法 ...
- Part2-HttpClient官方教程-Chapter2-连接管理
2.1 连接持久性 建立从一个主机到另一个主机的连接的过程相当复杂,并且涉及两个端点之间的多个分组交换,这可能相当耗时.连接握手的开销可能很大,特别是对于小型的HTTP消息. 如果可以重新使用开放连接 ...