卧薪尝胆,厚积薄发。
HEOI2014 人人尽说江南好
Date: Mon Sep 24 10:21:27 CST 2018 In Category: NoCategory

Description:

$n$ 堆石子,最开始每堆有一个,每次可以把两堆合成一堆,但合并后的堆不能超过 $m$ 个,问先手胜还是后手胜。
$1\leqslant textcases\leqslant100,1\leqslant m,n\leqslant 10^9$

Solution:

最后的状态一定是 $\lfloor\frac n m\rfloor$ 个 $m$ 的和一个 $n\%m$ 个,每次操作一定会减少一堆,所以统计一下 $\%2$ 就是答案。

Code:


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
int testcases;
scanf("%d",&testcases);
long long n,m;
for(int i = 1;i <= testcases;++i)
{
scanf("%lld%lld",&n,&m);
printf("%d\n",(n - (n / m) + (n % m != 0)) & 1 ^ 1);
}
return 0;
}
Copyright © 2020 wjh15101051
ღゝ◡╹)ノ♡