CF2203D.Divisibility Game
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob are playing a game. They have an array a of n elements and an array b of m elements.
The players take turns. Alice goes first. On their turn, each player chooses a number x from array a and a number y from array b. Alice has her own rule for choosing x and y, and Bob has his:
- Alice must choose x and y such that y is divisible by x.
- Bob must choose x and y such that y is not divisible by x.
After choosing x and y, y is removed from the array b (but x remains in a). When y is removed from b, if there are multiple occurrences of y, only one is removed. The player who cannot make a move loses.
Who will win if both players play optimally?
爱丽丝和鲍勃正在玩一个游戏。他们有一个包含 n 个元素的数组 a 和一个包含 m 个元素的数组 b。
两名玩家轮流进行操作,爱丽丝先手。在每一轮中,每位玩家需从数组 a 中选择一个数 x,并从数组 b 中选择一个数 y。爱丽丝和鲍勃各自遵循不同的选择规则:
- 爱丽丝必须选择满足 y 被 x 整除(即 x∣y)的 x 和 y;
- 鲍勃必须选择满足 y 不被 x 整除(即 x∤y)的 x 和 y。
选定 x 和 y 后,y 将从数组 b 中被移除(但 x 仍保留在 a 中)。当 y 从 b 中被移除时,若 y 在 b 中出现多次,则仅移除其中一个。无法进行合法操作的玩家判负。
若双方均以最优策略进行游戏,谁将获胜?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n,m≤106).
The second line of each test case contains n integers ai (1≤ai≤n+m) — the elements of the array a.
The last line of each test case contains m integers bi (1≤bi≤n+m) — the elements of the array b.
Additional constraints on the input:
- the sum of n over all test cases does not exceed 106;
- the sum of m over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m≤106)。
每个测试用例的第二行包含 n 个整数 ai(1≤ai≤n+m)——即数组 a 的元素。
每个测试用例的最后一行包含 m 个整数 bi(1≤bi≤n+m)——即数组 b 的元素。
输入的额外约束条件:
- 所有测试用例中 n 的总和不超过 106;
- 所有测试用例中 m 的总和不超过 106。
输出格式
For each test case, print one word:
- Alice if Alice wins;
- Bob if Bob wins.
对于每个测试用例,输出一个单词:
- 若 Alice 获胜,输出
Alice; - 若 Bob 获胜,输出
Bob。
输入输出样例
输入#1
3 9 3 3 2 4 2 2 4 4 2 4 6 7 12 10 3 3 2 5 4 2 5 3 4 4 4 10 7 13 1 5 1 1 2 3 4 5
输出#1
Alice Bob Alice
说明/提示
Consider the first test case. Let's show how Alice wins through the moves:
- Alice's move: x=3,y=6 (after this, 6 will be removed from b, resulting in b=[7,12])
- Bob's move: x=3,y=7 (Bob will choose y=7 on his turn anyway, since there is no x that does not divide y=12, after this move b=[12])
- Alice's move: x=4,y=12 (after this move, b becomes empty)
- Bob's move: Bob loses, as he cannot make a move
考虑第一个测试用例。下面展示爱丽丝(Alice)如何通过以下操作获胜:
- 爱丽丝的操作:x=3,y=6(此后,6 将从 b 中被移除,得到 b=[7,12])
- 鲍勃(Bob)的操作:x=3,y=7(鲍勃在本轮中必然选择 y=7,因为此时不存在能整除 y=12 的 x;此操作后 b=[12])
- 爱丽丝的操作:x=4,y=12(此操作后,b 变为空集)
- 鲍勃的操作:鲍勃失败,因为他无法进行任何操作
输入解题思路,AI测评打分。不知道怎么写?