QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 100

#11132. 水果游戏

统计

Apfelmann 和 Bananenfrau 是好朋友。今天,Apfelmann 带来了一些苹果,Bananenfrau 带来了一些香蕉。此外,他们还发现了一个椰子。

朋友们决定玩一个水果游戏。他们将苹果、香蕉和唯一的椰子排成一排放在桌子上。玩家轮流行动,Apfelmann 先手。

当且仅当桌面上该苹果或香蕉与椰子之间没有其他水果时,该苹果或香蕉被认为是“可口的”。

轮到 Apfelmann 时,他必须从桌上拿走一个可口的苹果并吃掉。如果此时没有可口的苹果,Apfelmann 跳过他的回合。同样,轮到 Bananenfrau 时,她必须从桌上拿走一根可口的香蕉并吃掉。如果此时没有可口的香蕉,Bananenfrau 跳过她的回合。

先吃完自己所有水果的玩家被宣布为游戏的获胜者。

给定水果在桌上的初始排列,若双方都采取最优策略并力争获胜,请确定谁将赢得游戏。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^4$),表示测试用例的数量。

接下来的 $t$ 行,每行包含一个由大写英文字母 “A”、“B” 和 “C” 组成的字符串,表示水果从左到右的初始排列。“A” 代表苹果,“B” 代表香蕉,“C” 代表椰子。每行字符串中至少包含一个苹果、至少一个香蕉,且恰好有一个椰子。

输入字符串的总长度不超过 $10^6$。

输出格式

对于每个测试用例,输出一行,包含获胜者的名字。

样例

输入 1

3
AAACBB
CABAB
BBBBCBA

输出 1

Bananenfrau
Apfelmann
Bananenfrau

说明

在第一个样例测试用例中,Apfelmann 和 Bananenfrau 轮流从椰子的不同侧面吃掉苹果和香蕉。由于香蕉比苹果少,因此 Bananenfrau 获胜。

在第二个样例测试用例中,玩家轮流从左到右吃掉苹果和香蕉。Apfelmann 先吃完苹果。

在第三个样例测试用例中,Apfelmann 必须跳过他的第一个回合。然后,Bananenfrau 可以选择吃掉椰子左侧的香蕉或右侧的香蕉。一旦 Bananenfrau 吃掉最右侧的香蕉,Apfelmann 将在下一回合吃掉唯一的苹果并获胜。对于 Bananenfrau 来说,更好的策略是先一个接一个地吃掉椰子左侧的所有香蕉,从而迫使 Apfelmann 跳过他的回合。此后,Bananenfrau 将能够通过吃掉最右侧的香蕉来获胜。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.