HDU 1850 Being A good boy in spring Festival to be a good kid in Spring Festival (NIM game, micro-deformation)

Source: Internet
Author: User

Idea: If the total number of cards is different or the result of ans is 0, then must lose, output 0. Otherwise, you must give the other party a P-state, you can have all the poker heap to be checked, will ans^a[i] can be obtained in addition to a[i] Other poker number of different or results tmp, the purpose is to make TMP is 0, then certainly to take some cards from the a[i] heap, so that the remaining card number XOR or TMP is 0. What may happen (1) TMP is larger than a[i], then this is not the right solution. (2) Tmp=0, then take a[i] all away. (3) Tmp<a[i], then to take away a[i]-tmp card, leaving TMP Zhang, just different or the result is 0.

1#include <iostream>2#include <cstdio>3 using namespacestd;4 inta[101];5 intMain ()6 {7     //freopen ("Input.txt", "R", stdin);8     intN;9      while(cin>>n,n)Ten     { One          for(intI=0; i<n; i++) Ascanf"%d",&a[i]); -  -         intans=a[0], cnt=0; the          for(intI=1; i<n; i++) -ans^=A[i]; -  -         if(!ans) cout<<"0"<<endl;//must lose +         Else -         { +              for(intI=0; i<n; i++) A             { at                 inttmp=ans^A[i]; -                 if(a[i]-tmp>=0) -cnt++; -             } -cout<<cnt<<Endl; -         } in     } -     return 0; to}
AC Code

HDU 1850 Being A good boy in spring Festival to be a good kid in Spring Festival (NIM game, micro-deformation)

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.