zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    [windows菜鸟]C#中调用Windows API参考工具
    [windows菜鸟]C#中调用Windows API的技术要点说明
    [windows菜鸟]Windows API函数大全(完整)
    C#卸载加载到进程里的dll
    C# 防火墙操作之开启与关闭
    CMD命令行管道命令
    linux kernel elv_queue_empty野指针访问内核故障定位与解决
    U-Boot Driver Model领域模型设计
    linux I/O stack cache 强制刷新
    基于lcov实现的增量代码UT覆盖率检查
  • 原文地址:https://www.cnblogs.com/pblr/p/5028661.html
Copyright © 2011-2022 走看看