n个盒子中,每个盒子原本有一些石头,每次能放的石头不能超过已经存在石头个数的平方。
很明显的是一个组合游戏的和,求每个的sg值,然后求各sg值的异或和。
寻找必败态:
设x,x * x+x<s,使x尽量大,所以:
1.c>x 则c * c+c>=s 成立,为原Nim博弈的一个小状态,sg值为s-c。
2.c==x,则c * c+c<s,先手必须至少放一个石头,则会达到1状态,所以后手赢,sg值为0;
3.c<x,无法确定,(s,x)为一个必败态,那么,问题可转化为求(x,c)的sg值。
供上小菜鸡的代码:
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#define debug(); puts("what the fuck");
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF= 0x7fffffff;
const int MAXN= 1e6+10;
double PI=3.1415926535898;
typedef long long ll;
int s,c;
int sg(int s,int c){
int x=sqrt(s);
while((x*x+x)>=s) x--;
if(x<c) return s-c;
else if(x==c) return 0;
else return sg(x,c);
}
int main(){
int N;
int i,j=1;
while(cin>>N&&N){
int ans=0;
for(i=1;i<=N;i++){
cin>>s>>c;
ans=ans^sg(s,c);
}
ans=ans^0;
if(ans) printf("Case %d:\nYes\n",j++);
else printf("Case %d:\nNo\n",j++);
}
}
还请各位客官指出不足。