BZOJ3105: [cqoi2013] New NIM game

Source: Internet
Author: User

Exercises

Linear base? Similar to the base on a vector.

Here's the problem: http://blog.csdn.net/wyfcyx_forever/article/details/39477673

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 100+5 - #defineMAXM 100000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { -     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intN,A[MAXN],B[MAXN]; - ll Sum,ans; the intMain () * { $Freopen ("Input.txt","R", stdin);Panax NotoginsengFreopen ("output.txt","W", stdout); -n=read (); theFor1 (I,n) A[i]=read (), sum+=(LL) a[i]; +Sort (A +1, a+n+1); AFor3 (I,n,1) the     { +         intt=A[i]; -For3 (J, -,0) $          if(a[i]>>j&1) $           { -               if(B[j]) a[i]^=B[j]; -               Else{B[j]=a[i]; Break;} the           } -         if(A[i]) ans+=(ll) t;Wuyi     } thecout<<sum-ans<<Endl; -     return 0; Wu}
View Code

The method of dynamically maintaining a linear base is Orz.

3105: [cqoi2013] New Nim game time limit:10 Sec Memory limit:128 MB
submit:396 solved:239
[Submit] [Status] Description The traditional NIM game is this: there are some match stacks, each with several matches (the number of matches in different heaps can be different). Two players take turns, each time you can choose a match heap to remove several matches. You can take one or the whole bunch of matches, but not from more than a dozen matches at the same time. The player who took the last match won. The game is slightly different: in the first round, the first player can take a number of matches directly from the whole pile. Can not take a bunch of, but can not take all. The second round is also the same, the second player also has such an opportunity. Starting with the third turn (and the first player), the rules are the same as the Nim game. If you take it first, how can you guarantee to win? If you can win, let the first round match the total number of matches as small as possible. Input first behavior integer k。 That is, the number of match stacks. The second line contains kA positive integer not exceeding 109, that is, the number of matches in each heap. Output outputs the minimum number of matches taken in the first round. If there is no guarantee to win, output-1. Sample Input6
5 5 6 6 5 5
Sample Output +HINT

k<=100

BZOJ3105: [cqoi2013] New NIM game

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.