HDU 1536 S-Nim(组合游戏Nim)
来源:互联网 发布:淘宝商业计划书模板 编辑:程序博客网 时间:2024/05/29 16:31
题意:
限定普通Nim每步拿的的个数,求当前状态是必胜还是必败
分析:
求sg的时候改改就好了,−−为了这个vis数组我unordered_set都上了还是T,看了题解发现改成100就可以了,我表示。。。似懂非懂,谁有科学的解释求解答吧
代码:
//// Created by TaoSama on 2015-11-21// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>#include <unordered_set>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, m, s[105];int sg[10005], mark[10005], kase;int dfs(int x) { int& ret = sg[x]; if(mark[x] == kase) return ret; mark[x] = kase; bool vis[105] = {}; for(int i = 1; i <= n; ++i) if(x >= s[i]) vis[dfs(x - s[i])] = true; else break; for(int i = 0; ; ++i) if(!vis[i]) {ret = i; break;} return ret;}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(scanf("%d", &n) == 1 && n) { ++kase; for(int i = 1; i <= n; ++i) scanf("%d", s + i); sort(s + 1, s + 1 + n); scanf("%d", &m); while(m--) { int k; scanf("%d", &k); int ans = 0; while(k--) { int x; scanf("%d", &x); ans ^= dfs(x); } putchar(ans ? 'W' : 'L'); } puts(""); } return 0;}
0 0
- HDU 1536 S-Nim(组合游戏Nim)
- [ACM] hdu 1536 S-Nim(Nim组合博弈 SG函数打表)
- hdu 1536 S-Nim
- Hdu 1536 S-Nim
- HDU 1536 S-Nim
- hdu 1536 S-Nim
- HDU-1536-S-Nim
- HDU 1536 S-Nim
- hdu 1536 S-Nim
- HDU 1536 S-Nim
- HDU 1536 S-Nim
- HDU 1536 S-Nim
- 【hdu 1536】S-Nim
- hdu 1536 S-Nim
- hdu 1536 S-Nim
- HDU 1536 S-Nim (博弈 sg函数 Nim和)
- HDU 1536 S-Nim SG函数 Nim
- 组合游戏(Nim 、反Nim)
- 阿里云服务器配置说明(待完善)
- C# 获取获取经纬度!
- POJ 3694Network (tarjan bcc + LCA)
- HDU 4155 The Game of 31 (博弈)
- 字节流与字符流的区别详解
- HDU 1536 S-Nim(组合游戏Nim)
- 在WPS中粘帖代码保持代码高亮
- 垃圾回收的一些面试题
- 计算机的存储介质介绍
- 标准trie树(前缀树)的介绍及java实现
- Trie 树 及Java实现
- Unity中使用SLua的一些注意事项
- Servlet生命周期
- UVA 147 Dollars