QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 960 MB Total points: 100 Hackable ✓

#15835. Drinking Culture

الإحصائيات

菲律宾人酷爱饮酒。在菲律宾,计划一场“inuman”(饮酒聚会)时,人们有多种选择:从传统的棕榈酒 lambanog,到随处可见的 San Miguel Pale Pilsen 啤酒,再到经典的 Tanduay Rum

你知道吗?Ginebra San Miguel(一种流行的本地杜松子酒)瓶身上的标志是画家费尔南多·阿莫索洛(Fernando Amorsolo)于 1917 年受托创作的,他后来被公认为菲律宾首位国家艺术家。饮酒是菲律宾文化的一部分!

鲍勃(Bob)自诩为调酒师。他收藏了 $n$ 瓶酒精饮料,编号为 $1$ 到 $n$。他知道第 $i$ 瓶酒含有 $v_i$ 单位的液体(按体积测量),其中恰好有 $a_i$ 单位是酒精。注意,始终满足 $0 \le a_i \le v_i$。

液体的酒精含量等于该液体中酒精所占的比例(按体积计)。第 $i$ 瓶液体的酒精含量恰好为 $a_i/v_i$。每瓶酒的内容物都是完全均匀的,即从第 $i$ 瓶中取出的任何数量的液体都将保持 $a_i/v_i$ 的酒精含量。

为了调制一杯酒,鲍勃可以选择他收藏中的任意瓶子子集,并从每个瓶子中取出任意数量的液体(不必是整数值)。他将这些样本混合到一个杯子中,并搅拌至均匀。

鲍勃的朋友是一位统计学家,她在经历了漫长而艰苦的工作后,想让鲍勃为她调制一杯能让她不省人事的酒。她向鲍勃提出了以下挑战:

  • 她从区间 $[0, V]$ 中均匀随机生成一个实数 $s$,其中 $V = \sum_{i=1}^{n} v_i$ 是鲍勃收藏中所有液体的总量。
  • 她还从区间 $[0, 1]$ 中均匀随机生成一个实数 $f$。
  • 鲍勃的任务是利用他的收藏调制出一杯酒,使得:
    • 酒的总量恰好为 $s$,且
    • 酒的酒精含量恰好为 $f$。

鲍勃能成功完成这项任务的概率是多少?

输入格式

第一行包含一个整数 $n$。 第二行包含 $n$ 个空格分隔的整数 $v_1, v_2, v_3, \dots, v_n$。 第三行包含 $n$ 个空格分隔的整数 $a_1, a_2, a_3, \dots, a_n$。

输出格式

输出一个介于 0.0 和 1.0 之间的十进制数值,表示鲍勃能完成任务的概率。 如果你的答案与裁判答案的绝对误差或相对误差不超过 $10^{-8}$,则视为正确。用符号表示,设 $ans_{\text{you}}$ 为你的答案,$ans_{\text{judge}}$ 为裁判答案,若满足以下条件则你的答案被接受: $$|ans_{\text{you}} - ans_{\text{judge}}| \le 10^{-8}$$

数据范围

$2 \le n \le 2 \times 10^5$ 对于每个 $i$,$1 \le v_i \le 10^9$ 且 $0 \le a_i \le v_i$

样例

输入 1

3
350 750 330
140 131 16

输出 1

0.19356182654786474591

说明

让我们考虑两个具体的例子。这里,$V = 350 + 750 + 330 = 1430$。 假设 $s = 500$ 且 $f = 3/13$。那么,答案是肯定的!鲍勃可以(例如)混合 $97750/377$ 单位的第 1 瓶酒和 $90750/377$ 单位的第 3 瓶酒。混合物中的液体总量为 $$97750/377 + 90750/377 = 188500/377 = 500,$$ 酒精含量为 $$\frac{(97750/377) \frac{140}{350} + (90750/377) \frac{16}{330}}{500} = \frac{3}{13}.$$ 然而,假设 $s = 814$ 且 $f = 0.1234567$。那么很遗憾,答案是否定的。可以证明,使用鲍勃的酒精收藏无法调制出这样的酒。

当考虑 $s$ 和 $f$ 所有可能取值对的分布时,可以调制出该酒的概率约为 $0.19356182654786474591$。

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.