转自大佬博客: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:我会说大佬这篇博客让我的编码状态姿势大幅度提高了吗~

  1. //It is made by Awson on 2018.2.2
  2. #include <bits/stdc++.h>
  3. #define LL long long
  4. #define dob complex<double>
  5. #define Abs(a) ((a) < 0 ? (-(a)) : (a))
  6. #define Max(a, b) ((a) > (b) ? (a) : (b))
  7. #define Min(a, b) ((a) < (b) ? (a) : (b))
  8. #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
  9. #define writeln(x) (write(x), putchar('\n'))
  10. #define lowbit(x) ((x)&(-(x)))
  11. using namespace std;
  12. const int N = ;
  13. void read(int &x) {
  14. char ch; bool flag = ;
  15. for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || ); ch = getchar());
  16. for (x = ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar());
  17. x *= -*flag;
  18. }
  19. void print(int x) {if (x > ) print(x/); putchar(x%+); }
  20. void write(int x) {if (x < ) putchar('-'); print(Abs(x)); }
  21.  
  22. int S[N+], C[N+], cnt;
  23. struct hs {
  24. int a[];
  25. hs() {memset(a, , sizeof(a)); }
  26. hs(int x) {for (int i = ; i >= ; i--) a[i] = x%, x /= ; }
  27. hs(int *_a) {for (int i = ; i < ; i++) a[i] = _a[i]; }
  28. void rd() {for (int i = ; i < ; i++) read(a[i]); }
  29. void st() {sort(a, a+); }
  30. int hash() {
  31. int ans = ;
  32. for (int i = ; i < ; i++) ans = ans*+a[i];
  33. return ans;
  34. }
  35. };
  36. struct tt {int to, next; }edge[(N<<)+];
  37. int path[N+], top, in[N+], ans[N+];
  38.  
  39. void add(int u, int v) {++in[v]; edge[++top].to = v, edge[top].next = path[u]; path[u] = top; }
  40. int no(int a, int b) {return (a-)*cnt+b-; }
  41. void dfs(int cen, int last, int h) {
  42. if (cen == ) {S[++cnt] = h, C[h] = cnt; return; }
  43. for (int i = last; i < ; i++) dfs(cen+, i, h*+i);
  44. }
  45. void prework() {
  46. dfs(, , );
  47. for (int i = ; i <= cnt; i++)
  48. for (int j = ; j <= cnt; j++) {
  49. hs a(S[i]), b(S[j]);
  50. for (int p = ; p < ; p++) if (a.a[p])
  51. for (int q = ; q < ; q++) if (b.a[q]) {
  52. hs c(a.a);
  53. c.a[p] = (a.a[p]+b.a[q])%;
  54. c.st(); int tmp = C[c.hash()];
  55. add(no(j, tmp), no(i, j));
  56. }
  57. }
  58. queue<int>Q; while (!Q.empty()) Q.pop();
  59. for (int i = ; i <= cnt; i++) ans[no(i, )] = , Q.push(no(i, ));
  60. while (!Q.empty()) {
  61. int u = Q.front(); Q.pop();
  62. for (int i = path[u]; i; i = edge[i].next) if (!ans[edge[i].to]) {
  63. if (ans[u] == ) {ans[edge[i].to] = -; Q.push(edge[i].to); }
  64. else if (--in[edge[i].to] == ) {
  65. Q.push(edge[i].to); ans[edge[i].to] = ;
  66. }
  67. }
  68. }
  69. }
  70. void work() {
  71. prework();
  72. int t, f; hs a, b; read(t);
  73. while (t--) {
  74. read(f); a.rd(), b.rd(); a.st(); b.st();
  75. if (f) swap(a, b);
  76. int as = ans[no(C[a.hash()], C[b.hash()])];
  77. if (as == ) puts("Deal");
  78. else if (as == - && f || as == && !f) puts("Bob");
  79. else puts("Alice");
  80. }
  81. }
  82. int main() {
  83. work();
  84. return ;
  85. }

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. Metasploit的基本使用

    Metasploit可以在Linux.Windows和Mac OS X系统上运行.我假设你已安装了Metasploit,或者你使用的系统是Kali Linux.它有命令行接口也有GUI接口. 我使用的 ...

  2. 剑指offer—第三章高质量代码(合并两个排序链表)

    题目:输入员两个递增排序的链表,合并这两个链表并使新的链表中的结点仍然是按照递增排序的. 思路:首先,定义两个头节点分别为Head1和Head2的链表,然后比较第一个节点的值,如果是Head1-> ...

  3. noip积木大赛

    先要覆盖一号位置的高度,(现在你的目的只是想要覆盖一号位置). 每次你可以选区间[l,r]高度+1,这个作为一个操作. 为什么不选的范围大一点,让更多的区间增加高度呢. 所以红色的地方是,在我的目的是 ...

  4. [WPF]控件应用多个样式(转)

    最近在做WPF项目,公司没有专门的UI工程师,什么都要自己做.接触WPF已经有好几年了,自定义样式什么的也可以做一些.WPF在使用样式的时候一般都是 Style="{StaticResour ...

  5. 限制UITextfield的输入字符为50个字符

    1.实现UITextfieldDelegate 2.在UITextfield的代理方法中判断添加字符还是删除字符,从而做不同的操作 #pragma mark-UITextfield的代理方法 - (B ...

  6. 一周学会HTML----Day03常用标签(下)

    form 标签 表单(重要) 表单用途 用于收集用户信息,提交给服务器 基本使用 (action,method,enctype) 要提交的表单必须放到form里 input select textar ...

  7. 野村综合社,惠普2面,索尼,CDK面试经理

    今天疯了一口气面试了四个企业,自我介绍都说了七八遍,晚上回家到头就睡.中间接了oracle的电话,也不知道如何. 11:00野村面试 野村综合社北京流通部 面试3个人,一个英语部门负责人,一个日语负责 ...

  8. CF 1088(A , B , C , D)——思路

    http://codeforces.com/contest/1088 A:Ehab and another construction problem 输出 2 和 n(偶数的话)或者 2 和 n-1( ...

  9. (转)Android代码混淆-添加了Gson遇到的问题

    折腾了好久.....郁闷 -_- 1.首先,project.properties里的配置文件变了,之前的项目一直都是在project.properties这个文件中添加一行proguard.confi ...

  10. js对字符串进行编码方法总结

    在用javascript对URL字符串进行编码中,虽然escape().encodeURI().encodeURIComponent()三种方法都能对一些影响URL完整性的特殊字符进行过滤.但后两者是 ...