hdu 1729 NIM博弈的变形

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++);
    }
}

还请各位客官指出不足。

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值