HDU Stone Game
大概是一道水题吧,了解SG函数的性质就行。
不过还是看了别人的代码。
具体分析 点击打开
找到必胜的条件吧,然后可以递归来求解不确定状态吧。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
int SG(int s,int t)
{
int c=sqrt(s);
while(c*c+c>=s) c--;
if(t>c) return s-t;
else return SG(c,t);
}
int main()
{
int n;
int a,b;
int kase=1;
while(scanf("%d",&n)&&n)
{
int ans=0;
while(n--)
{
scanf("%d%d",&a,&b);
ans^=SG(a,b);
}
printf("Case %d:\n",kase++);
if(ans) printf("Yes\n");
else printf("No\n");
}
return 0;
}