【题解】 Codeforces 919F A Game With Numbers(拓扑排序+博弈论+哈希)
Solution:
- 我感觉我也说不太好,看Awson的题解吧。
说一点之前打错的地方:
- 连边存的是hash后的数组下标
if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==1){
if(f==0)printf("Alice\n");else printf("Bob\n");
continue;
}
if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==-1){
if(f==0)printf("Bob\n");else printf("Alice\n");
continue;
}
- 每个点存的是A状态与B状态,A操作的必胜还是必输态
- 然后就是一个要注意的点:我们是反向存边,由后状态推向先状态,如果后状态为必输态,那么先状态一定为必胜态,如果先状态的所有可以达到的后状态都为必胜态,那么这个先状态是必输态
- 这题思路比较明确,就是一些代码细节要注意吧,还有因为这题学会了\(Struct\)的骚操作
Code:
//It is coded by Ning_Mew on 3.27
#include<bits/stdc++.h>
using namespace std;
const int maxn=400000+10;
int n,f;
int S[maxn],C[maxn],ct=0;
int head[maxn],cnt=0,in[maxn],ans[maxn];
struct Edge{int nxt,to;}edge[(maxn<<6)+5];
void add(int from,int to){
in[to]++;
edge[++cnt].nxt=head[from];
edge[cnt].to=to;
head[from]=cnt;
}
//bool cmp(const int &xx,const int &yy){return xx<yy;}
struct hs{
int a[8];
hs(){memset(a,0,sizeof(a));}
hs(int x){for(int i=7;i>=0;i--){a[i]=x%5;x=x/5;}}
hs(int *_a){for(int i=7;i>=0;i--)a[i]=_a[i];}
void rd(){for(int i=0;i<=7;i++)scanf("%d",&a[i]);}
void st(){sort(a,a+8);}
int hash(){
int ans=0;
for(int i=0;i<=7;i++)ans=ans*5+a[i];
return ans;
}
};
void dfs(int pl,int last,int h){
if(pl==8){++ct;S[ct]=h;C[h]=ct;return;}
for(int i=last;i<=4;i++)dfs(pl+1,i,h*5+i);
}
int num(int x,int y){return (x-1)*ct+(y-1);}
void prework(){
dfs(0,0,0);
for(int i=1;i<=ct;i++){
for(int j=1;j<=ct;j++){
hs a(S[i]),b(S[j]);
for(int pi=0;pi<=7;pi++)if(a.a[pi]){
for(int pj=0;pj<=7;pj++)if(b.a[pj]){
hs c(a.a);
c.a[pi]=(a.a[pi]+b.a[pj])%5;
c.st();int tmp=C[c.hash()];
add( num( j,tmp ),num( i,j ) );
}
}
}
}
queue<int>Q;
while(!Q.empty())Q.pop();
//-1 lose 1 win 0 deal
for(int i=2;i<=ct;i++)ans[ num(i,1) ]=-1,Q.push( num(i,1) );
while(!Q.empty()){
int u=Q.front();Q.pop();
for(int i=head[u];i!=0;i=edge[i].nxt){
int v=edge[i].to;
if(ans[v]!=0)continue;
if(ans[u]==-1){ans[v]=1;Q.push(v);}
else{
in[v]--;
if(in[v]==0){ans[v]=-1;Q.push(v);}
}
}
}return;
}
int main(){
memset(ans,0,sizeof(ans));
prework();
scanf("%d",&n);
hs a,b;
for(int i=1;i<=n;i++){
scanf("%d",&f);
a.rd();b.rd();a.st();b.st();
if(f==1)swap(a,b);
if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==1){
if(f==0)printf("Alice\n");else printf("Bob\n");
continue;
}
if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==-1){
if(f==0)printf("Bob\n");else printf("Alice\n");
continue;
}
printf("Deal\n");
}
return 0;
}
【题解】 Codeforces 919F A Game With Numbers(拓扑排序+博弈论+哈希)的更多相关文章
- Codeforces 919F. A Game With Numbers(博弈论)
Imagine that Alice is playing a card game with her friend Bob. They both have exactly 88 cards and ...
- Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序
C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...
- 题解报告:hdu 2647 Reward(拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...
- CodeForces 1213F (强联通分量分解+拓扑排序)
传送门 •题意 给你两个数组 p,q ,分别存放 1~n 的某个全排列: 让你根据这两个数组构造一个字符串 S,要求: (1)$\forall i \in [1,n-1],S_{pi}\leq S _ ...
- [Codeforces 919F]A Game With Numbers
Description 题库链接 两个人 Van♂ 游戏,每人手上各有 \(8\) 张牌,牌上数字均为 \([0,4]\) 之间的数.每个人在自己的回合选自己手牌中数字不为 \(0\) 的一张与对方手 ...
- Codeforces 919F——A Game With Numbers
转自大佬博客:https://www.cnblogs.com/NaVi-Awson/p/8405966.html; 题意 两个人 Van♂ 游戏,每人手上各有 8'>88 张牌,牌上数字均为 [ ...
- (CodeForces 510C) Fox And Names 拓扑排序
题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...
- Educational Codeforces Round 25 E. Minimal Labels 拓扑排序+逆向建图
E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- hihoCoder1343 : Stable Members【BFS拓扑排序】
题目链接:https://hihocoder.com/problemset/problem/1343 #1343 : Stable Members 时间限制:10000ms 单点时限:1000ms 内 ...
随机推荐
- 20155210 Exp5 MSF基础应用
Exp5 MSF基础应用 一个主动攻击实践,MS08-067 首先利用msfconsole启用msf终端 然后利用search MS08-067搜索漏洞,会显示相应漏洞模块 如图: 根据上图,我们输入 ...
- 2017-2018 Exp3 MAL_免杀原理与实践 20155214
目录 Exp3 MAL_免杀原理与实践 实验内容 对msf生成后门程序的检测 Veil-Evasion应用 Visual Studio2017 + shellcode生成后门 主要思路 知识点 最后的 ...
- 《Flask Web开发实战:入门、进阶与原理解析(李辉著 )》PDF+源代码
一句话评价: 这可能是市面上(包括国外出版的)你能找到最好的讲Flask的书了 下载:链接: https://pan.baidu.com/s/1ioEfLc7Hc15jFpC-DmEYBA 提取码: ...
- 汇编-MOV指令
知识点: MOV指令 基址 内联汇编 把OD附加到资源管理器右键菜单 一.MOV指令 aaa=0x889977;//MOV DWORD PTR DS:[0x403018],0x8899 ...
- dxp altium pcb里面如果想让重叠的两个元件不报错怎么设置?
dxp的设置是Design Rules里面有个Placement选项,把第一个的钩去掉即可.
- 配置LNPM
在 Ubuntu 系统中,可以使用 apt-get 命令来搭建 LNMP环境.这种方式较编译方式安装更加简便,因此选择使用该方式来搭建环境以供学习. 安装Nginx 使用 sudo apt-get i ...
- Azure SQL Database Active Geo-Replication 简介
对于数据库的维护来说,备份工作可谓是重中之重.MS Azure 当然也提供了很完善的数据库备份功能.但是在动手创建备份计划前请思考一下备份工作的真实目的.当然首先要保证数据的安全,一般来说定时创建数据 ...
- yocto-sumo源码解析(二): oe-buildenv-internal
1 首先,脚本先对运行方式进行了检测: if ! $(return >/dev/null 2>&1) ; then echo 'oe-buildenv-internal: erro ...
- ats显示代理缓存
如果要将ats用作显示代理缓存,则必须配置客户端软件(即浏览器)以将请求直接发送到ats. 如果没有将ats配置为使用透明度选项(通过交换机或路由器在路由到源服务器的情况下拦截客户端请求并重新路由到a ...
- EOS开发基础之二:使用cleos命令行客户端操作EOS(钱包wallet基础操作)
不知道下边这一段英文你们是不是能看懂,如果看不懂那就算了,我就是转过来随便看看的. 总之你记住nodeos.cleos和keosd这三个工程十分重要就行了,回头咱们的研究都从这三个工程杀进去. EOS ...