CF1728D.Letter Picking

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Alice and Bob are playing a game. Initially, they are given a non-empty string ss, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.

Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string ss, removes it from ss and prepends (adds to the beginning) it to their own string.

The game ends when the string ss becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.

A string aa is lexicographically smaller than a string bb if there exists such position ii that aj=bja_j = b_j for all j<ij \lt i and ai<bia_i \lt b_i.

What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?

爱丽丝和鲍勃正在玩一个游戏。初始时,他们得到一个非空字符串 ss,该字符串仅由小写拉丁字母组成,且其长度为偶数。每位玩家各自还拥有一个属于自己的字符串,初始为空。

爱丽丝先手,之后双方轮流进行操作。在一次操作中,当前玩家从字符串 ss 的首端或尾端取走一个字母,将其从 ss 中删除,并将其添加到自己字符串的开头(即前置)。

当字符串 ss 变为空时,游戏结束。字符串字典序更小的一方获胜;若双方字符串相等,则为平局。

字符串 aa 字典序小于字符串 bb,当且仅当存在某个位置 ii,使得对所有 j<ij \lt i 都有 aj=bja_j = b_j,且 ai<bia_i \lt b_i。

若双方均以最优策略进行游戏(即:均优先争取胜利;若无法获胜,则争取平局),则游戏结果如何?

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of testcases.

Each testcase consists of a single line — a non-empty string ss, consisting of lowercase Latin letters. The length of the string ss is even.

The total length of the strings over all testcases doesn't exceed 20002000.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示测试用例的数量。

每个测试用例由一行组成——一个非空字符串 ss,仅由小写拉丁字母构成。字符串 ss 的长度为偶数。

所有测试用例中字符串的总长度不超过 20002000。

输出格式

For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".

对于每个测试用例,如果双方都采取最优策略,请输出游戏的结果。若 Alice 获胜,输出 “Alice”;若 Bob 获胜,输出 “Bob”;若为平局,输出 “Draw”。

输入输出样例

  • 输入#1

    2
    forces
    abba

    输出#1

    Alice
    Draw

说明/提示

One of the possible games Alice and Bob can play in the first testcase:

  1. Alice picks the first letter in ss: s=s="orces", a=a="f", b=b="";
  2. Bob picks the last letter in ss: s=s="orce", a=a="f", b=b="s";
  3. Alice picks the last letter in ss: s=s="orc", a=a="ef", b=b="s";
  4. Bob picks the first letter in ss: s=s="rc", a=a="ef", b=b="os";
  5. Alice picks the last letter in ss: s=s="r", a=a="cef", b=b="os";
  6. Bob picks the remaining letter in ss: s=s="", a=a="cef", b=b="ros".

Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.

第一个测试用例中 Alice 和 Bob 可能进行的一场游戏如下:

  1. Alice 选取 ss 中的第一个字母:s=s="orces",a=a="f",b=b="";
  2. Bob 选取 ss 中的最后一个字母:s=s="orce",a=a="f",b=b="s";
  3. Alice 选取 ss 中的最后一个字母:s=s="orc",a=a="ef",b=b="s";
  4. Bob 选取 ss 中的第一个字母:s=s="rc",a=a="ef",b=b="os";
  5. Alice 选取 ss 中的最后一个字母:s=s="r",a=a="cef",b=b="os";
  6. Bob 选取 ss 中剩余的唯一字母:s=s="",a=a="cef",b=b="ros"。

Alice 获胜,因为 "cef" < "ros"。在本示例游戏中,双方均未采用任何特定策略,因此该例子并不能说明当双方都采取最优策略时 Alice 必然获胜。

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

首页