codeforces 120E Put Knight!

题目链接:传送门

Petya and Gena play a very interesting game "Put a Knight!" on a chessboard n × n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (r, c) can threat squares (r - 1, c + 2), (r - 1, c - 2), (r + 1, c + 2), (r + 1, c - 2), (r - 2, c + 1), (r - 2, c - 1), (r + 2, c + 1) and (r + 2, c - 1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts.

Input

The first line contains integer T (1 ≤ T ≤ 100) — the number of boards, for which you should determine the winning player. Next T lines contain T integers ni (1 ≤ ni ≤ 10000) — the sizes of the chessboards.

Output

For each ni × ni board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1".

Examples
Input

2
2
1

Output

1
0

【题意】

给你一个n,表示这里有一个n*n的棋盘,两个人相互在棋盘上方象棋中的马,要求放下去的马不能和之前放下去的马相互攻击,也就是说一个马放下去的话就不能在马跳日对应的八个方向上放马。然后,放下去最后一个马的人胜利,问你是否能先手必胜。

【分析】

开始以为是博弈,后来就打了个表,答案显然是很明显,然后就交了一发,过了,然后就证明了一下。

规律很明显:当n是奇数的时候先手必胜,否则后手必胜。

下面是证明:

对于一个人的一次操作来说,我们假设他和他导致不能放马的地方都被他占掉了,显然可以得到每次马占的位置都是奇数个,也就是说当n是奇数的时候,显然可以放下去奇数个马,否则就能放下去偶数个马,也就是对应的先手必胜和后手必胜。

【代码】

#include<bits/stdc++.h>
using namespace std;
int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int T,a;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&a);
        if(a&1) puts("0");
        else puts("1");

    }
    return 0;
}
    原文作者:骑士周游问题
    原文地址: https://blog.csdn.net/mengzhongsharen/article/details/78492842
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞