QOJ.ac

QOJ

时间限制: 5 s - 10 s 内存限制: 1024 MB 总分: 17

#5959. 起立鼓掌

统计

歌剧院的首演之夜到了,你的朋友是首席女高音。虽然你不会坐在观众席中,但你希望确保她能获得全体起立鼓掌的待遇——即每一位观众都站起来为她鼓掌。

起初,所有观众都坐着。每位观众都有一个“羞涩等级”。羞涩等级为 $S_i$ 的观众会等待至少 $S_i$ 名其他观众站起来鼓掌后,才会立即站起来鼓掌。如果 $S_i = 0$,那么无论其他人做什么,该观众都会立即站起来鼓掌。例如,羞涩等级为 $S_i = 2$ 的观众起初会坐着,但在看到至少两名观众站起来鼓掌后,她也会站起来鼓掌。

你知道观众席中每个人的羞涩等级,并且准备邀请额外的朋友加入观众席,以确保最终每个人都能站起来鼓掌。你可以为这些朋友指定任意的羞涩等级。请问为了保证全场起立鼓掌,你最少需要邀请多少位朋友?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例包含一行,首先是 $S_{max}$(观众中最害羞的人的最高羞涩等级),随后是一个长度为 $S_{max} + 1$ 的数字字符串。该字符串的第 $k$ 位数字(从 0 开始计数)表示观众中有多少人的羞涩等级为 $k$。例如,字符串 "409" 表示有 4 名观众的 $S_i = 0$,有 9 名观众的 $S_i = 2$(没有 $S_i = 1$ 或其他等级的观众)。注意,最初每种羞涩等级的人数都在 0 到 9 之间。

字符串不会以 0 结尾。注意,这意味着观众席中始终至少有一名观众。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是测试用例编号(从 1 开始),$y$ 是你需要邀请的最少朋友数量。

数据范围

$1 \le T \le 100$。

小数据集

$0 \le S_{max} \le 6$。

大数据集

$0 \le S_{max} \le 1000$。

样例

样例输入 1

4
4 11111
1 09
5 110011
0 1

样例输出 1

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

说明

在 Case #1 中,观众最终会自发地全场起立鼓掌,无需你邀请任何人——首先 $S_i = 0$ 的观众站起来,然后 $S_i = 1$ 的观众站起来,以此类推。

在 Case #2 中,必须邀请一名 $S_i = 0$ 的朋友,这足以让所有观众站起来。

在 Case #3 中,一种最优方案是增加两名 $S_i = 2$ 的观众。

在 Case #4 中,只有一名观众,他会立即站起来。无需邀请任何朋友。

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.