题意:Bob和Alice在一张有向无环图上移动,给定二者的起点,Bob先手.Bob的失败条件是不能移动或者与Alice相遇.两个人都采取最优策略,求Bob是否会赢

分析:银牌题.先确定所有的失败状态,然后根据这些反向状态BFS.

用\(dp[i][j][0or1]\)表示bob在i点,Alice在j点,当前移动的人是bob还是Alice的情况, bob是否必败.

首先能确定的是 \(dp[i][j][0] = dp[i][j][1] = 0\), 对于出度为0的点\(i\),\(dp[i][j][0]= 0\).

搜索时有两种状态:

一是当前手是Bob,上一次是Alice,因为两者都选择最优策略,所以Alice肯定会选择让Bob的必败的状态,所以能达到该状态的其余状态都是必败态,将其入队列.

二是当前为Alice,上一次是Bob.Bob肯定不会选择让自己必败的状态,除非它的每一个选择都会走到必败态.统计这个前驱状态会走到的必败态的个数,若此个数等于这个前驱点的出度,表示状态出发的所有状态,Bob都是必败,则这个状态也是必败,将其入队列.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e2+5;
int x,y;
int dp[MAXN][MAXN][2];
int deg[MAXN]; //出度
int num[MAXN][MAXN]; //失败的标记
struct Edge{
int v,next;
}E[MAXN*MAXN] ,rE[MAXN*MAXN];
int rhead[MAXN],rtot,N, M; void init()
{
memset(num,0,sizeof(num));
memset(deg,0,sizeof(deg));
memset(rhead,-1,sizeof(rhead));
rtot = 0;
} void rAddEdge(int u,int v)
{
rE[rtot] = (Edge){v,rhead[u]};
rhead[u] = rtot++;
} struct Node{
int a, b, cur;
};
bool BFS()
{
memset(dp, -1,sizeof(dp));
queue<Node> Q; //从所有的必败态开始反着搜
for(int i=1;i<=N;++i){
Q.push((Node){i,i,0}); //都是必败态
Q.push((Node){i,i,1});
dp[i][i][0] = dp[i][i][1] = 0;
if(!deg[i]){
for(int j=1;j<=N;++j){
if(j==i) continue;
Q.push((Node){i,j,0});
dp[i][j][0] = 0;
}
}
} while(!Q.empty()){
Node x = Q.front(); Q.pop();
int a = x.a , b = x.b, cur = x.cur;
int nxt = cur^1;
if(!cur){ //Bob
int u = b;
for(int i = rhead[u]; ~i ;i = rE[i].next){
int v = rE[i].v;
if(dp[a][v][1] ==-1){
dp[a][v][1] = 0;
Q.push((Node){a,v,1});
}
}
}else{ //Alice
int u = a;
for(int i = rhead[u]; ~i ; i = rE[i].next){
int v = rE[i].v;
num[v][b]++;
if(num[v][b]>= deg[v] && dp[v][b][0]==-1){
dp[v][b][0] = 0;
Q.push((Node){v,b,0});
}
}
}
}
if(dp[x][y][0]==0) return false;
return true;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int T,cas=1; scanf("%d",&T);
while(T--){
init();
scanf("%d %d ",&N, &M);
int u, v;
while(M--){
scanf("%d %d",&u, &v);
rAddEdge(v,u); //反向建图
deg[u]++;
}
scanf("%d %d", &x , &y);
printf("Case #%d: ",cas++);
if(BFS()) printf("Yes\n");
else printf("No\n");
}
return 0;
}

Gym - 100548H The Problem to Make You Happy 2014-2015 ACM-ICPC, Asia Xian Regional Contest (BFS+博弈)的更多相关文章

  1. 2014-2015 ACM-ICPC, Asia Xian Regional Contest G The Problem to Slow Down You 回文树

    The Problem to Slow Down You Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjud ...

  2. Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP

    题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...

  3. (线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/ ...

  4. 2014-2015 ACM-ICPC, Asia Xian Regional Contest GThe Problem to Slow Down You

    http://blog.csdn.net/u013368721/article/details/42100363  回文树 建立两棵回文树,然后count处理一遍就可以了,然后顺着这两棵树的边走下去就 ...

  5. Gym 100548F Color 2014-2015 ACM-ICPC, Asia Xian Regional Contest (容斥原理+大数取模)

    题意:有N朵花,在M种颜色中选择恰好k种不同的颜色,将这N朵花染色,要求相邻的两朵花颜色不相同. 分析:若限制改为选择不超过k种颜色将N朵花朵染色,则方案数\(f(N,k) = k*(k-1)^{N- ...

  6. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  7. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

  8. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  9. Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖

    题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...

随机推荐

  1. Java 执行linux scp 远程获取文件和上传

      需要的jar包:ganymed-ssh2-build210.jar import java.io.ByteArrayOutputStream;import java.io.File;import ...

  2. The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files

    使用spring框架提供的JDBC模板操作数据库时,提示错误 解决方案:导入事务管理jar包spring-tx-4.2.4.RELEASE.jar

  3. 如何在 Linux 上永久挂载一个 Windows 共享

    导读 如果你已经厌倦了每次重启 Linux 就得重新挂载 Windows 共享,读读这个让共享永久挂载的简单方法. 在 Linux 上和一个 Windows 网络进行交互从来就不是件轻松的事情.想想多 ...

  4. 更改hadoop native库文件后datanode故障

    hadoop是用cloudra的官方yum源安装的,服务器是CentOS6.3 64位操作系统,自己写的mapreduce执行的时候hadoop会提示以下错误: WARN util.NativeCod ...

  5. 【BZOJ3681】Arietta 树链剖分+可持久化线段树优化建图+网络流

    [BZOJ3681]Arietta Description Arietta 的命运与她的妹妹不同,在她的妹妹已经走进学院的时候,她仍然留在山村中.但是她从未停止过和恋人 Velding 的书信往来.一 ...

  6. R语言中获取当前目录

    # 获取当前工作目录 getwd() # 设置工作目录 setwd()

  7. 解Bug之路-TCP粘包Bug

    解Bug之路-TCP粘包Bug - 无毁的湖光-Al的个人空间 - 开源中国 https://my.oschina.net/alchemystar/blog/880659 解Bug之路-TCP粘包Bu ...

  8. the age of the TCP connection TCP Slow Start

    w防止网络过载和拥塞 HTTP The Definitive Guide The performance of TCP data transfer also depends on the age of ...

  9. LeetCode_Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  10. c++ caffe 输出 activation map 、 层参数

    python输出activation map与层参数:https://blog.csdn.net/tina_ttl/article/details/51033660 caffe::Net文档: htt ...