懒得复制,戳我戳我

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. css样式显示省略号

     用css样式显示省略号,记 .xx{ display: block; width:200px;/*对宽度的定义,根据情况修改*/ overflow: hidden; white-space: n ...

  2. ASP.NET Core 3.0 实战:构建多版本 API 接口

    第一次在博客写分享,请多多捧场,如有歧义请多多包含! 因为业务需求发展需要,所以API接口的变更升级是必不可少的事情,而原有的接口是不可能马上停止使用的.例如:Login接口为例,1.0版本之返回用户 ...

  3. Huploadify V2.1+ SpringMVC上传文件的实现

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  4. 20155330 《网络攻防》 Exp4 恶意代码分析

    20155330 <网络攻防> Exp4 恶意代码分析 实验后回答问题 (1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操 ...

  5. python删除文件与目录的方法

    python内置方法删除目录(空目录与非空目录)及文件 1.os.remove(file_path):删除文件 #PPTV是文件夹,xen.txt是文件 >>> os.remove( ...

  6. MyBatis的一级缓存和二级缓存简介笔记

    关于mybatis中一级缓存和二级缓存的简单介绍 mybatis的一级缓存: MyBatis会在表示会话的SqlSession对象中建立一个简单的缓存,将每次查询到的结果结果缓存起来,当下次查询的时候 ...

  7. 初级字典树查找在 Emoji、关键字检索上的运用 Part-2

    系列索引 Unicode 与 Emoji 字典树 TrieTree 与性能测试 生产实践 在有了 Unicode 和 Emoji 的知识准备后,本文进入编码环节. 我们知道 Emoji 是 Unico ...

  8. nodejs 监控代码变动实现ftp上传

    被动模式下 //https://www.npmjs.com/package/watch //文件同步功能 var watch = require('watch'); var path = requir ...

  9. WebGL模型拾取——射线法二

    这篇文章是对射线法raycaster的补充,上一篇文章主要讲的是raycaster射线法拾取模型的原理,而这篇文章着重讲使用射线法要注意的地方.首先我们来看下图. 我来解释一下上图中的originTr ...

  10. LAXCUS大数据操作系统节点挂掉后的处理

    昨天回公司加班跑一个LAXCUS大数据应用,JVM直接挂了,没有留下任何异常信息,查看代码,也没有内存泄漏的问题.百思不得姐,只好去求教LAXCUS大数据操作系统的技术客服,客服查看了故障节点配置.日 ...