HDU 5724 - Chess
来源:互联网 发布:广西人东北人 知乎 编辑:程序博客网 时间:2024/06/04 20:01
Problem Description
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.
Input
Multiple test cases.
The first line contains an integer T(T≤100), indicates the number of test cases.
For each test case, the first line contains a single integer n(n≤1000), the number of lines of chessboard.
Then n lines, the first integer of ith line is m(m≤20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20) followed, the position of each chess.
Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.
Sample Input
2
1
2 19 20
2
1 19
1 18
Sample Output
NO
YES
题意:给出一个 n 行 * 20 的棋盘,对于每个位置,如果右边是空的则可以放棋子,如果不是空的就在右边第一个为空的位置放,两人轮流放,直到谁不能放了就判输。
提示在代码中。
#include <cstdio>#include <cstring>int ans[1100000];bool vis[30];int DFS(int x){ if (ans[x] != -1) return ans[x]; memset(vis, false, sizeof(vis)); int tmp; for (int i = 0; i < 19; ++i) { if ((1 << i) > x) break; ///Find a 0 near to 1 if (((x & (1<<i)) == 0) && (x & (1<<(i+1)))) { int j = i+2; for (; j < 20; ++j) { if (x & (1 << j)) continue; else break; } j--; ///change 1's position for (int k = i+1; k <= j; ++k) { tmp = (x - (1<<k) + (1<<i)); tmp = DFS(tmp); vis[tmp] = true; } } } for (int i = 0; ;i++) { if (!vis[i]) { ans[x] = i; break; } } return ans[x];}int main(){ memset(ans, -1, sizeof(ans)); for (int i = 0; i <= 20; ++i)///Must lose ans[(1<<i)-1] = 0; for (int i = 1; i <= 1100000; ++i) { if (ans[i] == -1) ans[i] = DFS(i); } int T; scanf("%d", &T); while (T--) { int n, m, ret, state; scanf("%d", &n); ret = 0; for (int i = 0; i < n; ++i) { state = 0; scanf("%d", &m); for (int j = 0; j < m; ++j) { int tmp; scanf("%d", &tmp); state += (1 << (20-tmp)); } ret ^= ans[state]; } if (ret) printf("YES\n"); else printf("NO\n"); } return 0;}
- HDU 5724 Chess
- 多校&&HDU.5724 Chess
- HDU 5724 Chess (博弈)
- HDU 5724 Chess
- HDU-5724 Chess(Nim)
- 【HDU】5724 Chess
- hdu 5724chess 博弈
- HDU 5724 Chess
- HDU 5724 - Chess
- hdu 5724 - chess (sg函数)
- HDU 5724 Chess(博弈论)
- hdu 5724 Chess(sg函数)
- hdu 5724 Chess SG函数
- HDU 5724 Chess (状压+sg)
- Chess HDU
- Chess HDU
- Chess HDU
- HDU 5724 Chess (博弈 状压+sg函数)
- hdu5573 Binary Tree 二进制
- C【语言】计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
- 关于Oracle 数据库12.1.0.2的新参数EXAFUSION_ENABLED
- Zookeeper全解析——Paxos作为灵魂
- 人人都能用Python写出LSTM-RNN的代码![你的神经网络学习最佳起步]
- HDU 5724 - Chess
- pgm转jpg
- RabbitMQ-二、安装部署
- rtmplib rtmp协议过程分析
- Jquery ajax 没有返回
- jabRef中文手册
- hdu 1584 蜘蛛牌
- 自定义结构体通过模板实现
- Python如何读写文本文件