UVALive 3668 A Funny Stone Game(博弈)
2014-01-25 19:39
573 查看
Description
The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., n - 1. Two persons pick stones in turn. In every turn, each person selects three piles of stones numbered i, j, k (i < j, j
View Code
The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., n - 1. Two persons pick stones in turn. In every turn, each person selects three piles of stones numbered i, j, k (i < j, j
#include <cstdio> #include <algorithm> #include <iostream> #include <cstring> using namespace std; const int MAXN = 23; int sg[MAXN + 5]; bool mex[MAXN * MAXN]; int n, s[MAXN]; void build_sg() { for(int i = MAXN - 1; i >= 0; --i) { memset(mex, 0, sizeof(mex)); for(int j = i + 1; j < MAXN; ++j) { for(int k = j; k < MAXN; ++k) mex[sg[j] ^ sg[k]] = true; } for(int j = 0; ; ++j) if(!mex[j]) {sg[i] = j; break;} } } void solve() { int ans = 0, *sg = ::sg + MAXN - n; for(int i = 0; i < n; ++i) ans ^= sg[i] * (s[i] & 1); if(ans == 0) { printf(" -1 -1 -1\n"); return ; } for(int i = 0; i < n; ++i) { if(s[i] == 0) continue; for(int j = i + 1; j < n; ++j) { for(int k = j; k < n; ++k) { if((sg[i] ^ sg[j] ^ sg[k] ^ ans) == 0) { printf(" %d %d %d\n", i, j, k); return ; } } } } } int main() { build_sg(); int cnt = 0; while(scanf("%d", &n) != EOF && n) { for(int i = 0; i < n; ++i) scanf("%d", &s[i]); printf("Game %d:", ++cnt); solve(); } }
View Code
相关文章推荐
- [nim博弈扩展 sg函数] UVALive 3668 A Funny Stone Game
- UVALive 3668 A Funny Stone Game
- uva 1378 A Funny Stone Game (博弈-SG)
- LA 3668 A Funny Stone Game(博弈,SG定理)
- UVA 1378 - A Funny Stone Game(博弈)
- uva 1378 A Funny Stone Game 博弈/组合游戏 sg定理
- 【UVA1378】A Funny Stone Game (博弈-求SG值-输出方案)
- UVA 1378 A Funny Stone Game (经典博弈)
- UVALive-7278 - Game of Cards【博弈】【sg定理】
- uva 1378 A Funny Stone Game(博弈论)
- UVA - 1378 A Funny Stone Game (SG定理)
- sg函数_______A Funny Stone Game(uva 1378)
- uva 1378 - A Funny Stone Game(组合游戏)
- uva 1378 - A Funny Stone Game(组合游戏)
- UVa Live 7278 - Game of Cards 博弈
- UVa 1378 A Funny Stone Game [博弈论 SG函数]
- [博弈]A Funny Stone Game
- [UVA1378] A Funny Stone Game && SG函数
- Uva 1378 - A Funny Stone Game
- 博弈_______Stone Game(hdu 4387)