欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2104C.Card Game
Card Game
Alice and Bob are playing a game. They have cards numbered from to . At the beginning of the game, some of these cards are given to Alice, and the rest are given to Bob.
Card with number beats card with number if and only if , with one exception: card beats card .
The game continues as long as each player has at least one card. During each turn, the following occurs:
- Alice chooses one of her cards and places it face up on the table;
- Bob, seeing Alice's card, chooses one of his cards and places it face up on the table;
- if Alice's card beats Bob's card, both cards are taken by Alice. Otherwise, both cards are taken by Bob.
A player can use a card that they have taken during one of the previous turns.
The player who has no cards at the beginning of a turn loses. Determine who will win if both players play optimally.
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains a single integer () — the number of cards;
- the second line contains characters, each either
AorB. If the -th character isA, then card number is initially given to Alice; otherwise, it is given to Bob.
Additional constraint on the input: in each test case, at least one card is initially given to Alice, and at least one card is initially given to Bob.
Output
For each test case, output Alice if Alice wins with optimal play, or Bob if Bob wins. It can be shown that if both players play optimally, the game will definitely end in a finite number of turns with one of the players winning.
Note
In the first test case, Alice has only one card, and Bob has only one card. Since Alice's card beats Bob's card, she wins after the first turn.
In the second test case, Alice has only one card, and Bob has only one card. Since Bob's card beats Alice's card, he wins after the first turn.
In the third test case, there are two possible game scenarios:
- if Alice plays the card on the first turn, Bob can respond with the card and take both cards. Then, Alice has to play the card on the second turn, and Bob will respond by playing the card . Then, he wins;
- if Alice plays the card on the first turn, Bob can respond with the card and take both cards. Then, Alice has to play the card , and Bob can respond either with the card or the card . Then, he wins.
In the fourth test case, there are two possible game scenarios:
- if Alice plays the card on the first turn, Bob can respond with the card and take both cards. Then, Alice has to play the card on the second turn, and Bob will respond by playing the card . Then, he wins;
- if Alice plays the card on the first turn, Bob can respond with the card and take both cards. Then, Alice has to play the card , and Bob can respond either with the card or the card . Then, he wins.
Samples
8
2
AB
2
BA
4
ABAB
4
BABA
3
BAA
5
AAAAB
5
BAAAB
6
BBBAAA
Alice
Bob
Bob
Bob
Alice
Alice
Bob
Alice
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |