【cf 1194 D】1-2-K Game

(Sb Road then let this problem get stuck, I'm more than sb sb)

Meaning of the questions:

n thing, two people take turns, each can be removed one, two, or the k, the output can not take, who is seeking to win.

$ 0 \ leq n \ leq 10 ^ {9}, 3 \ leq k \ leq 10 ^ {9} $

 

answer:

Without this k, obviously if n is a multiple of 3 it is FLAC win or wins the upper hand.

Method of operation is always a personal guarantee $ n \ equiv 0 (mod 3) $

So the question is this way of thinking:

  • If $ k \ equiv 0 (mod 3) $, SG push function, easy to find that it has a length of (k + 1) cycle section, then after mod (k + 1) can be determined by SG value.
  • Otherwise, the effect of k with 1 or 2 as taken do not take k does not affect the win situation, according to the original method to judge.

 

Code:

#include<bits/stdc++.h>
#define maxn 100005
#define maxm 500005
#define inf 0x7fffffff
#define ll long long
 
using namespace std;
int N,K;
 
inline int read(){
    int x=0,f=1; char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
 
int main(){
    int T=read();
    while(T--){
        N=read(),K=read();
        if(K%3==0) N%=(K+1);
        if((N+1)%3==1 && N!=K) printf("Bob\n");
        else printf("Alice\n");
    }
    return 0;
}
1-2-K Game

 

Guess you like

Origin www.cnblogs.com/YSFAC/p/11665510.html