HDU 1517 A Multiplication Game SG打表
2017-08-24 11:05
399 查看
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=1517题意:
Stan和Ollie玩游戏,初始给定一个数字p=1,两人轮流操作,每次可以用数字p乘以[2,9]内的任意一个数,再给出一个n,谁先使p>=n就获胜。问每次游戏的结果思路:
可以直接找规律的,与2和9有关,写一写很快就发现了。也可以sg打表,因为范围比较大,用map而非数组,这里sg只有false和true两种值#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000 + 10, INF = 0x3f3f3f3f; int main() { int n; while(~ scanf("%d", &n)) { ll p = 1; for(int i = 1; true; i++) { if(i & 1) p *= 9; else p *= 2; if(n <= p) { puts((i & 1) ? "Stan wins." : "Ollie wins."); break; } } } return 0; }
sg打表
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000 + 10, INF = 0x3f3f3f3f; map<ll, bool> sg; map<ll, bool> vis; bool dfs(ll x, ll n) { if(x >= n) return false; if(vis.find(x) != vis.end()) return sg[x]; vis[x] = true; for(int i = 2; i <= 9; i++) { if(! dfs(x * i, n)) return sg[x] = true; } return sg[x] = false; } int main() { ll n; while(~ scanf("%lld", &n)) { sg.clear(); vis.clear(); dfs(1, n); puts(sg[1] ? "Stan wins." : "Ollie wins."); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000 + 10, INF = 0x3f3f3f3f; map<ll, int> sg; map<ll, bool> vis; int dfs(ll x, ll n) { if(x >= n) return 0; if(vis.find(x) != vis.end()) return sg[x]; vis[x] = true; bool use[10]; memset(use, 0, sizeof use); for(int i = 2; i <= 9; i++) { use[dfs(x*i,n)] = true; } for(int i = 0; i < 10; i++) if(! use[i]) { return sg[x] = i; } } int main() { ll n; while(~ scanf("%lld", &n)) { sg.clear(); vis.clear(); dfs(1, n); puts(sg[1] ? "Stan wins." : "Ollie wins."); } return 0; }
相关文章推荐
- HDU 3032 Nim or not Nim? SG打表找规律
- HDU 5795 A Simple Nim 详解(SG打表找规律,博弈好题)
- hdu 3032 Nim or not Nim? (SG打表找规律)
- HDU 3032 (SG打表找规律)
- HDU 1848 Fibonacci again and again SG打表
- hdu_1517(SG函数+打表找规律)
- hdu1536 sg打表
- HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)
- hdu 5795 2016 Multi-University Training Contest 6(SG+打表找规律)
- HDU-4664 Triangulation(博弈SG打表+类似凸包性质)
- hdu 1848 sg——dfs&&打表双实现
- HDU 5795 A Simple Nim 打表sg
- HDU 1517 A Multiplication Game (博弈-求sg)
- HDU 1846 Brave Game 巴什博弈 SG打表
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- HDU 1517 A Multiplication Game (博弈-求sg)
- HDU - 1847 Good Luck in CET-4 Everybody! 简单博弈 SG打表
- HDU 5795 A Simple Nim(SG打表找规律)
- hdu 5795 A Simple Nim(SG打表找规律)
- HDU 3032 Nim or not Nim?(博弈,SG打表找规律)