codeforces Gym - 101147A The game of Osho(sg博弈)

题意:
给出g对数字,每对由bi和ni组成,一次操作可以选择一对,然后将ni减去bi的k次幂,k为任意非负整数,无法操作者失败,问先后手谁能赢。

题解:
打出sg表可以发现,对于b是奇数,sg值=n%2。
对于b是偶数,则存在一个长度为b+1的循环节,如果n%(b+1)==0,则sg=0,如果n%(b+1)==b,则sg=2,其余情况,都是1010交替出现,即sg=(n%(b+1))%2。

附上打表代码+ac代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#define iss ios::sync_with_stdio(false)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int>pii;
const int MAXN=1e6+5;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double pi=acos(-1);
int sg[105][105];
bool vis[105];
void getsg(){

    memset(sg,0,sizeof sg);
    for(int i=1;i<=20;i++){//b
        for(int j=1;j<=20;j++){//n
            memset(vis,0,sizeof vis);
            for(int k=1;k<=j;k=k*i){
                vis[sg[i][j-k]]=1;
                if(i==1) break;
            }
            for(int k=0;;k++){
                if(!vis[k]){
                    sg[i][j]=k;
                    break;
                }
            }
        }
    }
    for(int i=1;i<=20;i++){
        for(int j=1;j<=20;j++){
            cout<<sg[i][j]<<" ";
        }
        cout<<endl;
    }
}
int main()
{
    freopen("powers.in","r",stdin);
    //getsg();
    int t;
    cin>>t;
    while(t--){
        int b,n,g;
        cin>>g;
        int ans=0;
        while(g--){
            cin>>b>>n;
            if(b&1){
                ans^=n%2;
            }
            else{
                if(n%(b+1)==b) ans^=2;
                else if(n%(b+1)!=0) ans^=(n%(b+1))%2;  
            }
        }
        if(ans) printf("%d\n",1);
        else printf("2\n");
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值