"Bzoj" "3759" Hungergame Hunger Games

Source: Internet
Author: User
Tags cmath

Game theory/Gauss Elimination element

If you do not open the box this operation, then is a very naked nim game ...

But with the opening of the box this operation, it became the egg hurt t_t

First we can think of a direct approach: open all the boxes, of course, if at this time all A[i] xor and ==0 wins ...

But it's obvious that even the sample is not going to ╮(╯▽╰)╭.

Then we can think about, for a group of all the boxes that are not open, we do one operation, will be divided into two groups: open and not open (nonsense!). )

So sad ... Can't write it down ...

Forget Orz POPOQQQ, carry the following:

the state of winning the winner is: the given set of numbers exist an XOR and zero non-empty set, then the initiator win proof: First we have a state a: The current all open box of the number of stones in different or zero, And the number of stones in the closed box does not exist in the set of a different or zero non-empty-case set of a state when the initiator has two operations:1. Take some stones from an open box. So according to Nim's conclusion, The back can also take some stones to restore the state to a state 2. Open some boxes because there is not an XOR and zero non-empty set in the Open box, the number of stones in all open boxes will be different or zero. So the back can take some stones to restore the state to a state so when the initiator will be defeated then if there is no non-empty set of XOR and Zero, then the initial state satisfies the state A, the initiator will fail if there is an XOR and zero non-empty set, then the initiator must open all the XOR and zero subsets, So that the rest of the box does not exist in the non-empty set of XOR or zero, the state a left to the next, the initiator will win then is to determine whether there is no XOR or zero of the non-empty set of problems ... Decisive Gaussian elimination for linear radicals
View Code

My Code: (A subset of the first direct brute-force enumeration ...) )

1 /**************************************************************2 problem:37593 User:tunix4 language:c++5 result:accepted6 time:8280 Ms7 memory:1272 KB8 ****************************************************************/9  Ten //Bzoj 3759 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; at intGetint () { -     intv=0, sign=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } in Const intn=1e7+Ten, inf=~0u>>2; - Const Doubleeps=1e-8; to /*******************template********************/ +   - inta[ -]; the intMain () { * #ifndef Online_judge $Freopen ("Input.txt","R", stdin);Panax Notoginseng //freopen ("Output.txt", "w", stdout); - #endif the     intt=getint (); +      while(t--){ A         intn=getint (); the         BOOLans=0; +Rep (I,n) a[i]=getint (); -           $F (I,1,(1<<n)-1){ $             inttmp=0, tmp2=0; - Rep (j,n) -                 if(I & (1&LT;&LT;J)) tmp^=A[j]; the             if(tmp==0) {ans=1; Break; } -         }WuyiPuts (ans?)"Yes":"No"); the     } -     return 0; Wu}
View Code

Gaussian elimination:

1 /**************************************************************2 problem:37593 User:tunix4 language:c++5 result:accepted6 time:0 Ms7 memory:1272 KB8 ****************************************************************/9  Ten //Bzoj 3759 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; at intGetint () { -     intv=0, sign=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sign=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } in Const intn=1e7+Ten, inf=~0u>>2; - Const Doubleeps=1e-8; to /*******************template********************/ + inta[ -]; - BOOLGaussintN) { the Rep (i,n) { *F (j,i+1, N-1)if(a[j]>A[i]) swap (a[i],a[j]); $         if(!a[i])return 1;Panax NotoginsengD (J, -,0)if(A[i]>>j &1){ -Rep (X,n)if(X!=i && a[x]>>j&1) a[x]^=A[i]; the              Break; +         } A     } the     return 0; + } - intMain () { $ #ifndef Online_judge $Freopen ("Input.txt","R", stdin); - //freopen ("Output.txt", "w", stdout); - #endif the     intt=getint (); -      while(t--){Wuyi         intn=getint (); the         BOOLans=0; -Rep (I,n) a[i]=getint (); WuPuts (Gauss (n)?"Yes":"No"); -     } About     return 0; $}
View Code

The gap in time is too big!!! Seems to be the question of people more conscience, will not be Gaussian elimination of the children's shoes have been too ...

"Bzoj" "3759" Hungergame Hunger Games

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.