Bzoj 1299 [LLH Invitational] chocolate bar game (nim game) + construction

Source: Internet
Author: User

Test Instructions:Link Method:Game + Construction parsing:God did not think of what to do, after reading the words of WYF uncle to understand the problem of the test instructions is n heap of stones, after you each operation there are two ways the first is the NIM game has been established on the Nim game. The second option is to select several heaps in the unchecked heap to join the Nim game. So how does this work? I've been trying to build a losing state, but maybe I've gone too far to think about turning this problem into a NIM game and finally going into a dead end. However, this problem must be defeated in this way: if it is the initiator, I can create an XOR and 0 of the Nim game, at this time the latter has two methods, the first is in the Nim game, then the initiator can be the game of the XOR and into 0, the second is to choose a new stone heap to join the original NIM game, If it is the initiator, it will not give the opportunity to add a set of different or 0 stone heap. So the initiator must be set to select the most elements of the XOR and 0 of the Nim game, at this time, in the remaining heap, must not have a set of stone heap of the XOR and 0, which is obvious. So if the latter chooses the second approach, then it will make the original NIM game XOR and is not 0, so the initiator can also be the game's XOR and changed to 0. That is, if the initiator starts selecting the most gravel heap to create an XOR and 0 Nim game, the latter will fail. can also be converted, if the initiator can choose an arbitrary number of stones to build an XOR and 0 of the Nim game, the latter will be defeated. It's obvious. The radius of the stone heap is 14, so we can < Span class= "Mrow" id= "mathjax-span-59" > 2 14 Direct Dfs gan. or Gaussian elimination. But apparently the former is 2333. Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define Nusing namespace STD;intNintA[n];BOOLV[n];intFlagvoidDfsintNO) {if(no==n+1)    {intans=0, cnt=0; for(intI=1; i<=n;i++)if(V[i]) ans^=a[i],cnt++;if(!ans&&cnt!=0) {flag=1; }return; } v[no]=1;d FS (no+1); v[no]=0;d FS (no+1);}intMain () {inttot=Ten; while(tot--) {scanf("%d", &n); for(intI=1; i<=n;i++)scanf("%d", &a[i]);memset(V,0,sizeof(v)); flag=0; Dfs1);if(flag)puts("NO");Else puts("YES"); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 1299 [LLH Invitational] chocolate bar game (nim game) + construction

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.