HDOJ 5724 Chess (SG)
来源:互联网 发布:java cas干什么用的 编辑:程序博客网 时间:2024/06/07 01:14
题意
有n排列数为20的格子,有些行的有些格子放有棋子,每次可以把一个棋子向右移动一个格子,也可以从别的棋子上面跳过去,不能走的人即为输,判断这个人输赢。
思路
加深了一下对求SG表的记忆,其实就是类似DP的考虑当前状态可以通过一步变成什么子问题的状态,然后就求子问题中不存在的mex就行了。
这个题在算某个行的状态的时候把每一行状压一下然后枚举下一步的子问题就可以了。
代码
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define LL long long#define Lowbit(x) ((x)&(-x))#define lson l, mid, rt << 1#define rson mid + 1, r, rt << 1|1#define MP(a, b) make_pair(a, b)const int INF = 0x3f3f3f3f;const int MOD = 1000000007;const int maxn = 1e5 + 10;const double eps = 1e-8;const double PI = acos(-1.0);typedef pair<int, int> pii;int vis[25];int sg[1<<21];void init(int x){ memset(vis, 0, sizeof(vis)); vis[1] = 0; for (int i = 20; i >= 0; i--) if (x & (1 << i)) { for (int j = i - 1; j >= 0; j--) if (!(x & (1 << j))) { vis[sg[x ^ (1 << i) ^ (1 << j)]] = 1; break; } } for (int i = 0; ; i++) if (!vis[i]) { sg[x] = i; break; }}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); for (int i = 0; i < (1 << 20); i++) init(i); int T; scanf("%d", &T); while (T--) { int n, m, ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &m); int status = 0, x; for (int j = 0; j < m; j++) { scanf("%d", &x); status |= 1 << (20 - x); } ans ^= sg[status]; } puts(ans ? "YES" : "NO"); } return 0;}
0 0
- HDOJ 5724 Chess (SG)
- HDOJ 1524 A Chess Game SG函数
- hdu 5724 - chess (sg函数)
- hdu 5724 Chess(sg函数)
- hdu 5724 Chess SG函数
- HDU 5724 Chess (状压+sg)
- HDOJ 5724 Chess
- HDOJ 题目1524A Chess Game(sg博弈)
- HDU 5724 Chess (博弈 状压+sg函数)
- HDU 5724 Chess(博弈,SG函数)
- hdu 5724 Chess(SG函数)
- HDU 5724-Chess-博弈论-sg函数
- HDU 5724 Chess(SG函数 Nim博弈)
- HDU 5724 Chess(SG博弈 + 状压)
- hdu 5724 Chess (SG函数)
- HDU 5724 chess sg函数学习
- hdu 5724 Chess [状压+SG函数]【博弈】
- hdu 5724 Chess(sg博弈)
- Android 特色开发,使用传感器
- 高级安全windows防火墙管理单元无法加载解决方法
- i+++i的解释及i+++++i的语法错误
- 面向对象_匿名内部类的格式和理解
- Python学习-用户交互raw_input()
- HDOJ 5724 Chess (SG)
- [心得]利用python并发提速上线测试效率
- Codeforces 730G Car Repair Shop
- python通过API查阅热点新闻
- 2014~2016百度之星hdu题目
- 和《创时代》
- Linux学习--第四天--find、locate、帮助命令、grep、who、w、压缩命令、网络命令、mount
- Java——第二章(变量)
- 并查集的find和join函数实现