http://acm.hdu.edu.cn/showproblem.php?pid=2188
题意:巴什博奕裸题。
巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。
显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,0< s≤m),那么先取者要拿走s个物品,如果后取者拿走k(k≤m)个,那么先取者再拿走m+1-k个,结果剩下(m+1)(r-1)个,以后保持这样的取法,那么先取者肯定获胜。总之,要保持给对手留下(m+1)的倍数,就能最后获胜。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int n,m,T;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
if(n%(m+1)==0) printf("Rabbit\n");
else printf("Grass\n");
}
return 0;
}