codeforces 120E Put Knight!
来源:互联网 发布:axure7.0mac中文版下载 编辑:程序博客网 时间:2024/06/05 18:22
题目链接:传送门。
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
221
Output
10
【题意】
给你一个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;}
阅读全文
0 0
- codeforces 120E Put Knight!
- E - Knight Moves
- Knight Tournament CodeForces
- codeforces 357C Knight Tournament
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- CodeForces 356A Knight Tournament 【线段树】
- CodeForces 357C - Knight Tournament(模拟)
- Codeforces #356C: Knight Tournament 题解
- Codeforces 78E Evacuation
- 【dp】codeforces 83E
- Codeforces 124 E
- Codeforces 231E
- Codeforces 231E - Cactus
- Codeforces #163 Div2 E
- codeForces 35E
- Codeforces 35E
- Playlist codeforces 268E
- 《20171109》
- robot framework 初学--打开浏览器
- opencv 手写选择题阅卷 (一)表格设计与识别
- Maven 运行错误GC overhead limit exceeded解决方法
- HDU 6223 Infinite Fraction Path
- codeforces 120E Put Knight!
- 【WEB】HTML标签自带属性title样式修改
- 2017/11/9模拟赛总结
- 习题6.2
- Honeywell WinCE6.0 开发包(D6X10 Device SDK for WinCE 6.0)
- springmvc的拦截器使用
- @EXPORT 和@EXPORT_OK区别
- phoenix secondary
- oj第四周作业题解