Bzoj 1022 SHOI2008 Little John's game John game theory

Source: Internet
Author: User

The main topic: Anti-Nim game, that is, take the last one to lose

First State 1: Assuming that all of the heap is 1, then the heap number for even win, otherwise the initiator will be defeated

Then state 2: Assuming that there are two heaps of the same number and not 1, then the FLAC has the ability to control the field, namely:

If the initiator takes a pile, then he can choose to leave a pile of 1 or all to take, so that the two piles are finally only 1 or 0;

If the initiator will be a bunch of left one, then the hand can choose to have a bunch of left a starters hands or all take away, so that the two piles finally only 1 or 0 left;

If the initiator takes a bunch away. Then he can have a bunch of the same take-off part, and then ibid

Status 3: If Xor!=0 so that the first can take a part of xor=0 and then the same state 2 to win or the initiator will be defeated

※ In view of my excessive sand tea, the above content only has the reference value. Not be able to prove correctness, please correct me

So if all the heap is 1 xor==0 initiator win or the other will win

If there is a heap is not 1 xor==0 to win otherwise the initiator win

#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 Little 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.