HDU 1907 John

Source: Internet
Author: User
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;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.