• 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 }
  • 相关阅读:
    从源码观测STLstd::vector
    如何设计一个更通用的查询接口
    spring内嵌cglib包,这里藏着一个大坑
    JUC之线程池基础与简单源码分析
    JUC之线程池的实现原理以及拒绝策略
    扩容新生代为什么能够提高GC的效率
    JUC之文章整理以及汇总
    JUC之Fork/Join框架
    关于Synchronized你了解多少?
    (数据科学学习手札134)pyjanitor:为pandas补充更多功能
  • 原文地址:https://www.cnblogs.com/pblr/p/5028661.html
Copyright © 2020-2023  润新知