欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1681A.Game with Cards
Game with Cards
Alice and Bob play a game. Alice has cards, the -th of them has the integer written on it. Bob has cards, the -th of them has the integer written on it.
On the first turn of the game, the first player chooses one of his/her cards and puts it on the table (plays it). On the second turn, the second player chooses one of his/her cards such that the integer on it is greater than the integer on the card played on the first turn, and plays it. On the third turn, the first player chooses one of his/her cards such that the integer on it is greater than the integer on the card played on the second turn, and plays it, and so on — the players take turns, and each player has to choose one of his/her cards with greater integer than the card played by the other player on the last turn.
If some player cannot make a turn, he/she loses.
For example, if Alice has cards with numbers , and Bob has cards with numbers , the game may go as follows:
- Alice can choose any of her cards. She chooses the card with integer and plays it.
- Bob can choose any of his cards with number greater than . He chooses a card with integer and plays it.
- Alice can choose any of her cards with number greater than . She chooses the card with integer and plays it.
- Bob can choose any of his cards with number greater than . He chooses a card with integer and plays it.
- Alice can choose any of her cards with number greater than , but she has no such cards, so she loses.
Both Alice and Bob play optimally (if a player is able to win the game no matter how the other player plays, the former player will definitely win the game).
You have to answer two questions:
- who wins if Alice is the first player?
- who wins if Bob is the first player?
Input
The first line contains one integer () — the number of test cases. Each test case consists of four lines.
The first line of a test case contains one integer () — the number of cards Alice has.
The second line contains integers () — the numbers written on the cards that Alice has.
The third line contains one integer () — the number of Bob's cards.
The fourth line contains integers () — the numbers on Bob's cards.
Output
For each test case, print two lines. The first line should be Alice if Alice wins when she is the first player; otherwise, the first line should be Bob. The second line should contain the name of the winner if Bob is the first player, in the same format.
Note
Let's consider the first test case of the example.
Alice has one card with integer , Bob has two cards with numbers .
If Alice is the first player, she has to play the card with number . Bob then has to play the card with number . Alice has no cards left, so she loses.
If Bob is the first player, then no matter which of his cards he chooses on the first turn, Alice won't be able to play her card on the second turn, so she will lose.
Samples
4
1
6
2
6 8
4
1 3 3 7
2
4 2
1
50
2
25 50
10
1 2 3 4 5 6 7 8 9 10
2
5 15
Bob
Bob
Alice
Alice
Alice
Bob
Bob
Bob
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |