SRM 518 DIV 二 1000P
SRM 518 DIV 2 1000P
2011年9月14日晚7点,SRM 518 DIV 2
250P 和 500P 都是简单题,所以剩余时间好多啊,1000P 没想在点上。
1000P Problem
有N个硬币头朝上放着,给一系列整数a[],每次随机的选ai个硬币反转。
求最后头朝上的期望个数。
1000P Solution
论坛里 {Exp[K]} 有解释,
“Firstly, there are n coins head up, and 0 coin tail up.
After each turn, each coin has the equal possibility P = (a[i] / N) to change its side. So we know the coins of head up is heads = heads * (1-P) + tails * P and the tail up is tails = N - heads(Because the sum of except value heads and tails is N).”
http://apps.topcoder.com/forums/?module=Thread&threadID=720659&start=0&mc=3
2011年9月14日晚7点,SRM 518 DIV 2
250P 和 500P 都是简单题,所以剩余时间好多啊,1000P 没想在点上。
1000P Problem
有N个硬币头朝上放着,给一系列整数a[],每次随机的选ai个硬币反转。
求最后头朝上的期望个数。
1000P Solution
论坛里 {Exp[K]} 有解释,
“Firstly, there are n coins head up, and 0 coin tail up.
After each turn, each coin has the equal possibility P = (a[i] / N) to change its side. So we know the coins of head up is heads = heads * (1-P) + tails * P and the tail up is tails = N - heads(Because the sum of except value heads and tails is N).”
http://apps.topcoder.com/forums/?module=Thread&threadID=720659&start=0&mc=3
public class CoinReversing { public double expectedHeads(int N, int[] a) { double h = N; for (int x : a) { double P = x*1.0 / N; h = h*(1-P) + (N-h)*P; } return h; } }