标签:
算得上是一个比较复杂的游戏了,解法见论文《解析一类组合游戏》,需要注意的是visit数组要适当开大点防止溢出。
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 const int N = 25; 7 int a[N]; 8 int sg[N]; 9 10 void init() 11 { 12 sg[0] = 0; 13 bool visit[N << 1]; 14 for ( int i = 1; i < N; i++ ) 15 { 16 memset( visit, 0, sizeof(visit) ); 17 for ( int j = 0; j < i; j++ ) 18 { 19 for ( int k = 0; k <= j; k++ ) 20 { 21 visit[sg[j] ^ sg[k]] = 1; 22 } 23 } 24 int l; 25 for ( l = 0; visit[l]; l++ ) ; 26 sg[i] = l; 27 } 28 } 29 30 int main () 31 { 32 init(); 33 int n, _case = 1; 34 while ( cin >> n, n ) 35 { 36 int ans = 0; 37 for ( int i = 0; i < n; i++ ) 38 { 39 cin >> a[i]; 40 if ( a[i] & 1 ) 41 { 42 ans = ans ^ sg[n - 1 - i]; 43 } 44 } 45 if ( !ans ) 46 { 47 cout << "Game " << _case++ << ": -1 -1 -1" << endl; 48 } 49 else 50 { 51 bool flag = false; 52 for ( int i = 0; i < n && !flag; i++ ) 53 { 54 if ( !a[i] ) continue; 55 for ( int j = i + 1; j < n && !flag; j++ ) 56 { 57 for ( int k = j; k < n; k++ ) 58 { 59 int tmp = ans ^ sg[n - 1 - i] ^ sg[n - 1 - j] ^ sg[n - 1 - k]; 60 if ( !tmp ) 61 { 62 cout << "Game " << _case++ << ": " << i << ‘ ‘ << j << ‘ ‘ << k << endl; 63 flag = true; 64 break; 65 } 66 } 67 } 68 } 69 } 70 } 71 return 0; 72 }
标签:
原文地址:http://www.cnblogs.com/huoxiayu/p/4710381.html