HDU 5795
題意:
兩人輪流從 n 堆 糖果里取糖果,每次可以
1) 選擇一堆取任意個(不為 0)
2) 選擇一堆糖果分成 3 堆(每堆數量 >= 1)
拿到最后一顆糖果的人贏。
?
?
解題 :
打表算出一些 sg 值,就可以發現規律,
sg(0) = 0; sg(1) = 1; sg(2)= 2;
當 x >= 3 時,后繼中就有分堆的情況辣
sg(3) = mex(sg(0),sg(1),sg(2),sg(1,1,1)) = 3;
sg(4) = mex(sg(0),sg(1),sg(2),sg(3),sg(1,1,2)) = 4;
...
sg(7) = 8;
sg(8) = 7;
...
sg(15) = 14;
sg(16) = 15;
...
所以 規律為
若 x = 8k + 7,sg(x) = x + 1; (k>=0)
若 x = 8k + 8, sg(x) = x - 1; (k>=0)
其余情況 ,sg(x) = x ;
開始自己找的是 8k-1 和 8k+1,也過了
?
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <string> #include <map> #include <cmath> using namespace std; int a[1000010]; int main() {int t,n;scanf("%d",&t);while(t--) {int ans = 0;scanf("%d",&n);for(int i=0;i<n;i++) {scanf("%d",&a[i]);if((a[i]-7)%8 == 0) a[i] += 1; else if( ((a[i] -8) % 8 ) == 0) a[i] -= 1;ans ^= a[i];}printf((ans == 0)?"Second player wins.\n":"First player wins.\n");}return 0; }?
轉載于:https://www.cnblogs.com/ember/p/5741719.html
總結
- 上一篇: Sqlite 管理工具收藏
- 下一篇: 男人梦到吃李子预示着什么