QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 100

#1936. 移动计算

Statistiques

在遥远的 Yaen 星球上,空间是二维的。星球上有许多美丽的石头,Yaen 人非常喜欢收集它们。他们将石头带回家,制作成精美的移动艺术品(mobile arts)来装饰他们的二维客厅。

在他们的二维世界中,移动艺术品(mobile)的定义如下:

  • 由一根绳子悬挂的一块石头,或者
  • 一根长度为 1 的杆子,两端各悬挂一个子移动艺术品;该杆子由一根绳子悬挂在子移动艺术品的重心处。当两个子移动艺术品的重量分别为 $n$ 和 $m$,且它们距离重心的距离分别为 $a$ 和 $b$ 时,满足等式 $n \times a = m \times b$。

例如,如果你有三块重量分别为 1、1 和 2 的石头,以下是一些可能的移动艺术品及其宽度:

给定石头的重量和房间的宽度,你的任务是设计出满足以下两个条件的最宽的移动艺术品:

  • 它使用了所有的石头。
  • 它的宽度小于房间的宽度。

你应该忽略石头的宽度。

在某些情况下,悬挂在杆子两端的两个子移动艺术品可能会重叠(见下图)。这样的移动艺术品是可以接受的。示例中的宽度为 $(1/3) + 1 + (1/4)$。

输入格式

输入的第一行给出了数据集的数量。随后是指定数量的数据集。每个数据集的格式如下:

$r$ $s$ $w_1$ $\vdots$ $w_s$

$r$ 是一个表示房间宽度的小数,满足 $0 < r < 10$。$s$ 是石头的数量。你可以假设 $1 \le s \le 6$。$w_i$ 是第 $i$ 块石头的重量,为一个整数。你可以假设 $1 \le w_i \le 1000$。

你可以假设不存在宽度在 $r - 0.00001$ 和 $r + 0.00001$ 之间的由给定石头组成的移动艺术品。

输出格式

对于输入中的每个数据集,输出一行包含一个小数。该小数应给出如上定义的可能的最宽移动艺术品的宽度。输出行不应包含空格等额外字符。

如果没有满足要求的移动艺术品,则输出 $-1$。

答案的误差不应超过 $0.00000001$。只要满足上述精度条件,你可以输出小数点后任意位数的数字。

样例

输入格式 1

5
1.3
3
1
2
1
1.4
3
1
2
1
2.0
3
1
2
1
1.59
4
2
1
1
3
1.7143
4
1
2
3
5

输出格式 1

-1
1.3333333333333335
1.6666666666666667
1.5833333333333335
1.7142857142857142

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.