【题解】 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 内 ...
随机推荐
- windows linux hosts文件的配置,开发项目中域名跳转等。
我们通常都知道Windows中hosts文件(C:\Windows\System32\drivers\etc),用来映射域名的.linux上当然也有,一般在/etc/hosts下. 当工作的项目,在开 ...
- centos安装redis并设置开机启动
1.通过yum安装: yum install redis 2.设置redis.conf中daemonize为yes.设置密码: requirepass 3.安装完后的启动脚本是完善的,/etc/ini ...
- 汇编 push ,pop指令
知识点: PUSH POP CALL堆栈平衡 RETN指令 一.PUSH入栈指令 (压栈指令): 格式: PUSH 操作数 //sub esp,4 ;mov [esp],EBP 操作数 ...
- ssh无法登录,提示Connection closing...Socket close.
一.问题无法ssh直接连接到服务器 [C:\~]$ ssh 192.168.7.77 Connecting to ... Connection established. To escape to lo ...
- spring 配置 线程池并使用 springtest 进行测试
在 applicationContext.xml 中配置spring线程池: <!-- 包路径扫描 --> <context:component-scan base-package= ...
- Spring Boot(十二):Spring Boot 如何测试打包部署
有很多网友会时不时的问我, Spring Boot 项目如何测试,如何部署,在生产中有什么好的部署方案吗?这篇文章就来介绍一下 Spring Boot 如何开发.调试.打包到最后的投产上线. 开发阶段 ...
- UWP简单示例(一):快速合成音乐MV
说明 本文发布时间较早,内容可能已过时.最新动态请关注 TypeScript 版本.(2019 年 3 月 注) 在线演示: 音频可视化(TypeScript) 准备 IDE:Visual Studi ...
- Scrapy的日志等级和请求传参
日志等级 日志信息: 使用命令:scrapy crawl 爬虫文件 运行程序时,在终端输出的就是日志信息: 日志信息的种类: ERROR:一般错误: WARNING:警告: INFO:一般的信息: ...
- LintCode——筛子求和
描述:扔n个骰子,向上面的数字之和为 S .给定 Given n,请列出所有可能的 S 值及其相应的概率. 样例:给定n=1,返回 [ [1, 0.17], [2, 0.17], [3, 0.17], ...
- 访问kubernetes ingress-controller
ingress-controller可以理解为一套反向代理系统,本身需要暴露端口到集群外部,以便客户端访问. 根据实际使用,给出两种暴露端口的方式,如下: 方案一 拓扑 说明 ingress-cont ...