欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1956B.Nene and the Card Game
Nene and the Card Game
You and Nene are playing a card game. The deck with cards is used to play this game. Each card has an integer from to on it, and each of integers through appears exactly on cards. Additionally, there is a table where cards are placed during the game (initially, the table is empty).
In the beginning of the game, these cards are distributed between you and Nene so that each player receives cards.
After it, you and Nene alternatively take turns, i.e. each person takes turns, starting with you. On each turn:
- The player whose turn is it selects one of the cards in his hand. Let be the number on it.
- The player whose turn is it receives point if there is already a card with the integer on the table (otherwise, he receives no points). After it, he places the selected card with the integer on the table.
Note that turns are made publicly: each player can see all the cards on the table at each moment.
Nene is very smart so she always selects cards optimally in order to maximize her score in the end of the game (after rounds). If she has several optimal moves, she selects the move that minimizes your score in the end of the game.
More formally, Nene always takes turns optimally in order to maximize her score in the end of the game in the first place and to minimize your score in the end of the game in the second place.
Assuming that the cards are already distributed and cards in your hand have integers written on them, what is the maximum number of points you can get by taking your turns optimally?
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of test cases follows.
The first line contains a single integer () — the number of cards you and Nene receive in the beginning of the game.
The second line contains integers () — the integers on the cards in your hand. It is guaranteed that each integer from through appears in the sequence at most times.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output one integer: the maximum number of points you can get.
Note
In the first test case, the integers written on your cards are , , and . The integers written on Nene's cards are , , and . The game may proceed as follows:
- You select one of the cards with an integer written on it and place it on the table.
- Nene selects one of the cards with an integer written on it and places it on the table.
- You select the card with an integer written on it, receive point, and place the selected card on the table.
- Nene selects the card with an integer written on it, receive point, and places the selected card on the table.
- You select the card with an integer written on it and place it on the table.
- Nene selects the card with an integer written on it, receive point, and places the selected card on the table.
- You select the card with an integer written on it and place it on the table.
- Nene selects the card with an integer written on it, receive point, and places the selected card on the table.
At the end of the game, you scored point, and Nene scored . It can be shown that you cannot score more than point if Nene plays optimally, so the answer is .
In the second test case, if both players play optimally, you score points and Nene scores points.
Samples
5
4
1 1 2 3
8
7 4 1 2 8 8 5 5
8
7 1 4 5 3 4 2 6
3
1 2 3
1
1
1
2
1
0
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |