luogu#P9862. [CCC 2008 J5/S5] Nukit
[CCC 2008 J5/S5] Nukit
题目背景
注:J5 与 S5 仅数据范围有所不同,在此选取 S5 的数据范围及数据进行评测。
题目描述
Canada’s top two nuclear scientists, Patrick and Roland, have just completed the construction of the world’s first nuclear fission reactor. Now it is their job to sit and operate the reactor all day, every day. Naturally they got a little bored after doing this for a while and as a result, two things have happened. First, they can now control the individual reactions that happen inside the reactor. Second, to pass the time, they have invented a new game called Nukit.
At the beginning of Nukit, a number of particles are put in the reactor. The players take alternating turns, with Patrick always going first. When it is a player’s turn to move, they must select some of the remaining particles to form one of the possible reactions. Then those particles are destroyed. Eventually there will be so few particles that none of the reactions can be formed; at this point, the first person who is unable to form a reaction on their turn loses.
In our universe you can assume that there are only types of particles: A
, B
, C
, D
. Each reaction is a list of particles that can be destroyed on a single turn. The five reactions are:
AABDD
ABCD
CCD
BBB
AD
For example, the first reaction AABDD
says that it is allowable to destroy two A
, one B
, and two D
particles all at the same time on a turn.
It turns out that, no matter how many particles start off in the reactor, exactly one of Patrick or Roland has a perfect winning strategy. By player has a perfect winning strategy, we mean that no matter what the other player does, player can always win by carefully choosing reactions.
For example, if the reactor starts off with one A
, five B
, and three D
particles then Roland has the following perfect winning strategy: “if Patrick forms reaction BBB
initially, then form reaction AD
afterward; if Patrick forms reaction AD initially, then form reaction BBB
afterward.” (The strategy works because either way, on Patrick’s second turn, there are not enough particles left to form any reactions.)
Given the number of each type of particle initially in the reactor, can you figure out who has a perfect winning strategy?
输入格式
The first line of input contains , the number of test cases . Each test case consists of integers separated by spaces on a single line; they represent the initial number of A
, B
, C
and D
particles. You can assume that there are initially between and (inclusive) of each type of particle.
输出格式
For each test case, output the player who has a perfect winning strategy, either Roland
or Patrick
.
题目大意
Patrick 和 Roland 在玩一个游戏,它的规则如下:
初始时给你 个整数(每个整数的大小都不超过 ),依次表示:
- 当前
A
字符的个数; - 当前
B
字符的个数; - 当前
C
字符的个数; - 当前
D
字符的个数。
每次操作,可以选择下面 个操作方式进行操作:
AABDD
ABCD
CCD
BBB
AD
举个例子,当选择了 AABDD
时,就说明你想要删除 个 A
, 个 B
, 个 D
。其他的同理。
但是请注意,如果当前某个字符数量小于你所要删除的那个字符的数量,你便不能执行该操作。
如果每个操作都无法执行的话,便视为输掉此游戏。
现在他们想要玩 轮游戏 ,每轮游戏 Patrick 先手,Roland 后手。假设两人都足够聪明。如果 Patrick 赢了,输出 Patrick
,否则输出 Roland
。
6
0 2 0 2
1 3 1 3
1 5 0 3
3 3 3 3
8 8 6 7
8 8 8 8
Roland
Patrick
Roland
Roland
Roland
Patrick
提示
Partial Explanation for Sample Output:
The first output occurs since Patrick loses immediately, since he cannot form any reaction. (Roland’s perfect winning strategy is “do nothing.”)
The second output occurs since Patrick has the perfect winning strategy “form reaction ABCD,” which makes Roland lose on his first turn.
The third output is explained in the problem statement.