QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#14966. Nene 和纸牌游戏

统计

你和 Nene 正在玩一个纸牌游戏。游戏使用一副包含 $2n$ 张牌的牌组。每张牌上都有一个 $1$ 到 $n$ 之间的整数,且 $1$ 到 $n$ 中的每个整数恰好出现在 $2$ 张牌上。此外,桌面上有一个区域用于放置游戏过程中的牌(初始时桌面为空)。

游戏开始时,这 $2n$ 张牌被分发给你和 Nene,每人各获得 $n$ 张牌。

之后,你和 Nene 交替进行 $2n$ 个回合,即每人各进行 $n$ 个回合,由你先手。在每一回合中:

  • 当前轮到回合的玩家从手中选择一张牌。设牌上的数字为 $x$。
  • 如果桌面上已经有一张数字为 $x$ 的牌,则该玩家获得 $1$ 分(否则不得分)。随后,该玩家将选出的这张数字为 $x$ 的牌放置在桌面上。

注意,游戏过程是公开的:每一时刻,每位玩家都能看到桌面上所有的牌。

Nene 非常聪明,她总是会采取最优策略,以在游戏结束($2n$ 个回合后)最大化她的得分。如果她有多种最优策略,她会选择能使你的最终得分最小化的策略。

更正式地说,Nene 总是优先采取最优策略以最大化她的得分,其次采取策略以最小化你的得分。

假设牌已经分发完毕,你手中的牌上写着整数 $a_1, a_2, \ldots, a_n$,请问在双方都采取最优策略的情况下,你能获得的最高分数是多少?

输入格式

每个测试点包含多个测试用例。第一行包含测试用例数量 $t$ ($1 \le t \le 10^4$)。接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 2 \cdot 10^5$),表示游戏开始时你和 Nene 每人获得的牌数。

第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$),表示你手中牌上的数字。保证 $1$ 到 $n$ 中的每个整数在序列 $a_1, a_2, \ldots, a_n$ 中最多出现 $2$ 次。

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,输出一个整数:你能获得的最高分数。

样例

样例输入 1

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

1
2
1
0
0

说明

在第一个测试用例中,你手中的牌上的数字为 $1, 1, 2, 3$。Nene 手中的牌上的数字为 $2, 3, 4, 4$。游戏过程可能如下:

  1. 你选择一张数字为 $1$ 的牌并将其放在桌面上。
  2. Nene 选择一张数字为 $4$ 的牌并将其放在桌面上。
  3. 你选择另一张数字为 $1$ 的牌,获得 $1$ 分,并将其放在桌面上。
  4. Nene 选择另一张数字为 $4$ 的牌,获得 $1$ 分,并将其放在桌面上。
  5. 你选择数字为 $2$ 的牌并将其放在桌面上。
  6. Nene 选择数字为 $2$ 的牌,获得 $1$ 分,并将其放在桌面上。
  7. 你选择数字为 $3$ 的牌并将其放在桌面上。
  8. Nene 选择数字为 $3$ 的牌,获得 $1$ 分,并将其放在桌面上。

游戏结束时,你得了 $1$ 分,Nene 得了 $3$ 分。可以证明,如果 Nene 采取最优策略,你无法获得超过 $1$ 分,因此答案为 $1$。

在第二个测试用例中,如果双方都采取最优策略,你得 $2$ 分,Nene 得 $6$ 分。

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.