我的个人记载
  • About Me
不知名小站
Never Give Up
  1. 首页
  2. 博弈论
  3. 正文

1 - 2 - k Game

2019年07月31日 130点热度 8人点赞 0条评论

题目描述
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 ≤ 10^9, 3 ≤ k ≤ 10^9) — 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

题意:有一个东西放在n这个位置 每次可以选择向左移动 1 、2 或者 k 步 不能小于 0 ,不能移动则输。

#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

#define lowbit(x) x & (-x)
#define lson left,mid,root << 1
#define rson mid+1,right,root << 1 | 1

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const double eps=1e-8;
const int maxn=1e5+100;

int main()
{
    int t;
    ll n,k;
    scanf("%d",&t);
    while(t --)
        {
            scanf("%lld%lld",&n,&k);
            if(n == 0)
                {
                puts("Bob");
                continue;
                }
            if(k % 3)
                {
                    if(n % 3)
                        puts("Alice");
                    else
                        puts("Bob");
                }
            else
                {
                int t = n % (k + 1);
                if(t % 3 || t == k)
                    puts("Alice");
                else
                    puts("Bob");
                }
        }
    return 0;
}
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2020年07月03日

框框

喜欢算法,喜欢编程。

打赏 点赞

文章评论

取消回复

框框

喜欢算法,喜欢编程。

文章归档
  • 2021年1月
  • 2020年10月
  • 2020年8月
  • 2020年7月
  • 2020年1月
  • 2019年11月
  • 2019年8月
  • 2019年7月
分类目录
  • 2008年哈尔滨区域赛
  • 2018焦作网络赛
  • Greater New York Region 2014
  • kuangbin并查集专题
  • Kuangbin数论专题
  • NZPC 2017
  • upc个人训练赛
  • 位运算
  • 博弈论
  • 多校训练
  • 搜索
  • 数据结构
  • 数论
  • 杭电多校训练第五场
  • 深入理解计算机基础/CSAPP
  • 算法模板
  • 线段树
  • 训练赛

COPYRIGHT © 2020 我的个人记载. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

苏ICP备19034952号-1