hdoj-5591-ZYB's Game

来源:互联网 发布:s算法的基本特征 编辑:程序博客网 时间:2024/06/05 01:09

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 ofX 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
13
 

Sample Output
1

简单的博弈,分清楚必败态和必胜态就Ok

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        printf("%d\n",n%2 == 0 ? 0 : 1);      }    return 0;}


0 0
原创粉丝点击