现在的位置: 首页 > 综合 > 正文

BNU4210

2013年03月04日 ⁄ 综合 ⁄ 共 434字 ⁄ 字号 评论关闭

题目:题目链接


题意:题目的意思就是说给你一堆石子。这里的取石子规则是第一个人拿石子时不能全部拿走。后面的人取石子的时候索取的石子数目不能超过前面的人拿走的数目。现在给你石子的个数,问你最后的结果。


分析:找规律,当石子的数目是2的幂次的时候,处于必败态。


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d", &n);
        if(n == 1)
            printf("0\n");
        else
        {
            int fp = 0;
            while(1)
            {
                if(n == 1)
                {
                    fp = 1;
                    break;
                }
                if(n % 2 == 1)
                {
                    fp = 0;
                    break;
                }
                n /= 2;
            }
            if(!fp)
                printf("1\n");
            else printf("0\n");
        }
    }
    return 0;
}

抱歉!评论已关闭.