【题解】 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 内 ...
随机推荐
- Alamofire请求网络
HTTP - GET和POST请求- 如果要传递大量数据,比如文件上传,只能用POST请求- GET的安全性比POST要差些,如果包含机密/敏感信息,建议用POST- 如果仅仅是索取数据(数据查询), ...
- Python3入门(四)——Python函数
一.概述 python和其他高级语言一样,支持函数 注意和scala不一样,结果必须使用return,否则默认return None!这和scala最后一个值作为返回是不一样的! 二.函数调用 和其他 ...
- WPF编程,窗体最大化、最小化、关闭按钮功能的禁用
原文:WPF编程,窗体最大化.最小化.关闭按钮功能的禁用 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...
- 基于代的垃圾回收机制--《CLR via C#》读书笔记
我们知道,垃圾回收在内存无限大的理想情况下是不需要的,正是因为内存存在的瓶颈,我们才需要垃圾回收.在<垃圾回收算法之引用计数算法>和<垃圾回收算法之引用跟踪算法>两篇文章中,我 ...
- 对JSON传递图片Base64编码的一点总结
项目中跟Java对接的时候需要传输图片,经过Base64编码后传输的. 但是实际调试的时候发现Java那边始终无法正常解析出图片. 冷静想想之后,发现问题在于使用OpenCV读取图片,编码的是Mat: ...
- P2463 [SDOI2008]Sandy的卡片
写一种\(O(nm)\)的做法,也就是\(O(\sum 串长)\)的. 先通过差分转化,把每个数变成这个数与上一个数的差,第一个数去掉,答案就是最长公共子串+1 按照套路把所有串拼起来,中间加一个分隔 ...
- Bluedroid协议栈HCI线程分析
蓝牙进程中有多个线程,其中HCI 线程是负责处理蓝牙主机端和控制器的数据处理和收发的工作. 本篇文章就是分析一下该线程的数据处理流程. 1.跟HCI相关的接口 首先看看hci的相关的接口:在hci_l ...
- mybatis 异常 too many connections 解决方案 mysql
参考: https://blog.csdn.net/u011628250/article/details/54017481 https://www.cnblogs.com/baby123/p/5710 ...
- stl源码剖析 详细学习笔记 RB_tree (1)
// // RB_tree_STL.cpp // 笔记 // // Created by fam on 15/3/21. // // #include "RB_tree_STL.h&q ...
- OD之修改文件标题(一)
OD是逆向工程中的一个重要工具,逆向工程调试说明具体请参考:百度百科,OD介绍,当然就我了解而言,俗话就是破解软件,市面上的什么破解版,精简版啥的基本都是通过这种技术的,但是这并不能一概而论说逆向工程 ...