CF248E.Piglet's Birthday
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Piglet has got a birthday today. His friend Winnie the Pooh wants to make the best present for him — a honey pot. Of course Winnie realizes that he won't manage to get the full pot to Piglet. In fact, he is likely to eat all the honey from the pot. And as soon as Winnie planned a snack on is way, the pot should initially have as much honey as possible.
The day before Winnie the Pooh replenished his honey stocks. Winnie-the-Pooh has n shelves at home, each shelf contains some, perhaps zero number of honey pots. During the day Winnie came to the honey shelves q times; on the i-th time he came to some shelf u__i, took from it some pots k__i, tasted the honey from each pot and put all those pots on some shelf v__i. As Winnie chose the pots, he followed his intuition. And that means that among all sets of k__i pots on shelf u__i, he equiprobably chooses one.
Now Winnie remembers all actions he performed with the honey pots. He wants to take to the party the pot he didn't try the day before. For that he must know the mathematical expectation of the number m of shelves that don't have a single untasted pot. To evaluate his chances better, Winnie-the-Pooh wants to know the value m after each action he performs.
Your task is to write a program that will find those values for him.
小猪今天过生日。他的朋友小熊维尼想送他一份最好的礼物——一个蜂蜜罐。当然,维尼很清楚自己根本没法把一整罐蜂蜜完好无损地送给小猪;事实上,他很可能会把罐子里的蜂蜜全吃光。而且,由于维尼在去小猪家的路上就计划好了要吃点零食,因此这个蜂蜜罐一开始所装的蜂蜜量应尽可能多。
就在前一天,维尼补充了自己的蜂蜜储备。维尼家里有 n 个架子,每个架子上放着若干(可能为零)个蜂蜜罐。当天,维尼共 q 次来到蜂蜜架子前;第 i 次,他来到某个架子 ui,从中取出 ki 个罐子,逐一品尝其中的蜂蜜,然后将这全部 ki 个罐子放到另一个架子 vi 上。维尼挑选罐子时完全凭直觉行事,这意味着:他在架子 ui 上所有大小为 ki 的罐子集合中,等概率地随机选择一个。
现在维尼回忆起了前一天自己对蜂蜜罐所做的一切操作。他打算带一个前一天未曾品尝过的蜂蜜罐去参加生日派对。为此,他需要知道:未被品尝过的蜂蜜罐一个也没有的架子数量 m 的数学期望值。为了更准确地评估自己的成功几率,维尼希望在每次操作执行后,都能知道当前的 m 值。
你的任务是编写一个程序,帮他计算出每次操作后对应的这些 m 值。
输入格式
The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of shelves at Winnie's place. The second line contains n integers a__i (1 ≤ i ≤ n, 0 ≤ a__i ≤ 100) — the number of honey pots on a shelf number i.
The next line contains integer q (1 ≤ q ≤ 105) — the number of actions Winnie did the day before. Then follow q lines, the i-th of them describes an event that follows chronologically; the line contains three integers u__i, v__i and k__i (1 ≤ u__i, v__i ≤ n, 1 ≤ k__i ≤ 5) — the number of the shelf from which Winnie took pots, the number of the shelf on which Winnie put the pots after he tasted each of them, and the number of the pots Winnie tasted, correspondingly.
Consider the shelves with pots numbered with integers from 1 to n. It is guaranteed that Winnie-the-Pooh Never tried taking more pots from the shelf than it has.
输入的第一行包含一个整数 n(1≤n≤105)——小熊维尼家中的架子数量。
第二行包含 n 个整数 ai(1≤i≤n,0≤ai≤100)——第 i 个架子上的蜂蜜罐数量。
接下来一行包含一个整数 q(1≤q≤105)——小熊维尼前一天所进行的操作次数。随后是 q 行,其中第 i 行按时间顺序描述一次事件;该行包含三个整数 ui、vi 和 ki(1≤ui,vi≤n,1≤ki≤5)——分别表示维尼取走蜂蜜罐的架子编号、维尼品尝完每个罐子后将罐子放回的架子编号,以及维尼当天品尝的蜂蜜罐数量。
假设这些放有蜂蜜罐的架子编号为 1 至 n 的整数。题目保证:小熊维尼从某个架子上取走的蜂蜜罐数量不会超过该架子当前所拥有的数量。
输出格式
For each Winnie's action print the value of the mathematical expectation m by the moment when this action is performed. The relative or absolute error of each value mustn't exceed 10 - 9.
对于小熊的每个操作,请输出执行该操作时的数学期望值 m。每个值的相对误差或绝对误差均不得超过 10−9。
输入输出样例
输入#1
3 2 2 3 5 1 2 1 2 1 2 1 2 2 3 1 1 3 2 2
输出#1
0.000000000000 0.333333333333 1.000000000000 1.000000000000 2.000000000000
输入解题思路,AI测评打分。不知道怎么写?