CodeForces 453A Little Pony and Expected Maximum
来源:互联网 发布:软件测评师证 编辑:程序博客网 时间:2024/06/11 22:51
Description
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.
Input
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
Output
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4.
Sample Input
6 1
3.500000000000
6 3
4.958333333333
2 2
1.750000000000
Hint
Consider the third test example. If you've made two tosses:
- You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
- You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
- You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
- You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
按照第二组样例,M = 6, N = 3
那么如果扔到的最大点数是是1, 那么只有一种情况 即 1 1 1
如果扔到的最大点数是2 那么可能是 1 1 2, 1 2 1,.......每个位置都只能有1和2两种可能(不然最大点数就不是2了),但是要减去所有都是1的情况,所以最大点数是2的情况为2^n-1^n。
因为总的种数是m^n次。所以概率就是(2^n-1^n)/m^n,那么递推一下就可以了。
扔的最大点为k的概率k^n/m^n-(k-1)^n/m^n;
<span style="background-color: rgb(255, 255, 255);">#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int main(){int n,m,i;while(scanf("%d%d",&m,&n)!=EOF){double sum=0.0;double pre=0.0;for(i=1;i<=m;i++){double now=pow((double(i)/double(m)),double(n));sum+=(now-pre)*i;pre=now;}printf("%.12lf\n",sum);}return 0;}</span>
- Codeforces 453A Little Pony and Expected Maximum
- Codeforces 453A. Little Pony and Expected Maximum
- Codeforces 453 A. Little Pony and Expected Maximum
- Codeforces 453A Little Pony and Expected Maximum(期望)
- codeforces 453A Little Pony and Expected Maximum 最大值期望
- Codeforces 453A Little Pony and Expected Maximum 概率期望
- codeforces 453-A Little Pony and Expected Maximum
- codeforces 453A Little Pony and Expected Maximum(期望)
- 【codeforces】 453A Little Pony and Expected Maximum
- Codeforces 453A Little Pony and Expected Maximum
- Codeforces 453A Little Pony and Expected Maximum
- CodeForces 453A Little Pony and Expected Maximum
- [概率DP] Codeforces 453A Little Pony and Expected Maximum
- Codeforces 453 A. Little Pony and Expected Maximum
- Little Pony and Expected Maximum CodeForces
- A. Little Pony and Expected Maximum
- A. Little Pony and Expected Maximum
- Codeforces 453A Little Pony and Expected Maximum 概率题Orz
- 山东理工OJ 1298 活动选择
- findBugs学习小结
- Struts2上传文件的最大Size的设置
- Codeforces Round #205 (Div. 2)
- 微信公众号开发入门篇--使用TP框架配置
- CodeForces 453A Little Pony and Expected Maximum
- vijos-p1599 货币 -记忆化搜索
- tomcat默认端口和应用
- Mysql用NaviCat导入.sql文件出错,...unkown engine= innodb......
- 【mina】对象序列化 mina通信
- 南阳acm 187-快速查找素数
- sql 存储过程命名规范
- 装饰模式简介
- 2016HDU多校联赛-HDU-5744-Keep On Movin(水题)