zoukankan      html  css  js  c++  java
  • Hdoj 2509 Be the Winner

    Diciption
    Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time. 
    For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is 
    the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win). 

    Input

    You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases. 
    Output

    If a winning strategies can be found, print a single line with "Yes", otherwise print "No". 
    Sample Input

    2
    2 2
    1
    3

    Sample Output

    No
    Yes


    anti_nim游戏。
    这种Nim是不能操作者赢。
    Sg函数的话还是和普通的Nim一样,初始化是sg[0]=0;
    最后游戏的和的话,先手必胜当且仅当:
    1.每一堆石子都是1并且Nim和为0.
    2.有至少一堆石子>1并且Nim和不为0.

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int sg[105],n,m;
    int now,v[1005];
    
    inline void init(){
    	sg[0]=0;
    	for(int i=1;i<=100;i++){
    		now=0;
    		for(int j=0;j<i;j++)
    		    for(int k=j;k+j<i;k++) v[sg[j]^sg[k]]=i;
    		while(v[now]==i) now++;
    		
    		sg[i]=now;
    	}
    }
    
    int main(){
    	init();
    	
    	while(scanf("%d",&n)==1){
    		bool flag=0;
    		int a,ans=0;
    		
    		while(n--){
    			scanf("%d",&a);
    			ans^=sg[a];
    			if(a>1) flag=1;
    		}
    		
    		if((!flag&&!ans)||(flag&&ans)) puts("Yes");
    		else puts("No");
    	}
    	
    	return 0;
    }
    

      

     
  • 相关阅读:
    常见HTTP状态(304,)
    面试错题集
    从零构建以太坊(Ethereum)智能合约到项目实战——学习笔记1
    windows 以太坊开发框架Truffle环境搭建
    Ollydbg使用问题汇总
    网络攻防实战技术之——缓冲区溢出篇
    如何批量删除.svn文件
    树莓派安装nextcloud、Seafile
    汇编语言从入门到精通-5微机CPU的指令系统2
    kali安装vm tools正确操作
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8508930.html
Copyright © 2011-2022 走看看