Otherwise, if s is an odd number, the first hand wins.If there is no 1 in the first place, it is proved that when the total number of steps is an odd number, the first hand wins, N points. On the contrary, if it is an even number, it is a pvertex. (In this case
To win the next game, you only need to ensure that the number of any pile of stones is no less than 2 until there is only one pile at the end, because 1 is a special one)
In addition, it is proved that an odd number of 1 and s is not 2, it is a winning state. Starting from a 1, suppose there is a 1 and s. If s is an odd number, it can be merged first.
Two piles of stones; if s is an even number, the first hand can take 1; so in this case, the first hand must win, because move 1 can choose to drop one or two steps.
Now there are two cases of 1 and s. If one of them consumes 1 and merges with s, the remaining State is (1, s + 1) N points; remove 1,
The remaining (1, s) is also N points. merge two 1, (2, s) => (s + 3) States. If s is an odd number, that is, P-state. The first hand is the winner, and vice versa.
This is a defeat. This situation is summarized into the third article in the conclusion. In the case of three values, one value can be changed to another value.
However, when s = 2 or s = 0, it is a special case, because after 2 is removed, it becomes 1, and when s is 0, it is all 1. Through the above rule, we already know
1 is special. Now there is an NP Graph
It is not hard to find that if c is a multiple of 3, it must be a first-hand defeat.
#include
#include
#include using namespace std;bool judge (int c, int s) { if (c&1 && s > 2) return true; if (s == 0 || s == 2) return c % 3; return s&1;}int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { int n, s = 0, c = 0, x; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); if (x == 1) c++; else { if (s == 0) s = x; else s += x + 1; } } printf("Case #%d: %s\n", kcas, judge(c, s) ? "Alice" : "Bob"); } return 0;}