Codeforces Round #259 (Div. 2)C. Little Pony and Expected Maximum(数学期望)
来源:互联网 发布:服装设计绘图软件 编辑:程序博客网 时间:2024/05/22 15:35
题目链接:http://codeforces.com/contest/454/problem/C
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 mdots. 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.
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
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.
6 1
3.500000000000
6 3
4.958333333333
2 2
1.750000000000
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
公式:pow(i/m,n)-pow((i-1)/m,n);
代码如下:
#include <cstdio>#include <cmath>int main(){int n, m;int i;while(~scanf("%d%d",&m,&n))//共m面,共抛n次{double sum, t;sum = 0;for(i = 1; i <= m; i++){t = (pow((double)i/m,n) - pow((double)(i-1)/m,n));sum+=t*(double)i;}printf("%.12lf\n",sum);}return 0;}
- Codeforces Round #259 (Div. 2)C. Little Pony and Expected Maximum(数学期望)
- Codeforces Round #259 (Div. 2) C. Little Pony and Expected Maximum(期望)
- Codeforces Round #259 (Div. 2) C. Little Pony and Expected Maximum (找规律)
- Codeforces #259 (Div. 2) C. Little Pony and Expected Maximum
- Codeforces Div. 2 #259-C. Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 2) C. Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 2)C. Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 2) C. Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 2) C Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 2)-C. Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum
- Codeforces 454C Little Pony and Expected Maximum 简单期望
- CF #259 div.2 C. Little Pony and Expected Maximum
- codeforces 453A Little Pony and Expected Maximum(期望)
- Codeforces Round #259 (Div. 1)——Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum
- Codeforces Round #259 (Div. 1) A Little Pony and Expected Maximum
- CodeForces 454C Little Pony and Expected Maximum (数学推导)
- UVALive 6712(2013长春区域赛)
- SPFA+链表
- Regex
- 单例模式(DCL缺陷以及如何安全发布对象)
- [LeetCode] Gray Code
- Codeforces Round #259 (Div. 2)C. Little Pony and Expected Maximum(数学期望)
- ios修改textField的placeholder的字体颜色、大小
- Qt4第三方库QJSON编译说明
- text-indent在ie6下input发生位移
- wpf 异步命令
- 法国的好的好的
- Spring加载配置文件的三种方式
- [LeetCode] Sort Colors
- POSIX 线程详解