Bzoj 1022 shoi2008 John's game John Game Theory

Source: Internet
Author: User

Anti-nim game, that is, take the last person to lose

First State 1: If all the heap is 1, the number of heap is equal to that of the first hand. Otherwise, the first hand is defeated.

Then state 2: If the number of two heaps is the same but not 1, the latter has the field control capability, that is:

If the first hand takes a heap, the latter hand can choose to leave one or all of the other stacks, so that only one or 0 of the two stacks are left;

If one heap is left by the first hand, the latter can choose to leave another heap for the first hand to take or all, so that only one or zero heap is left;

If the first hand takes a part of the heap, the later hand can take the same part of the heap, and then

Status 3: If XOR! If it is set to 0, you can take a portion of the first hand and set XOR to 0. Then, in the same status, the first hand wins. Otherwise, the first hand loses.

※In view of the fact that I am too fond of tea, the above content only has reference value and cannot prove its correctness. please correct me.

So if all the heap is 1 XOR = 0, the first hand will win, or the second hand will win.

If a heap is not 1 XOR = 0, the first hand wins. Otherwise, the first hand wins.

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int n;bool Calculate(){int i,x,xor_sum=0;bool flag=1;cin>>n;for(i=1;i<=n;i++){scanf("%d",&x);if(x^1) flag=0;xor_sum^=x;}if(flag)return !xor_sum;elsereturn xor_sum;}int main(){int T,i;for(cin>>T;T;T--){if( Calculate() )puts("John");elseputs("Brother");}}


Bzoj 1022 shoi2008 John's game John Game Theory

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.