poj3682:数学期望,O(1)做法附推导过程

这几天一直在磨蹭这题..第一个答案很容易,但在第二个答案我无法算出来了,于是只好求助于Zayin.Zayin又求助于我们年级里面的一个研究生数学老师..而现在终于算出来了,我看了看,自己也推出来几次了,先看题:)

King Arthur‘s Birthday Celebration

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2921 Accepted: 926

Description

King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. The luxurious celebration will start on his birthday and King Arthur decides to let fate tell when to stop it. Every day he will toss a coin which has probability p that it comes up heads and 1-p up tails. The celebration will be on going until the coin has come up heads for K times. Moreover, the king also decides to spend 1 thousand coins on the first day‘s celebration, 3 thousand coins on the second day‘s, 5 thousand coins on the third day‘s ... The cost of next day will always be 2 thousand coins more than the previous one‘s. Can you tell the minister how many days the celebration is expected to last and how many coins the celebration is expected to cost?

Input

The input consists of several test cases.
For every case, there is a line with an integer K ( 0 < K ≤ 1000 ) and a real number p (0.1 ≤ p ≤ 1).
Input ends with a single zero.

Output

For each case, print two number -- the expected number of days and the expected number of coins (in thousand), with the fraction rounded to 3 decimal places.

Sample Input

1 1
1 0.5
0

Sample Output

1.000 1.000
2.000 6.000

Source

POJ Founder Monthly Contest – 2008.08.31, [email protected]POJ

题意:

国王(一个自恋狂)迎来了他的生日,生日开始之时他每天都会抛一次硬币,正面向上的概率为P(= =b其实我很想吐槽怎么做到的),然后多天累计正面向上次数达到k次后,生日庆典结束。

生日庆典要钱的么。国王第一天要花掉1千个金币,第二天要花掉3千个金币,第三天要花掉5千个金币...第n天要花掉(2n-1)个金币。

求:期望举办生日庆典天数和期望花费金币数。

网上大多数都是DP做法,O(n),而且即使是O(1)做法也没给出过程..在此写个小小的推理过程...在此感谢Zayin和老师提供的思路。

第一个答案太简单,在这里我就不予推理了,在这里给出的是第二个答案的推导过程:

设P(t)为举办t天生日后结束的概率,则有:

P(t) = C(t - 1, k - 1) * (1 - P)^(t-k)*P^k;

又 sigma(t = 1,+∞) P(t) = 1

sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^(t-k)*P^k = 1

(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t = 1

∴ sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t = ((1 - p)/p)^k

得出:

E = sigma(t = 1,+∞) P * t^2 (说明:sigma(t = 1,n) 2 * t - 1 = n^2)

sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^(t-k) * P^k * t^2

(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t * t^2

(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t * t^2

(p/(1 - p))^k * sigma(t = 1,+∞) C(t - 1, k - 1) * (1 - P)^t * t^2

(p/(1 - p))^k * k * sigma(t = 1,+∞) C(t, k) * (1 - P)^t * t

在 sigma(t = 1,+∞) C(t, k) * (1 - P)^t * t 中,有:

sigma(t = 1,+∞) C(t, k) * (1 - P)^t * (t + 1) - sigma(t = 1,+∞) C(t, k) * (1 - P)^t

sigma(t = 1,+∞) C(t + 1, k) * (1 - P)^t - (1 /(1 - p)) * sigma(t = 1,+∞) C(t, k) * (1 - P)^(t + 1)

(k + 1) * sigma(t = 1,+∞) C(t + 1, k + 1) * (1 - P)^t - (1 /(1 - p)) * sigma(t = 1,+∞) C(t, k) * (1 - P)^(t + 1)

((k + 1)/(1 - p)^2) * sigma(t = 1,+∞) C(t + 1, k + 1) * (1 - P)^(t + 2) - (1 /(1 - p)) * sigma(t = 1,+∞) C(t, k) * (1 - P)^(t + 1)

代入化得:

((k + 1)/(1 - p)^2) * ((1 - p)/p)^(k + 2) - (1 /(1 - p)) * ((1 - p)/p)^(k + 1)

(k + 1) * ((1 - p)^k/p^(k + 2)) - ((1 - p)^k/p^(k + 1))

∴(p/(1 - p))^k * k * ((k + 1) * ((1 - p)^k/p^(k + 2)) - ((1 - p)^k/p^(k + 1)))

((k * (k + 1))/p^2) - k/p

(k^2 + k)/p^2 - k * p/p^2

(k^2 + k - k * p)/p^2

∴ E = (k^2 + k - k * p)/p^2
然后答案就是(k * (k + 1 - p) / (p * p))了。

以上过程如有纰漏或错误,请您务必在评论区提出。

附上AC代码:

 1 /*Source Code
 2
 3 Problem: 3682        User: aclolicon
 4 Memory: 180K        Time: 0MS
 5 Language: C++        Result: Accepted
 6 Source Code*/
 7 #include
 8 int main(){
 9     double k, p;
10     while(scanf("%lf", &k) && k!=0){
11         scanf("%lf", &p);
12         printf("%.3lf %.3lfn", k/p, (k * (k + 1 - p) / (p * p)));
13     }
14     return 0;
15 }

啊啊,于是这题总算是搞定了。不过某种意义来说,我只是跟随大牛的脚步完成了推导过程,数学期望这方面还需要多加强化。

时间: 2024-10-05 01:18:06

poj3682:数学期望,O(1)做法附推导过程的相关文章

LightOJ 1030 数学期望

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1030 uDebug Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amoun

数学期望

数学期望又称均值(加权均值),例如 甲8环,9环,10环的概率分别为0.1,0.8,0.1,即权重,则加权均值为8*0.1+9*0.8+10*0.1=9:同理乙的加权均值为8.95 则甲的平均成绩优于乙 对于离散型随机变量 连续型随机变量

数学1——概率与数学期望

1.什么是数学期望? 数学期望亦称期望.期望值等.在概率论和统计学中,一个离散型随机变量的期望值是试验中每一次可能出现的结果的概率乘以其结果的总和. 这是什么意思呢?假如我们来玩一个游戏,一共52张牌,其中有4个A.我们1元钱赌一把,如果你抽中了A,那么我给你10元钱,否则你的1元钱就输给我了.在这个游戏中,抽中的概率是$\frac{1}{13} ( \frac{4}{52} ) $,结果是赢10元钱:抽不中概率是$\frac{12}{13}$,结果是亏1元钱.那么你赢的概率,也就是期望值是$-

HDUBoard Game Dice (数学期望)

推出的公式是M^x*x/N,大概意思是M^x*x这些种可能后一定会找出一个裁判,在除以N为数学期望. 可能和数学公式还有关系. #include<stdio.h> #include<math.h> __int64 gcd(__int64 a,__int64 b){ return b == 0 ? a : gcd(b, a%b); } int main() { __int64 i,j,n,m,t,x,a,b,temp,sum; scanf("%I64d",&

HDU 4405 飞行棋上的数学期望

突然发现每次出现有关数学期望的题目都不会做,就只能找些虽然水但自己还是做不出的算数学期望的水题练练手了 题目大意: 从起点0点开始到达点n,通过每次掷色子前进,可扔出1,2,3,4,5,6这6种情况,扔到几前进几,当然对应飞行通道可以通过x直达一点y,x<y,计算到达n点或超过n 点要扔色子的次数的数学期望 从某一点 i 扔完色子可到达 i+1,i+2,i+3,i+4,i+5,i+6这6个点,令dp[i]为到达末尾的数学期望 那么到达之后6个点的数学期望是一样的,那么dp[i]=dp[i+1]*

概率论,简要数学期望(转载)

概率论(https://ruanx.pw/post/%E6%A6%82%E7%8E%87%E8%AE%BA.html) 这东西并不难学.这片博客主要介绍离散概率.连续概率.期望与微积分…… 离散型概率入门 计算方法 首先,我们来讨论一个最原始的问题:抛一个质地均匀的硬币,抛中正面的几率是多大?显然50%50%. 那么问题加深一番:抛两个质地均匀的硬币,都抛中正面的几率是多大?显然25%25%. 进一步,抛nn个硬币,全都正面朝上的几率是0.5×0.5×0.5?=0.5n0.5×0.5×0.5?=

HDU3910(数学期望题,题目难懂)

Liang Guo Sha Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 590    Accepted Submission(s): 426 Problem Description Maybe you know “San Guo Sha”, but I guess you didn’t hear the game: “Liang Gu

[sdut]2623+[sdut]2878//四五届省赛中的两道数学期望

两道数学期望的题今天一起总结上来. 1.the number of steps(第四届省赛) 1 #include <iostream> 2 #include <string.h> 3 #include <iomanip> 4 using namespace std; 5 double dp[100][100]; 6 int n; 7 double a,b,c,d,e; 8 9 int main() 10 { 11 while(cin>>n&&

ZOJ3329-One Person Game(概率DP求数学期望)

One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very simple and interesting one-person game. You have 3 dice, namelyDie1, Die2 and Die3. Die1 hasK1 faces. Die2 has K2 faces.Die3 has K3 faces. All the dic