CF2196A.Game with a Fraction

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob have two integers pp and qq, and they are playing a game with these numbers. The players take turns, with Alice going first. On their turn, a player can do one of two actions:

  • decrease pp by one (this action is possible if p>0p \gt 0);
  • decrease qq by one (this action is possible if q>1q \gt 1).

The game ends when p=0p = 0 and q=1q = 1.

Bob wins if at any point during the game the fraction pq\frac{p}{q} is equal to in value the fraction 23\frac{2}{3}. Otherwise, Alice wins.

Given the initial values of pp and qq, determine the winner of the game if both players play optimally.

Alice 和 Bob 有两个整数 pp 和 qq,他们正用这两个数进行一场游戏。双方轮流行动,Alice 先手。在每一轮中,当前玩家可以执行以下两种操作之一:

  • 将 pp 减少 1(该操作仅在 p>0p > 0 时可行);
  • 将 qq 减少 1(该操作仅在 q>1q > 1 时可行)。

当 p=0p = 0 且 q=1q = 1 时,游戏结束。

若在游戏过程中的任意时刻,分数 pq\frac{p}{q} 的值恰好等于 23\frac{2}{3},则 Bob 获胜;否则 Alice 获胜。

给定初始的 pp 和 qq,假设双方均以最优策略进行游戏,请判断游戏的获胜者。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

Each input case consists of a single line containing two integers pp and qq (1≤p,q≤10181 \le p, q \le 10^{18}).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个输入用例由一行组成,包含两个整数 pp 和 qq(1≤p,q≤10181 \le p, q \le 10^{18})。

输出格式

For each input case, output:

  • "Alice" if Alice wins;
  • "Bob" if Bob wins.

对于每个输入样例,输出:

  • 若 Alice 获胜,输出 “Alice”;
  • 若 Bob 获胜,输出 “Bob”。

输入输出样例

  • 输入#1

    6
    4 6
    10 14
    15 15
    7 12
    7000000000000000 10487275715782582
    1000000000000000000 1000000000000000000

    输出#1

    Bob
    Bob
    Alice
    Alice
    Bob
    Alice

说明/提示

In the first input case, the fraction is already equal to 23\frac{2}{3} by value, so Bob wins.

In the second input case, one possible sequence of the game is as follows:

  • initially p=10,q=14p = 10, q = 14;
  • after Alice's turn p=9,q=14p = 9, q = 14;
  • after Bob's turn p=9,q=13p = 9, q = 13;
  • after Alice's turn p=9,q=12p = 9, q = 12;
  • after Bob's turn p=8,q=12p = 8, q = 12.

Bob wins, as 812\frac{8}{12} is equal to 23\frac{2}{3}. It can be shown that in this example, with optimal play from both players, Bob always wins.

For the third input case, Alice's optimal strategy will be to decrease qq as long as possible. In this case, the game will end in favor of Alice regardless of Bob's actions.

在第一个输入样例中,该分数的值已等于 23\frac{2}{3},因此鲍勃获胜。

在第二个输入样例中,游戏的一种可能进行序列如下:

  • 初始时 p=10,q=14p = 10, q = 14;
  • 爱丽丝操作后 p=9,q=14p = 9, q = 14;
  • 鲍勃操作后 p=9,q=13p = 9, q = 13;
  • 爱丽丝操作后 p=9,q=12p = 9, q = 12;
  • 鲍勃操作后 p=8,q=12p = 8, q = 12。

由于 812\frac{8}{12} 等于 23\frac{2}{3},鲍勃获胜。可以证明,在本例中,若双方均采取最优策略,则鲍勃总能获胜。

在第三个输入样例中,爱丽丝的最优策略是尽可能多地减少 qq。此时,无论鲍勃如何行动,游戏最终都将对爱丽丝有利。

输入解题思路,AI测评打分。不知道怎么写?

首页