QOJ.ac

QOJ

Time Limit: 4 s - 8 s Memory Limit: 1024 MB Total points: 16

#5872. 绝境

Statistics

你在玩一种卡牌游戏,每张牌上都写有一个整数。

游戏规则如下:你手中持有若干张牌(即你的“手牌”)。你需要将手中的牌排列成若干个“顺子”。顺子是指一组数值连续的牌,例如 $\{3, 4, 5\}$ 或单张牌 $\{7\}$。你获得的美元数等于所有顺子中长度最短的那个顺子的长度。如果你没有牌,则无法组成任何顺子,因此你获得零美元。

你将收到一系列测试用例,每个用例描述了你手中的牌。请为每个测试用例计算你能获得的最大美元数。

输入格式

输入的第一行包含测试用例的数量 $T$。

每个测试用例占一行。该行包含一个整数 $N$,表示你手中的牌数,随后是 $N$ 个整数,表示这些牌上的数字。所有数字均以空格分隔。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是测试用例编号(从 1 开始),$y$ 是你能获得的最大美元数。

样例

输入格式 1

4
10 1 2 3 4 5 10 9 8 7 6
8 101 102 103 104 105 106 103 104
0
5 1 2 3 4 9

输出格式 1

Case #1: 10
Case #2: 4
Case #3: 0
Case #4: 1

说明

在样例 1 中,你有十张牌,数字从 1 到 10,因此你可以组成一个长度为 10 的顺子,获得 10 美元。

在样例 2 中,你可以组成两个顺子 $\{101, 102, 103, 104, 105, 106\}$ 和 $\{103, 104\}$,从而获得 2 美元。但更好的做法是组成 $\{101, 102, 103, 104\}$ 和 $\{103, 104, 105, 106\}$,这样可以获得 4 美元。

在样例 4 中,数字为 9 的牌必须单独组成一个顺子。因此你获得 1 美元。

在样例 3 中,你有零张牌,因此你获得零美元。你不能凭空获得金钱。

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.