hdu5724Chess+SG博弈
来源:互联网 发布:linux添加用户组命令 编辑:程序博客网 时间:2024/06/07 10:38
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
Author
HIT
Source
2016 Multi-University Training Contest 1
//第一次跟着大大们做多校,乱写一通代码,wa着玩。赛后补。。
给一个n*20的棋盘,先给出了一堆棋子的位置,两个人轮流着进行操作。
操作:可以将棋子移到右边的第一个空位上,(不能多隔空位)
11100之后的状态可以有。11010,10110,01110.
假如直接将这种状态看成一个数(20位,不大),所以直接状压预处理出所有状态的SG,然后N行直接多问题SG亦或。。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;bool SG[2000004];int a[24];bool visit[24];int pow2[22];inline void getp(){ pow2[0]=1; pow2[1]=2; for(int i=2;i<=20;i++) pow2[i]=pow2[i-1]*2;}inline void geta(int x){ int cnt=20; memset(a,0,sizeof(a)); while(x){ a[cnt--]=x%2; x=x/2; }}inline int getnew(int x,int i,int j){ return x-pow2[i-1]+pow2[j-1];}void getSG(){ memset(SG,0,sizeof(SG)); int zhuang=(1<<20)-1; for(int i=1;i<=zhuang;i++){ geta(i); memset(visit,0,sizeof(visit)); int k=21; for(int j=20;j>=1;j--){ if(a[j]==0){ k=j; continue; } if(k==21) continue; visit[SG[getnew(i,21-j,21-k)]]=true; } for(int j=0;;j++){ if(visit[j]==false){ SG[i]=j; break; } } }}int main(){ getp(); getSG(); int t; scanf("%d",&t); while(t--){ int n; int out=0; scanf("%d",&n); while(n--){ int pp=0,w,c; scanf("%d",&c); while(c--){ scanf("%d",&w); pp+=pow2[20-w]; } out^=SG[pp]; } if(out) printf("YES\n"); else printf("NO\n"); } return 0;}
- hdu5724Chess+SG博弈
- hdu5724Chess
- HDU1851(sg博弈+nim博弈)
- 博弈,求SG值
- poj2960【Nim博弈,SG】
- 博弈 nim sg
- HDOJ1404(SG博弈)
- HDOJ1792(SG博弈)
- HDU 1536 (博弈SG)
- SG函数 博弈
- hdu1907||poj3480 sg博弈
- hdu 2509 sg博弈
- hdu 1729 sg博弈
- 博弈,求sg值
- zoj 3529 博弈SG
- HDOJ1729 [SG博弈]
- HDOJ1730[SG博弈]
- HDOJ1848[SG博弈]
- C++文件输入输出
- Java设计模式-工厂模式
- (POJ1325)Machine Schedule(二部图最大匹配)
- r语言之矩形树状图
- Dialogs(对话框)
- hdu5724Chess+SG博弈
- Java NIO使用及原理分析 (一)
- 杭电OJ 5745 La Vie en rose
- android studio recyclerview基础 自定义列表样式
- .net(NPOI)实现Excel数据的写入和读取
- 2016/07/22 Var变量声明、window的宽高属性、disable属性设置、过滤器
- POJ 3252 Round Numbers
- 【杭电1789】Doing Homework again
- 用C语言写三子棋游戏