版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
游戏规则:
一共有G个子游戏,一个子游戏有Bi, Ni两个数字。两名玩家开始玩游戏,每名玩家从N中减去B的任意幂次的数,直到不能操作判定为输。问谁最终能赢。
证明:b^x = k(b+1)+1或k(b+1)+b
到最后i=0时,剩下-1或1。
/*
b^x = k(b+1)+1或k(b+1)+b
*/
#include <iostream>
using namespace std;
int main()
{
freopen("powers.in","r",stdin);
int t;
cin >> t;
while( t-- )
{
int res = 0;
int m;
cin >> m;
for (int i = 1; i <= m; i++)
{
int b,n;
cin >> b >> n;
n %= (b+1);
if( n == b )
{
if( n % 2 == 0 ) res ^= 2; //此时的必胜态也可以选择失败,所以多组时为2,视为石子数为2的尼姆博弈;
else res ^= 1;
}else if( n % 2 != 0 ) res ^= 1;
}
if( res ) cout << "1" << endl;
else cout << "2" << endl;
}
return 0;
}