Chess HDU
来源:互联网 发布:mac的哪款粉底液好用 编辑:程序博客网 时间:2024/05/16 09:39
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)T(T≤100), indicates the number of test cases.
For each test case, the first line contains a single integer n(n≤1000)n(n≤1000), the number of lines of chessboard.
Then nn lines, the first integer of ith line is m(m≤20)m(m≤20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20)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
这题后来想到才20个,感觉可以用二进制表示提前处理一遍,其实问题的关键这么处理计算sg函数,因为之前计算sg的时候用的都是set,可是发现超时啊。。。,后来我才开始考虑一个问题,一个sg函数的可能取值是多少,实在没办法,打了一个10000内的表观察了一下,发现似乎不是很大,于是打算用数组实现一波,但是数组开多大很纠结,用了30发现居然过了。。。
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>#include<set>#include<cstring>#define INF 0x7fffffffusing namespace std;int sg[1<<20];int main(){ sg[0]=0; sg[1]=0;//初始化 bool vis[30]; for(int s=2;s<(1<<20);s++) { memset(vis,false,sizeof(vis)); for(int i=0;(1<<i)<s;i++) { if(!(s&(1<<i)))//找到一个为0的位置 { int j=i+1; while(s&(1<<j))//那么只要在这个位置前面为1的值都可以移动 { vis[sg[s^(1<<j)^(1<<i)]]=true; j++; } } } int i=0; while(vis[i])i++; sg[s]=i;//返回sg就好 } int t; scanf("%d",&t); int n; int m; int x; /*for(int i=0;i<10000;i++) cout<<i<<":"<<sg[i]<<endl;*/ while(t--) { scanf("%d",&n); int ans=0; while(n--) { scanf("%d",&m); int num=0; while(m--) { scanf("%d",&x); num+=1<<(20-x); } ans^=sg[num]; } //cout<<ans<<endl; if(!ans) printf("NO\n"); else printf("YES\n"); } return 0;}
- Chess HDU
- Chess HDU
- Chess HDU
- HDU 3004 the chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 1691 Chinese Chess
- hdu 3345 War Chess
- HDU 3026 Chinese Chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu 1680 Cheesy Chess
- HDU 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- ImportError: /home/kzl/anaconda2/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (requ
- java学习——java基础(十一)之JVM内存模型
- 百度地图 雷达/地理编码
- day3
- SQL server 2008 链接
- Chess HDU
- 学习笔记(逆向汇编)Day11-Day15
- wireshark抓取不到本地回路的数据包
- MongoDB实战-MongoDB的查询优化器与hint()
- 【POJ】3662
- 合法括号序列判断
- OSG-更新和回调
- 1019
- 【STL】反向迭代器