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$ 分(否則不獲得分數)。隨後,他將選擇的這張牌放置到桌面上。

請注意,回合是公開進行的:每位玩家在任何時刻都能看到桌面上所有的牌。

Nene 非常聰明,她總是會採取最佳策略來最大化她遊戲結束時的總得分。如果她有多種最佳策略,她會選擇能使你遊戲結束時總得分最小化的策略。

更正式地說,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.