QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 2048 MB 満点: 100

#16045. 煮蔬菜

統計

Photo by Martin Cathrae

煮蔬菜的诀窍是确保所有蔬菜块的大小大致相同。如果大小不一,小的会煮得太烂,或者大的会煮不熟(或者两者兼有)。幸运的是,你听说过菜刀,但父母关于使用锋利工具的警告仍在脑海中回荡。因此,你最好尽可能少地使用它。你可以将一块重量为 $w$ 的蔬菜任意切成两块,重量分别为 $w_{\text{left}}$ 和 $w_{\text{right}}$,其中 $w_{\text{left}} + w_{\text{right}} = w$。这一操作构成一次“切割”。给定一组蔬菜块,请确定最少需要多少次切割,才能使最终得到的最小蔬菜块与最大蔬菜块的重量比值超过给定的阈值。

输入格式

输入以一个保留两位小数的浮点数 $T$($0.5 < T < 1$)和一个正整数 $N \le 1\,000$ 开始。

接下来是 $N$ 个正整数重量 $w_1, w_2, \dots, w_N$。所有重量均小于 $10^6$。

输出格式

输出最少需要的切割次数,使得最终得到的最小重量块与最大重量块的比值大于 $T$。你可以假设所需的切割次数小于 500。

为了避免浮点数精度问题,你可以假设对于比值 $T$ 的最优解与对于比值 $T + 0.0001$ 的最优解相同。

样例

输入样例 1

0.99 3
2000 3000 4000

输出样例 1

6

输入样例 2

0.80 2
1000 1400

输出样例 2

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.