hdu 5724chess 博弈
来源:互联网 发布:java ee ide能写se 编辑:程序博客网 时间:2024/06/05 10:53
题目大意:有一个n*20的棋盘,每一行有若干个棋子,每个棋子可以移动到它右边离它最近第一个空格里,两个人轮流移动,直到有一方不能移动为输。问是否存在先手必胜策略。
分析:棋盘的各个行之间是相互独立的,预处理出0~(1<<20)-1的sg函数,然后对于每一行的状态求出该状态对应的sg函数值,进行异或操作即可。
#include <cstdio>#include <cmath>#include <iostream>#include<ctime>#include<cstdlib>using namespace std;int n;int sg[1100000];int h[20];int dfs(int x){ for (int i=0;i<20;i++) h[i]=0; for (int i=0;i<20;i++) { if (x&(1<<i)) { for (int j=i+1;j<20;j++) { if (!(x&(1<<j))) { h[sg[x^(1<<i)^(1<<j)]]=1; break; } } } } for (int i=0;i<20;i++) if (!h[i]) return i;}int main(){ int t; scanf("%d",&t); for (int i=(1<<20)-1;i>=0;i--) sg[i]=dfs(i); while (t--) { int n; scanf("%d",&n); int ans=0; for (int i=0;i<n;i++) { int q; scanf("%d",&q); int m=0; while (q--) { int x; scanf("%d",&x); m=m | (1<<(x-1)); } ans=ans^sg[m]; } if (ans) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- HDU 5724 Chess (博弈)
- hdu 5724chess 博弈
- HDU 5724 Chess (博弈 状压+sg函数)
- HDU 5724 Chess(博弈,SG函数)
- HDU 5724 Chess(博弈&状压)
- HDU 5724 Chess(SG函数 Nim博弈)
- HDU 5724 Chess(SG博弈 + 状压)
- hdu 5724 Chess [状压+SG函数]【博弈】
- hdu 5724 Chess(sg博弈)
- HDU 5724 Chess(状态压缩+组合博弈)
- (组合博弈)(sg函数模版)HDU 5724 Chess
- hdoj 5724 Chess 博弈初学
- HDU 1524 A Chess Game(SG博弈)
- 2016 多校最后一题 (HDU 5724) Chess (组合博弈)
- (HDU 5724)2016 Multi-University Training Contest 1 Chess(SG函数、博弈)
- HDU 5724 Chess
- 多校&&HDU.5724 Chess
- HDU 5724 Chess
- EXCEL查找SQL SERVER数据库的数据
- 在Android Studio中进行单元测试和UI测试
- Cocos2d-x setContentSize后一个奇怪的现象,老版本的失误
- python3 安装mysql库 pymysql
- Inorder Successor in BST
- hdu 5724chess 博弈
- Qt的The program has unexpectedly finished.问题
- JavaScript强化教程——javascript性能优化
- 安卓开启照相机并保存本地显示高清照片
- MD5算法解析
- HDOJ 2063 过山车(二分匹配)
- 欧拉函数算法分析
- 搭建caffe环境时“error: hdf5.h”找不到的解决方法
- AutoLayout的那些事(一)