HDU_1846 Brave Game(sg函数简化版)
2011-09-28 11:18
218 查看
/*做完后看到网上很多人推的规律,还有巴什博弈。表示还没有学习巴什博弈,直接用 sg写的,这题可以说是sg函数的简化版。最后只需判断sg 是否为0即可。回家看巴什 博弈去,T_T...(看到队里很多人都是0MS过的,不得不佩服啊,估计网上流传的代码这题 用sg写的我这是独此一家了,就是时间有点烂。呵呵,不过这题作为sg函数的入门题还是不 错的)*/ /*My Code 109+ms */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N = 1007; int sg ; int m; int mex(int v){ if(sg[v] != -1) return sg[v]; int i, tmp; bool vis = {0}; for(i = 1; i <= m; i++){ tmp = v - i; if(tmp < 0) break; sg[tmp] = mex(tmp); vis[sg[tmp]] = true; } for(i = 0; i < N; i++){ if(!vis[i]){ sg[v] = i; break; } } return sg[v]; } int main(){ //freopen("data.in", "r", stdin); int n, t; scanf("%d", &t); while(t--){ scanf("%d%d", &n, &m); if(n == m){ puts("first"); continue; } if(m == 1){ if(n&1) puts("first"); else puts("second"); continue; } memset(sg, -1, sizeof(sg)); sg[0] = 0; sg[1] = 1; mex(n); if(!sg ) puts("second"); else puts("first"); } return 0; }
相关文章推荐
- HDU 1846-Brave Game(巴什博弈-SG函数)
- HDU--2897 -- 邂逅明下 HDU--1846 -- Brave Game [巴什博奕]
- HDU - 1846 - Brave Game
- 【hdu 1846】Brave Game
- hdu 1846 Brave Game (巴什博弈)
- hdu 1846 Brave Game (巴什博弈)
- HDU - 1846 Brave Game
- HDU - 1846 Brave Game
- HDU 1846 Brave Game
- hdu1846 Brave Game
- HDU-1846-Brave Game 简单【巴什博弈】
- 【巴什博弈】杭电 hdu 1846 Brave Game
- HDU 1846 Brave Game
- hdu1846——Brave Game(巴什博奕)
- (step8.2.4)hdu 1846(Brave Game——巴什博奕)
- hdu 1846 Brave Game
- HDU 1846 Brave Game 巴什博弈 SG打表
- hdu 1846 Brave Game 勇敢者的游戏 DP/巴什博弈
- HDU1846 Brave Game
- HDU - 1846 Brave Game