题目:题目链接
现在有n个箱子,每个箱子有一个容积si和一个当前箱子内的石子数ci,两个人轮流往这n个箱子里面放石子,每次放的个数为1-ci*ci。例如箱子里有3颗石子,那么下一个人就可以放1~9颗石子最后不能放入石子的人输。
这是sg博弈,不过这个sg函数需要分析:
我们知道(s,s0肯定是必败态,此时已经没有可以放入的石子了。
而c+1则是必胜点则有c+1+(c+1)*(c+1)>=s根据这两个公式我们可以求出小于s的最大必败点t。
而t+1----s-1是必胜点因为(t+1---s-1都可以到达s这个点)
接下来分三种情况讨论:
当 c == t 时则此时一定是必败点直接返回0;
当c > t 时 此时C是必胜点只要返回C的后继集合中的最小即可。。。而此时最小是s-c石子数: s s-1 s-2 s-3 ..... c .. .. t
对应的sg值:0 1 2 3 ..... s-c ... 0
而当 c < t 时此时将t当做s继续递归下去。。因为刚开是的s始终为必败点
这个sg值的得到还是比较麻烦的
上代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
int min(int a, int b)
{
if(a<=b)
return a;
return b;
}
int max(int a, int b)
{
if(a>=b)
return a;
return b;
}
double min(double a, double b)
{
if(a<=b)
return a;
return b;
}
double max(double a, double b)
{
if(a>=b)
return a;
return b;
}
int find(int s, int c)
{
int p = sqrt(s+0.0);
while(p + p*p >= s)
p--;
if(c > p)
return s-c;
else return find(p, c);
}
int main()
{
int count=1;
int n;
while(scanf("%d", &n) && n)
{
int ans=0;
int s, c;
while(n--)
{
scanf("%d%d",&s,&c);
ans ^= find(s, c);
}
printf("Case %d:\n",count++);
if(ans)
printf("Yes\n");
else printf("No\n");
}
}
努力努力...