懒得复制,戳我戳我

Solution:


说一点之前打错的地方:

  • 连边存的是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(拓扑排序+博弈论+哈希)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  4. CodeForces 1213F (强联通分量分解+拓扑排序)

    传送门 •题意 给你两个数组 p,q ,分别存放 1~n 的某个全排列: 让你根据这两个数组构造一个字符串 S,要求: (1)$\forall i \in [1,n-1],S_{pi}\leq S _ ...

  5. [Codeforces 919F]A Game With Numbers

    Description 题库链接 两个人 Van♂ 游戏,每人手上各有 \(8\) 张牌,牌上数字均为 \([0,4]\) 之间的数.每个人在自己的回合选自己手牌中数字不为 \(0\) 的一张与对方手 ...

  6. Codeforces 919F——A Game With Numbers

    转自大佬博客:https://www.cnblogs.com/NaVi-Awson/p/8405966.html; 题意 两个人 Van♂ 游戏,每人手上各有 8'>88 张牌,牌上数字均为 [ ...

  7. (CodeForces 510C) Fox And Names 拓扑排序

    题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...

  8. 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 ...

  9. hihoCoder1343 : Stable Members【BFS拓扑排序】

    题目链接:https://hihocoder.com/problemset/problem/1343 #1343 : Stable Members 时间限制:10000ms 单点时限:1000ms 内 ...

随机推荐

  1. ORACLE官网下载登陆账号能够使用

    username: responsecool@sina.com password: abc123ABC http://www.oracle.com/index.html

  2. 20155306 白皎 《网络攻防》 EXP7 网络欺诈技术防范

    20155306 白皎 <网络攻防> EXP7 网络欺诈技术防范 问题回答 (1)通常在什么场景下容易受到DNS spoof攻击 局域网内的攻击以及连接公众场所的共享wifi (2)在日常 ...

  3. WPF的DataTrigger绑定自身属性

    原文:WPF的DataTrigger绑定自身属性 <DataTrigger Binding="{Binding RelativeSource={RelativeSource self} ...

  4. mfc c++字符串类与 流输出

    一.命名空间 所谓命名空间(namespace),是指标识符的各种可见范围.C++标准程序库中的所有标识符都被定义于一个名为std的命名空间(namespace)中.而我们要使用的string类也是一 ...

  5. P4175 [CTSC2008]网络管理

    如果没有修改就是简单主席树,有了修改的话因为主席树维护的是到根的一段路径,所以修改操作会修改子树,也就是连续的一段dfn 所以显然树套树一波就没了 极其好写 #include<bits/stdc ...

  6. [THUSC2017]巧克力[斯坦纳树、随机化]

    题意 题目链接 分析 对于第一问,如果颜色数量比较少的话可以 \(\binom{cnt}{k}\) 枚举最终连通块中的 \(k\) 种颜色,然后利用斯坦纳树求解. 如果颜色比较多,考虑将所有的颜色重新 ...

  7. JQ_五星级评分特效

    代码如下:<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" conte ...

  8. Js_Eval方法

    定义和用法eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 语法eval(string) 其中参数string为必需.是要计算的字符串,其中含有要计算的 JavaScr ...

  9. ECS centos7 使用外部邮件服务商的465加密端口

    ECS centos7 使用外部邮件服务商的465加密端口发送邮件. 1.修改/etc/mail.rc 文件中添加以下的 set smtp="smtps://smtp.163.com:465 ...

  10. allegro 封装 (引脚编号修改)

    1. 打开dra文件在find里面 off all  然后只点击text 2.点击需要更改的焊盘 3.菜单栏edit - text 4.弹出窗口修改即可