hdu 5724 Chess [状压+SG函数]【博弈】
来源:互联网 发布:wifi嗅探软件 编辑:程序博客网 时间:2024/06/05 10:42
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5724
———————————————————————————–.
Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2320 Accepted Submission(s): 985
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
———————————————————————————–.
题目大意:
就是有n个一维的棋盘,两个人轮流走,每次可以将一个棋子移到距离它最近的右边的空位上。最后谁不能移动棋子了就输了。
解题思路
题目中给定的每一维的状态可以用长度为20的二进制数表示,1为有棋子,0为没有棋子。
表示出来之后可以转移出每种状态的后继状态求出对应的SG值,最后将N个SG值异或一下就好了。
在每一次移动的时候对应的二进制数都会变小,所以从1->(1<<20)预处理一下结果就好了.
开始写的记忆化搜索的形式怎么都是WA,后来改了一发预处理就AC了.
附本题代码
———————————————————————————–.
#include <bits/stdc++.h>using namespace std;void display_bit(int a){ for(int i=31;i>=0;i--){ if(a&(1<<i)) printf("1"); else printf("0"); } printf(" -- %d\n",a);}/***********************************************************************/int sg[(1<<20)+100],tmp,p;bool h[30];void init(){ sg[0]=0; for(int i=1;i<(1<<20);i++){ memset(h,false,sizeof(h)); p=-1; for(int j=0;j<20;j++){ if((i&(1<<j))==0) p=j; else if(p!=-1){ tmp = i^(1<<j)^(1<<p); if(sg[tmp]<30) h[sg[tmp]]=true; } } for(int j=0;;j++) if(!h[j]) {sg[i]=j;break; } }}int main(){ init(); int _; while(~scanf("%d",&_)){ while(_--){ int n; scanf("%d",&n); int ans = 0,x,y,tem; for(int i=0;i<n;i++){ scanf("%d",&x); tem = 0; for(int j=0;j<x;j++){ scanf("%d",&y); tem |= (1<<(20-y)); } ans^=sg[tem]; } if(ans) puts("YES"); else puts("NO"); } } return 0;}
- HDU 5724 Chess (博弈 状压+sg函数)
- hdu 5724 Chess [状压+SG函数]【博弈】
- HDU 5724 Chess(博弈,SG函数)
- HDU 5724 Chess(SG函数 Nim博弈)
- HDU 5724 Chess(SG博弈 + 状压)
- (组合博弈)(sg函数模版)HDU 5724 Chess
- HDU-5724 Chess(SG函数+状压)
- hdu 5724 Chess(sg博弈)
- hdu 5724 - chess (sg函数)
- hdu 5724 Chess(sg函数)
- hdu 5724 Chess SG函数
- hdu5724 Chess【博弈+sg函数】
- HDU 5724 Chess (状压+sg)
- HDU ACM 1524 A Chess Game->博弈(SG函数)
- HDU 1524 A Chess Game [SG函数]【博弈】
- (HDU 5724)2016 Multi-University Training Contest 1 Chess(SG函数、博弈)
- HDU 5724 博弈,SG函数
- hdu 5724 Chess(SG函数)
- nyoj128——前缀式计算
- 9.2.5
- How To Install Apache Tomcat 8 on Ubuntu 16.04
- 链表(1)-定义一个简单的链表
- mybatis学习总结(二)——简介
- hdu 5724 Chess [状压+SG函数]【博弈】
- ggolt2数据分析与图形艺术 学习记录
- 简单MIPS处理器的设计蓝图
- Machine Learning机器学习笔记-week1
- 基础算法10:过滤器(Filter)对指定路径不进行过滤
- 小金问呀问不会问题 (sdut oj)
- Unity3D中如何计算场景中的三角面和顶点数
- Linux(ubuntu~16.04.4) redis 3.2.6 Redis Cluster集群主从搭建笔记
- Vue.js——60分钟快速入门