Bzoj 3105 New Nim Games

Source: Internet
Author: User

Note that the XOR of a non-empty set of a linear base is not 0.

Our goal is to eliminate such a linear base, is opposite how to take, Xor or and is 1.

From the big to the small sort of elimination is good

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 105using namespacestd;Long Longn,a[maxn],b[maxn],bit[ +],ans=0, sum=0;BOOLvis[ +];BOOLcmpLong LongXLong Longy) {    returnX>y;}intMain () {scanf ("%lld",&N);  for(Long LongI=1; i<=n;i++) {scanf ("%lld", &a[i]); sum+=a[i];} Sort (a+1, a+n+1, CMP);  for(Long LongI=1; i<=n;i++) b[i]=A[i];  for(Long LongI=1; i<=n;i++)         for(Long Longk= to; k>=0; k--)        {            if(! (a[i]& (1<<k)))Continue; if(!Vis[k]) {Vis[k]=true; ans+=b[i];bit[k]=a[i]; Break;} Elsea[i]^=Bit[k]; } printf ("%lld\n", sum-ans); return 0;}

Bzoj 3105 New Nim 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.