CF1578G.Game of Chance

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The King wants to marry off his daughter, and he wants her husband to have the greatest innate luckiness possible. To find such a person he decided to hold a heads-or-tails tournament.

If person AA with luckiness xx and person BB with luckiness yy play heads-or-tails against each other, person AA wins with probability x/(x+y)x/(x+y).

The tournament has several rounds. Each round some participants are split into pairs. Each pair plays against each other, and the loser leaves the tournament.

The participants are numbered from 11 to nn. During the first round, a number kk (1≤k≤n1 \le k \le n) is selected such that n−k/2n-k/2 is a power of 22 (such kk always exists and is unique). Only participants numbered from 11 to kk take part in the first round. It ensures that in all other rounds the number of participants is the power of 22.

During other rounds, all the participants who still have not left the tournament take part. If during some round, participants numbered p1<…<p2mp_1 \lt \ldots \lt p_{2m} take part, then they are split into pairs in the following manner: participant p2i−1p_{2i-1} plays against participant p2ip_{2i} for each ii from 11 to mm.

The rounds are held until only one participant is left. He is declared the winner of the tournament and he will marry the King's daughter. The princess can't wait to find out who is her future husband. She asked every participant to tell her his luckiness. Assuming they did not lie, she wants to know the probability of each participant winning the tournament. As you are the best friend of the princess, she asks you to help her.

国王想为女儿择婿,希望女婿拥有尽可能高的先天幸运值。为此,他决定举办一场抛硬币锦标赛。

若幸运值为 xx 的人 AA 与幸运值为 yy 的人 BB 进行抛硬币对决,则 AA 获胜的概率为 x/(x+y)x/(x+y)。

该锦标赛包含若干轮次。每轮中,部分参赛者被两两配对;每对选手进行对决,败者退出锦标赛。

参赛者编号为 11 至 nn。在第一轮中,选择一个数 kk(1≤k≤n1 \le k \le n),使得 n−k/2n - k/2 是 22 的幂(这样的 kk 总是存在且唯一)。仅编号为 11 至 kk 的参赛者参加第一轮。此举保证了后续所有轮次中参赛者人数均为 22 的幂。

在其余轮次中,所有尚未退出锦标赛的参赛者均参与。若某一轮中有 2m2m 名参赛者,其编号按升序排列为 p1<…<p2mp_1 < \ldots < p_{2m},则他们按如下方式配对:对每个 i=1,2,…,mi = 1, 2, \ldots, m,参赛者 p2i−1p_{2i-1} 与 p2ip_{2i} 对决。

锦标赛持续进行,直至仅剩一名参赛者。该人即为锦标赛冠军,并将迎娶国王的女儿。公主迫不及待地想知道自己未来的丈夫是谁。她向每位参赛者询问了各自的幸运值。假设所有参赛者均如实作答,她希望知道每位参赛者赢得锦标赛的概率。作为公主最好的朋友,她请你协助完成这项任务。

输入格式

The first line of the input contains the number of participants, nn (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5). The second line of the input contains nn integer numbers, a1,…,ana_1, \ldots, a_{n} (1≤ai≤1091 \le a_i \le 10^9). The luckiness of the ii-th participant equals to aia_i.

输入的第一行包含参与者人数 nn(2≤n≤3⋅1052 \le n \le 3 \cdot 10^5)。输入的第二行包含 nn 个整数 a1,…,ana_1, \ldots, a_{n}(1≤ai≤1091 \le a_i \le 10^9)。第 ii 位参与者的幸运值为 aia_i。

输出格式

Print nn numbers pip_i. The ii-th number should be the probability of the ii-th participant winning the tournament. The absolute error of your answer must not exceed 10−910^{-9}.

输出 nn 个数字 pip_i。其中第 ii 个数字应为第 ii 位参赛者赢得锦标赛的概率。你的答案的绝对误差不得超过 10−910^{-9}。

输入输出样例

  • 输入#1

    5
    1 4 1 1 4

    输出#1

    0.026 0.3584 0.0676 0.0616 0.4864

说明/提示

Here is an example of a tournament bracket, showing the winning probability in each pair.

以下是一个锦标赛对阵表的示例,其中显示了每对选手之间的获胜概率。

输入解题思路,AI测评打分。不知道怎么写?

首页