Codeforces 1194D. 1-2-K Game

Portal

Consider only the case of $ 1, $ down step, set $ p [i] $ indicates when $ n = i $ when the upper hand win whether

Found their hands, play with $ p $ is the $ 011 011 011 ... 011 $ this cycle (subscript start from $ 0 $, which represents the upper hand to win $ 1 $)

Then I found that when a multiple of $ K $ is not $ 3 $, there is no impact on the $ p $, because the situation is still a losing situation can only reach win, win situation can still reach a losing situation

Then consider $ K $ is a multiple of $ 3 $, then $ p [K] $ went from $ 0 $ becomes $ 1 $, then the $ p [K + 1] $ start is some $ 011011 ... 011 $ until $ p [2K] $

So you can judge according to the laws found

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
int main()
{
    int Q,n,m;
    Q=read();
    while(Q--)
    {
        n=read(),m=read();
        if(m%3||n<m) { if(n%3) printf("Alice\n"); else printf("Bob\n"); continue; }
        if(n==m) { printf("Alice\n"); continue; }
        if(n%(m+1)==m) printf("Alice\n");
        else if((n%(m+1))%3) printf("Alice\n");
        else printf("Bob\n");
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/LLTYYC/p/11597877.html