2、代碼
/*+++++++++++++++++++++++++++++
+ 拈遊戲
+
+author:zhouyong 2013-5-1 21:34
++++++++++++++++++++++++++++++++*/
#include <stdio.h>
bool win(int n,int m);
int main()
{
int n,m;
while(1)
{
scanf("%d%d",&n,&m);
printf("%d \n",win(n,m));
}
return 0;
}
bool win(int n,int m)
{
bool f=0;
n%=(m+1)*2;//這個地方的週期是自己憑感覺猜的。
if(n>=1&&n<=m)
return true; //贏的條件。
else
{
for(int i=1;i<=m;i++)
if(n>=i)
f+=!win(n-i,m);//遞歸使自己取球后,儘量使對方不能贏。
return f;
}
}