Chess
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 208 Accepted Submission (s):
Problem Description Alice and Bob is playing a special chess game on an nx20 chessboard. There is several chesses on the chessboard. They can move one chess in one turn. If There is no other chesses on the right adjacent blocks of the moved chess, move the chess to their right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. The chesses can ' t is placed at one block and no chess can is placed out of the chessboard. When someone can ' t move any chess during his/her turn, he/she'll lose the game. Alice always take the first turn. Both Alice and Bob would 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 was 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 2 1 + 1 Sample Output
NO YES Author hit Source multi-university Training Contest 1
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5724
The main topic: N row 20 rows of the chessboard, for each row, if the current piece to the right of the pawn, that can be placed directly to the right, if there is a jump on the back of the first vacancy, a first operation, the last who can not operate then lose, given each line of chess state, ask the initiator whether win
Title Analysis: Combinatorial game problem, direct SG function, because the column is only 20, can be pressed to engage, enumerate each state, find a feasible operation in the state and then mark, the SG function conclusion can refer to the SG function and the SG theorem
#include <cstdio> #include <cstring> int const MAX = 21;
int sg[1 << MAX], Vis[max];
int get_sg (int sta) {memset (Vis, false, sizeof (VIS));
for (int i = +; I >= 0; i--) {if (STA & (1 << i)) {int tmp = STA; for (int j = i-1; J >= 0; j--) {if (! (
STA & (1 << j)) {tmp ^= (1 << i) ^ (1 << j));
VIS[SG[TMP]] = true;
Break
}}}} for (int i = 0; I <=; i++) if (!vis[i]) return i;
return 0;
} int main () {memset (SG, 0, sizeof (SG));
for (int i = 0; i < (1 <<); i++) Sg[i] = Get_sg (i);
int T;
scanf ("%d", &t);
while (T--) {int n, m, p, ans = 0;
scanf ("%d", &n);
for (int i = 0; i < n; i++) {scanf ("%d", &m); int sta = 0;
while (M-) {scanf ("%d", &p);
STA |= (1 << (20-p));
} ans ^= Sg[sta]; } printf ("%s\n", ans?)
"YES": "NO"); }
}