小d的博弈(博弈论+sg)

活用sg即可

传送门

代码及其注释如下:

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define debug cout<<"debug"<<endl
mt19937 rd(time(0));
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
const double eps = 1e-5;
const double PI = 3.14159265358979323;
const int N = 2e5+10, M = 2*N, mod = 1e9+7;
const int INF = 0x3f3f3f3f;

int n, m, k;

// 普通sg函数, 按题意来, 铁寄
//int sg(int x)
//{
    cout<<u<<endl;
//    if(f[x] != -1) return f[x];
//    unordered_set<int> S;
//    // 从这里可以知道一个数的sg值即为该数二进制位数-2
//    // 当然, 打表看sg值速度更快
//    for(int i = 1; i<=x/2; i++)
//    {
//        if(i+i == x) break;
//        S.insert(sg(i));
//    }
//    for(int i = 0; ; i++)
//        if(!S.count(i)) return f[x] = i;
//}

int sg(int x)
{
//    cout<<u<<endl;
    int res = 0;
    ll w = 2;
    while(x>w)
    {
        x -= w;
        res++;
        w<<=1;
    }
    return res;
}

void prf(int x)
{
    while(x)
    {
        if(x&1) cout<<1;
        else cout<<0;
        x>>=1;
    }
    cout<<endl;
}

void solve()
{
    cin>>n>>m;
    int res = sg(n)^sg(m);
//    prf(n), prf(m);
//    cout<<sg(n)<<" "<<sg(m)<<endl;
    cout<<(res == 0 ? "Bob" : "Alice")<<endl;
}

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int T;
    T = 1;
    cin>>T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值