QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#11210. 顺子大师

Statistics

在扑克牌中,顺子是指五张点数连续的牌,花色不限。例如,7 梅花、6 黑桃、5 黑桃、4 红桃和 3 方块组成一个顺子。在本题中,我们将顺子的定义扩展为 3 到 5 张点数连续的牌。因此,包含 K 黑桃、Q 梅花和 J 红桃的手牌也是一个顺子。

熊猫先生正在玩一种名为“顺子大师”的扑克游戏。该游戏使用一副拥有 $N$ 个点数(从 1 到 $N$)的大型牌组。游戏规则很简单:将熊猫先生手中的牌分成若干个长度为 3 到 5 的顺子。

现在给定一手牌,你能帮熊猫先生判断是否可以将这些牌全部拆分为顺子吗?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。

每个测试用例包含两行。第一行包含一个整数 $N$,表示牌组中的点数数量。第二行包含 $N$ 个整数 $a_1, a_2, \dots, a_N$,表示熊猫先生手中每种点数的牌的数量。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 1 开始),如果熊猫先生可以将他所有的牌拆分为长度为 3 到 5 的顺子,则 $y$ 为 Yes,否则为 No。

数据范围

  • $1 \le T \le 100$
  • $1 \le N \le 2 \times 10^5$
  • $0 \le a_i \le 10^9$
  • $\sum N \le 4 \times 10^6$

样例

输入 1

2
13
1 2 2 1 0 0 0 0 0 0 0 0 0
13
1 1 1 1 0 1 1 0 0 0 0 0 0

输出 1

Case #1: Yes
Case #2: No

说明

在第一个测试用例中,熊猫先生可以将他的牌拆分为两个顺子:$[1, 2, 3]$ 和 $[2, 3, 4]$。在第二个测试用例中,无法为点数 6 和 7 的牌组成顺子。

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.