• hdu 5591 ZYB's Game


    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5591

    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

        博弈:当n=1时肯定第二个人赢。当n>=2时,x=1或x=n是肯定第一个人赢。对与其它情况,如果能取的数关于x对称,那么必定第二个人赢,因为不管第一个人取什么数,第二个人都取它对称的数,最后不定第一个人取x。所以当n为偶数时,不管x在什么位置,都是第一个人赢,因为开始所有数不关于x对称,第一人取数后就能让剩下的数关于x对称。当x为奇数时,x只有在中间位置才能第二个人赢,其它位置和偶数情款一样的。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int main(){
     6     int t,n;
     7     scanf("%d",&t);
     8     while (t--){
     9         scanf("%d",&n);
    10         if (n%2==1) printf("1
    ");
    11         else printf("0
    ");
    12     }
    13 }
  • 相关阅读:
    设计模式之六大设计原则学习笔记
    java多线程学习笔记
    mac上安装mongodb数据库教程
    在mac下使用终端命令通过ssh协议连接远程linux系统,代替windows的putty
    从request对象中获取请求json格式的参数
    @Conditional注释
    lambda 根据实体类的拼音排序
    PHP一行代码获取时间戳
    PHP导出生成Excel文件
    Mysql merge引擎介绍
  • 原文地址:https://www.cnblogs.com/pblr/p/5028661.html
Copyright © 2020-2023  润新知