BZOJ3609 [Heoi2014]人人尽说江南好 【博弈】
题目链接
题解
我们假设最后合成若干个\(m\),和\(n \mod m\),此时合成次数是最多的,也唯一确定胜利者
可以发现,在轮流操作的情况下,胜利者一定可以将终态变为这个状态
所以只用判奇偶性即可
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int n,m,cnt;
int main(){
int T = read();
while (T--){
n = read(); m = read();
cnt = n / m * (m - 1);
if (n % m) cnt += n % m - 1;
printf("%d\n",!(cnt & 1));
}
return 0;
}