Question
Refer to the blog: http://blog.csdn.net/akof1314/article/details/4447709
// 0 1-2 // 1 1-1 // 0 2-1 // 1 2-1 ///2 2-2 // 0 3-1 // 1 3 -1 // 2 3-1 // 3 3-2 // 0 4-1 // 1 4-1 // 2 4-1 // 3 4-1 // 4 4-2 // 0 5-1 // 1 5-1 // 2 5-1 // 3 5-1/* nheim game. For N-heap sugar, one case is that each heap is 1, so you will know who wins or who wins the heap number. If not all are 1, if these heaps are a strange situation, or they are non-singular situations, but non-singular situations can be converted to singular situations (for specific changes, refer to the previous article ). The classic nheim question is who gets the last one and who wins. This question is the last one. The second situation is analyzed below: 1. If the initial situation is a singular situation, the first attacker is the loser. 2. If the initial result is a non-singular situation, the winner is the winner. The number of non-singular and singular conversion times is relative. */# Include <stdio. h> # include <string. h> int main () {int t; scanf ("% d", & T); While (t --) {int N; int A [100]; scanf ("% d", & N); int sum = 0, K = 0; For (INT I = 0; I <n; I ++) {scanf ("% d", & A [I]); sum ^ = A [I]; // determines the singular situation like this? ^? If (A [I]! = 1) k = 1;} If (k = 0) {If (N % 2) printf ("Brother \ n "); else printf ("John \ n");} else {If (sum = 0) printf ("Brother \ n"); // you can determine a strange situation, 0 singular else printf ("John \ n"); // otherwise non-singular} return 0 ;}View code
HDU 1907 John (game)