Question Description: A and B take chess pieces from the two sets of chess pieces in turn to meet the following requirements: or take any number of (at least one) chess pieces from the pile, or retrieve the same number (at least one) of pawns from the two stacks, finish the two stacks and win the last one. Q: under what circumstances does a (first accessors) have a winning strategy? The input format is only one line. two integers separated by spaces are included to indicate the number of two heap pawns (each Heap has at least one and at most 10000 pawns ). The output format is only one line and contains one character. If the first accessor has a winning strategy, "Y" is output (excluding quotation marks); otherwise, "N" is output (excluding quotation marks ). [Example input 1] 1 [Example input 2] 5 3 [sample output 1] Y [sample output 2] n
Start with a simple situation.
Set n to the number of larger pieces, and m to the number of smaller pieces.
When n = 1, m = 2, it is easy to conclude that at this time it will be defeated.
Similarly, when (n, m) = (3, 5), (4, 7. The rest of the cases will win (because the opponent will be defeated by one step conversion ).
By betty's theorem,
The necessary conditions for defeat are:
Accode:
# Include <cstdio> # include <cmath> int main () {freopen ("Chess. in "," r ", stdin); freopen (" Chess. out "," W ", stdout); int n, m; scanf (" % d ", & N, & M); If (M> N) {int TMP = N; n = m; M = TMP;} printf ("% s \ n", INT (double (n-m) * (SQRT (5.l) + 1 .) /2 .) -M? "Y": "N"); Return 0 ;}