HDU

题意:A和B两人在1~N中选数字。已知1<=X<=N,谁先选中X谁就输。每当一个人选出一个不是X的数,裁判都会说明这个数比X大还是小,与此同时,可选范围随之缩小。已知A先选,求满足能让B赢的条件下X的个数。

分析:看了别人的博客,比喻成切棍子真的很形象,每次可选范围缩小,恰恰相当于切掉棍子中可选的一截。

1、有一根棍子,中间某处是X,每个人可以依次从两端切去一部分,先切到X的人输。

2、若X在棍子的正中央,那么A必输,因为A无论怎么切都会先打破X两端的平衡,B切成平衡即可。

3、只有N为奇数时,X才会在棍子正中央,且只有这一个位置,因此,个数为1。

4、当N为偶数时,无论X多么靠近中央,A只需要首先把X两端切成平衡,那么打破平衡的一定是B,A只需要随之恢复平衡即可,所以B必输,没有满足让B赢的X,因此,个数为0。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        int N;
        scanf("%d", &N);
        printf("%d
", N & 1);
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7078538.html