转自大佬博客:https://www.cnblogs.com/NaVi-Awson/p/8405966.html;

题意

两个人 Van♂ 游戏,每人手上各有 8'>88 张牌,牌上数字均为 [0,4]'>[0,4][0,4] 之间的数。每个人在自己的回合选自己手牌中数字不为 0'>00的一张与对方手牌中不为 0'>00 的一张。数字相加对 5'>55 取模,赋给自己当前选中的这张牌。 T'>TT 组询问,给出先手,问谁能胜。

分析

首先注意到卡牌顺序是没有影响的,我们可以按数字大小排序。这时由可重复的组合得每个人可能的方案只有 495(8+5−18)=495 种。所以两个人不同的状态共 4952=2450254952=245025 种。

我们可以将每个状态抽象成节点,节点存下两个状态,改轮的操作者的状态和对方的状态。用有向边链接操作前的和操作后的情况。对于每个节点我们考虑其连向的所有节点:

  1. 若存在一个连向的节点的状态能够保证当前的后手必败,那么改轮的操作者必胜;
  2. 若其连向的所有节点都是必胜,该节点必败;
  3. 其余的情况,则是平局

可以反向建边然后跑topsort

PS:我会说大佬这篇博客让我的编码状态姿势大幅度提高了吗~

  //It is made by Awson on 2018.2.2
#include <bits/stdc++.h>
#define LL long long
#define dob complex<double>
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
#define writeln(x) (write(x), putchar('\n'))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int N = ;
void read(int &x) {
char ch; bool flag = ;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || ); ch = getchar());
for (x = ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
x *= -*flag;
}
void print(int x) {if (x > ) print(x/); putchar(x%+); }
void write(int x) {if (x < ) putchar('-'); print(Abs(x)); } int S[N+], C[N+], cnt;
struct hs {
int a[];
hs() {memset(a, , sizeof(a)); }
hs(int x) {for (int i = ; i >= ; i--) a[i] = x%, x /= ; }
hs(int *_a) {for (int i = ; i < ; i++) a[i] = _a[i]; }
void rd() {for (int i = ; i < ; i++) read(a[i]); }
void st() {sort(a, a+); }
int hash() {
int ans = ;
for (int i = ; i < ; i++) ans = ans*+a[i];
return ans;
}
};
struct tt {int to, next; }edge[(N<<)+];
int path[N+], top, in[N+], ans[N+]; void add(int u, int v) {++in[v]; edge[++top].to = v, edge[top].next = path[u]; path[u] = top; }
int no(int a, int b) {return (a-)*cnt+b-; }
void dfs(int cen, int last, int h) {
if (cen == ) {S[++cnt] = h, C[h] = cnt; return; }
for (int i = last; i < ; i++) dfs(cen+, i, h*+i);
}
void prework() {
dfs(, , );
for (int i = ; i <= cnt; i++)
for (int j = ; j <= cnt; j++) {
hs a(S[i]), b(S[j]);
for (int p = ; p < ; p++) if (a.a[p])
for (int q = ; q < ; q++) if (b.a[q]) {
hs c(a.a);
c.a[p] = (a.a[p]+b.a[q])%;
c.st(); int tmp = C[c.hash()];
add(no(j, tmp), no(i, j));
}
}
queue<int>Q; while (!Q.empty()) Q.pop();
for (int i = ; i <= cnt; i++) ans[no(i, )] = , Q.push(no(i, ));
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (int i = path[u]; i; i = edge[i].next) if (!ans[edge[i].to]) {
if (ans[u] == ) {ans[edge[i].to] = -; Q.push(edge[i].to); }
else if (--in[edge[i].to] == ) {
Q.push(edge[i].to); ans[edge[i].to] = ;
}
}
}
}
void work() {
prework();
int t, f; hs a, b; read(t);
while (t--) {
read(f); a.rd(), b.rd(); a.st(); b.st();
if (f) swap(a, b);
int as = ans[no(C[a.hash()], C[b.hash()])];
if (as == ) puts("Deal");
else if (as == - && f || as == && !f) puts("Bob");
else puts("Alice");
}
}
int main() {
work();
return ;
}

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 919F]A Game With Numbers

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

  3. 【题解】 Codeforces 919F A Game With Numbers(拓扑排序+博弈论+哈希)

    懒得复制,戳我戳我 Solution: 我感觉我也说不太好,看Awson的题解吧. 说一点之前打错的地方: 连边存的是hash后的数组下标 if(ans[ num( C[a.hash()] , C[b ...

  4. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

  5. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  6. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  7. Educational Codeforces Round 8 D. Magic Numbers 数位DP

    D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...

  8. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  9. codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)

    In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 ...

随机推荐

  1. InpOut32 InputTest.cpp hacking

    /************************************************************************************ * InpOut32 Inp ...

  2. 关于public static void main(String[] args)相关知识

    main()方法是Java应用程序的入口方法,也就是说,程序在运行的时候,第一个执行的方法就是main()方法,这个方法和其他的方法有很大的不同.比如方法的名字必须是main,方法必须是public ...

  3. PS基础教程[4]如何载入笔刷

    笔刷是我们制作图片时的一个很好的工具,能够快速方便的帮助我们制作出很多现有的效果,所以我们都会制作很多的笔刷保存起来载入到PS中方便我们使用.本次系类经验的第四篇就来介绍一下笔刷的导入. 方法 1.笔 ...

  4. 微博6月底升级后 报 10017/2/statuses/share.json或者10014/2/statuses/share.json错误

    一,背景 2017-06-26微博公告替换了一些接口,导致以前的: statuses/repost 转发一条微博 statuses/update 发布一条微博 statuses/upload 上传图片 ...

  5. Python 函数 -slice()

    功能: slice() 函数实现切片对象,主要用在切片操作函数里的参数传递.返回一个切片对象. 语法: class slice(stop) class slice(start, stop[, step ...

  6. 自定义标签库_tag

    1)最简单的标签库 1,继承Tag接口,重写doEndTag()方法,返回类型不同后面流程不一样 想要jsp的内容必须重写了setPageContent()方法 再JspWriter out = pa ...

  7. bzoj 3612 [Heoi2014]平衡——整数划分(dp)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3612 因为力矩的缘故,变成了整数划分. 学习到了整数划分.就是那个图一样的套路.https: ...

  8. SQL Server数据库优化经验总结

    优化数据库的注意事项: 1.关键字段建立索引. 2.使用存储过程,它使SQL变得更加灵活和高效. 3.备份数据库和清除垃圾数据. 4.SQL语句语法的优化.(可以用Sybase的SQL Expert, ...

  9. 【转】使用JMeter 完成常用的压力测试(一)

    本文介绍了 JMeter 相关的基本概念.并以 JMeter 为例,介绍了使用它来完成最常用的三种类型服务器,即 Web服务器.数据库服务器和消息中间件,压力测试的方法.步骤以及注意事项. 讲到测试, ...

  10. 1041 Be Unique

    题意:找到一串数字序列中首个出现的不重复的数字. 思路:用哈希,因为数值大小在[1,10^4],所以可以直接开数组.输入数据时记录每个数字出现过的次数.然后遍历原序列,遇到第一个次数为1的数字就是所求 ...