BZOJ1299: [LLH Invitational Tournament] Chocolate bars (Nim game), bzoj1299llh

Source: Internet
Author: User

BZOJ1299: [LLH Invitational Tournament] Chocolate bars (Nim game), bzoj1299llh

Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 552 Solved: 331
[Submit] [Status] [Discuss] Description

TBL and X play games with chocolate bars. Each time a person can take several chocolate bars out of the box, or eat one of the chocolate bars to a positive integer length. TBL takes two hands in turn and cannot be operated. They performed a total of 10 rounds (one box at a time) with the best strategy ). Can you predict the outcome?

Input

There are 20 rows of input data. Line 2i-1 is a positive integer Ni, indicating the number of I-round chocolate bars. Line 2i contains the Ni positive integer Li, j, indicating the length of the I-round chocolate bar.

Output

10 rows of output data. Each row outputs "YES" or "NO", indicating whether TBL will win. If it wins, "NO" is output; otherwise, "YES" is output"

Sample Input3
11 10 15
5
13 6 7 15 3
2
15 12
3
9 7 4
2
15 12
4
15 12 11 15
3
2 14 15
3
3 16 6
4
1 4 10 3
5
8 7 7 5 12
Sample OutputYES
NO
YES
YES
YES
NO
YES
YES
YES
NO
HINT

 

Score of 20%, N <= 5, L <= 100.

Score of 40%, N <= 7. The score of 50%, L <= 5,000.

Scores of 100%, N <= 14, L <= 1,000,000,000.

 

Source

 

This question is really stupid to 2333 by myself.

This question is actually a variant of the Nim game.

There are two first-hand operations

1. Regular Nim game operations

2. Add another pile of stones to the game.

Then, the best strategy of the first hand must be to leave the second hand with a heap of xor and 0, and no matter how much stone xor is added, it is not 0.

In this case, you just need to extract the most xor and 0 stones.

However! Funny thing!

I have been struggling with how to find this thing, and I am blind to regard L in the data range as N. I have been thinking about how to implement 0/1 trie, after reading the blog of hzwer, I found that this TM is a silly question...

 

#include<cstdio>#include<queue>#include<cstring>#define int long long using namespace std;const int MAXN=1e6+10,INF=1e9+10;inline char nc(){    static char buf[MAXN],*p1=buf,*p2=buf;    return p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXN,stdin),p1==p2)?EOF:*p1++;}inline int read(){    char c=nc();int x=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=nc();}    while(c>='0'&&c<='9'){x=x*10+c-'0';c=nc();}    return x*f;}int a[MAXN],flag=0,ans=0;int N;void dfs(int now,int X){    if(now==N+1)    {        if(X==0&&flag==1) ans=1;         return ;    }    dfs(now+1,X);    flag=1;    dfs(now+1,X^a[now]);}main(){    #ifdef WIN32     freopen("a.in","r",stdin);    #else    #endif    int QWQ=10;    while(QWQ--)    {        N=read(),ans=0,flag=0;        for(int i=1;i<=N;i++)            a[i]=read();        dfs(1,0);        if(ans) printf("NO\n");        else     printf("YES\n");    }    return 0;}

 

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.