Match Game
Question 1: Today there are several matches, and the two will pick them one by one. It is stipulated that only a few matches can be taken from the pile at a time,
A heap of data can be taken away, but it is not desirable. The final winner is the method to win.
If sum = 0, the first accessors will lose, and the latter wins;
If sum =! 0, the first accessors turn it into a singular state, the first accessors win
That is, who first faces a singular state and who loses;
Question 2: There are several matches today, and the two will pick them one by one. It is stipulated that only a few matches can be taken from the pile at a time,
A heap of data can be taken away, but it is not desirable. The final winner is negative.
There are two cases: 1. The number of matches in each heap is 1. If there is an odd number of heap matches, the first accessors will get the last match and then the result will be lost;
If the heap is an even number, it will be lost if it is obtained later.
2. The number of matches in each heap is not 1. If sum is set to 0, the attacker first loses the match, and the latter wins the match,
If sum =! 0. The winner wins, and the latter loses.
Conclusion: Whoever faces a singular state first loses, no matter what the situation is!
The Code is as follows:
#include<stdio.h>int main(){ int T,a[100],i,sum,m,ok; while(~scanf("%d",&T)) { while(T--) { sum=0; ok=0; scanf("%d",&m); for(i=1;i<=m;i++) { scanf("%d",&a[i]); if(a[i]>1) ok=1; sum=sum^a[i]; } if(ok==0) { if(m%2==0) printf("John\n"); else printf("Brother\n"); } else if(sum==0) printf("Brother\n"); else printf("John\n"); } } return 0;}