1. 程式人生 > >51nod 1831 小C的遊戲(博弈論+打表)

51nod 1831 小C的遊戲(博弈論+打表)

%d cstring tdi urn 博弈 ring stream 導出 logs

比較坑的題目。

題意就是:給出一堆石子,一次操作可以變成它的約數個,也可以拿只拿一個,不能變成一個,最後拿的人輸。

經過打表發現

幾乎所有質數都是先手必敗的,幾乎所有合數都是先手必勝的

只有幾個例外,就是17^n, 2^n這些。

不過繼續推導可以發現16是先手必敗的,因為2,4,8,15都是先手必勝的

所以2^n(n>4)都是先手必勝的

17是先手必勝的,所以17^2是先手必敗的,17^n(n>2)是先手必勝的

17*2是先手必敗的

同理可以推導出2^n*17^m這些(當n>1或m>1)時是先手必勝的

#include <iostream>
#include 
<cstdio> #include <map> #include <cstring> using namespace std; map<int, int> dp, visit; int main() { int T, x; cin>>T; while(T--){ scanf("%d", &x); int isp = 1; for(int i = 2; i*i <= x; i++) if(x % i == 0) isp = 0; if(isp) cout<<((x == 2
) || (x == 17) ? "TAK" : "NIE")<<endl; else cout<<((x == 16) || (x == 34) || (x == 289) ? "NIE" : "TAK")<<endl; } return 0; }

51nod 1831 小C的遊戲(博弈論+打表)