AT3939 [ARC091D] Strange Nim

博弈论

与普通nim不同的是在任意一堆中至少取1,至多取 $ \lfloor \frac {a}{k} \rfloor $ 个

 相比,我们这次就不能直接^石子数量,所以我们需要写一个SG函数,去评判一堆石子,然后再去异或

 

 

 

#include<bits/stdc++.h>

#define int long long
using namespace std;
const int N=1e5+7;

int n;
int ans;
int SG(int x,int k)
{
    if(!(x%k))
    return x/k;
    if(x<k)
    return 0;
    
    int f=x/k+1, p=(x%k-1)/f+1;
    
    return SG(x-f*p,k);
}

signed main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    
    for(int i=1;i<=n;i++)
    {
        int q,w;
        cin>>q>>w;
        
        ans^=SG(q,w);
    }
    if(ans)
    cout<<"Takahashi"<<endl;
    else
    cout<<"Aoki"<<endl;
    
    return 0;
}

 

 

posted @ 2021-10-08 15:20  Hehe_0  阅读(52)  评论(0)    收藏  举报