1-2-K Game

题目描述

Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).

Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.

Who wins if both participants play optimally?

Alice and Bob would like to play several games, so you should determine the winner in each game.

 

输入

The first line contains the single integer T (1 ≤ T ≤ 100) — the number of games. Next T lines contain one game per line. All games are independent.

Each of the next T lines contains two integers n and k (0 ≤ n ≤ 109, 3 ≤ k ≤ 109) — the length of the strip and the constant denoting the third move, respectively.

 

输出

For each game, print Alice if Alice wins this game and Bob otherwise.

 

样例输入

4
0 3
3 3
3 4
4 4
 

样例输出

Bob
Alice
Bob
Alice

 

这个题就仅仅是找规律,然而找规律就会发生很多未知的错误,最终找到规律:除了k为3的倍数,其他的都是三个数一组,n为3的倍数时bob就win;当k为3的倍数时,以m+1个数为一组,除了n%(m+1)==m时,当得到的余数对3取余得到0时bob就win

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        if(m%3==0)
        {
            int x=n%(m+1);
            if(x!=m && x%3==0)
            {
                printf("Bob\n");
            } else
            {
                printf("Alice\n");
            }
        } else
        {
            if(n%3==0)
            {
                printf("Bob\n");
            } else
            {
                printf("Alice\n");
            }
        }
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值