zoukankan      html  css  js  c++  java
  • BestCoder Round #65 hdu5591(尼姆博弈)

    ZYB's Game

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 527    Accepted Submission(s): 430


    Problem Description
    ZYB played a game named NumberBomb with his classmates in hiking:a host keeps a number in [1,N] in mind,then 
    players guess a number in turns,the player who exactly guesses X loses,or the host will tell all the players that
    the number now is bigger or smaller than X.After that,the range players can guess will decrease.The range is [1,N] at first,each player should guess in the legal range.

    Now if only two players are play the game,and both of two players know the X,if two persons all use the best strategy,and the first player guesses first.You are asked to find the number of X that the second player
    will win when X is in [1,N].
     
    Input
    In the first line there is the number of testcases T.

    For each teatcase:

    the first line there is one number N.

    1T100000,1N10000000
     
    Output
    For each testcase,print the ans.
     
    Sample Input
    1
    3
     
    Sample Output
    1
     
    题意:两个人玩游戏,给出一个区间【1,n】和一个数x,每次两个人都必须从这个区间内挑出一个数,如果谁先挑到x则谁输,如果都没有挑到x则缩小数组范围(向靠近x处靠拢)
    题解:此题类似尼姆博弈,在两堆分别有若干个石子的堆里取石子(至少取一个,多着不限),每次只能从其中一堆中取,要想胜利只需要让对方在取石子时面临两堆石子相同的局面即可,1、当n是偶数时,无论我们选择那个数都不可能使两边的数的个数相等,所以后手必输,2、当n是奇数时,只有x等于中间的数是,两边的数的个数相等使得先手面临相等的局面,此时后手获胜,所以结果非1即0
     
    #include<stdio.h>
    #include<string.h>
    #include<string>
    #include<math.h>
    #include<algorithm>
    #define LL long long
    #define PI atan(1.0)*4
    #define DD double
    #define MAX 110
    #define mod 10007
    #define dian 1.000000011
    using namespace std;
    int main()
    {
        int t,n,m,i,j;
        scanf("%d",&t);
        while(t--)
        {
        	scanf("%d",&n);
        	if(n%2==0)
        		printf("0
    ");
        	else 
        	    printf("1
    ");
        }
    	return 0;
    } 
    

      

  • 相关阅读:
    JS和C# 里的闭包及闭包在事件中的使用
    ***项目开发记录
    七牛云存储之应用视频上传系统开心得
    二维码及二维码接合短URL的应用
    EF批量添加,删除,修改的扩展
    ngTemplateOutlet递归的问题
    每日新知2019-06-03
    Spring boot初始
    纯前端播放本地音乐
    macbook 安装任意来源
  • 原文地址:https://www.cnblogs.com/tonghao/p/5231533.html
Copyright © 2011-2022 走看看