首页 技术 正文
技术 2022年11月17日
0 收藏 704 点赞 3,665 浏览 2533 个字

Description

题库链接

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

\(1\leq T\leq 100000\)

Solution

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

我们可以将每个状态抽象成节点,节点存下两个状态,改轮的操作者的状态和对方的状态。用有向边链接操作前的和操作后的情况。我们可以用 \(O\left(8^2\cdot\binom{8+5-1}{8}^2\right)\) 来枚举所有状态建边。对于每个节点我们考虑其连向的所有节点:

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

我们可以通过反向建边 \(topsort\) 来实现。 \(O(1)\) 回答询问。

Code

//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 = 400000;
void read(int &x) {
char ch; bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
x *= 1-2*flag;
}
void print(int x) {if (x > 9) print(x/10); putchar(x%10+48); }
void write(int x) {if (x < 0) putchar('-'); print(Abs(x)); }int S[N+5], C[N+5], cnt;
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 /= 5; }
hs(int *_a) {for (int i = 0; i < 8; i++) a[i] = _a[i]; }
void rd() {for (int i = 0; i < 8; i++) read(a[i]); }
void st() {sort(a, a+8); }
int hash() {
int ans = 0;
for (int i = 0; i < 8; i++) ans = ans*5+a[i];
return ans;
}
};
struct tt {int to, next; }edge[(N<<6)+5];
int path[N+5], top, in[N+5], ans[N+5];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-1)*cnt+b-1; }
void dfs(int cen, int last, int h) {
if (cen == 8) {S[++cnt] = h, C[h] = cnt; return; }
for (int i = last; i < 5; i++) dfs(cen+1, i, h*5+i);
}
void prework() {
dfs(0, 0, 0);
for (int i = 1; i <= cnt; i++)
for (int j = 1; j <= cnt; j++) {
hs a(S[i]), b(S[j]);
for (int p = 0; p < 8; p++) if (a.a[p])
for (int q = 0; q < 8; q++) if (b.a[q]) {
hs c(a.a);
c.a[p] = (a.a[p]+b.a[q])%5;
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 = 2; i <= cnt; i++) ans[no(i, 1)] = 1, Q.push(no(i, 1));
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] == 1) {ans[edge[i].to] = -1; Q.push(edge[i].to); }
else if (--in[edge[i].to] == 0) {
Q.push(edge[i].to); ans[edge[i].to] = 1;
}
}
}
}
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 == 0) puts("Deal");
else if (as == -1 && f || as == 1 && !f) puts("Bob");
else puts("Alice");
}
}
int main() {
work();
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898