Codeforces Div. 2 #259-C. Little Pony and Expected Maximum
来源:互联网 发布:战舰世界克利夫兰数据 编辑:程序博客网 时间:2024/05/16 05:52
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
//AC代码
/*求数学期望唉,当时没想出来公式(淡淡的忧伤)*/#include<iostream>#include<queue>#include<cstdio>#include<algorithm>#include<cstring>#include<iomanip>#include<map>#include<cstdlib>#include<cmath>#include<vector>#define LL long long#define IT __int64#define zero(x) fabs(x)<eps#define mm(a,b) memset(a,b,sizeof(a))const int INF=0x7fffffff;const double inf=1e8;const double eps=1e-10;const double PI=acos(-1.0);const int Max=20001;using namespace std;int sign(double x){ return (x>eps)-(x<-eps);}typedef struct Node{ double x; double y; Node(const double &_x=0, const double &_y=0) : x(_x), y(_y) {} void input() { cin>>x>>y; } void output() { cout<<x<<" "<<y<<endl; }}point;double xmult(point p0,point p1,point p2){return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double dmult(point p0,point p1,point p2){return(p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);}double Distance(point p1,point p2)// 返回两点之间欧氏距离{return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );}int main(){ int n,m,i,j; double sum; while(cin>>n>>m) { sum=n; for(i=1;i<n;i++) sum-= pow(i/(double)n,(double)m); cout<<setprecision(12)<<setiosflags(ios::fixed)<<sum<<endl; } return 0;}
- Codeforces #259 (Div. 2) C. Little Pony and Expected Maximum
- Codeforces Div. 2 #259-C. Little Pony and Expected Maximum
- CF #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 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
- Codeforces 454C Little Pony and Expected Maximum 简单期望
- Little Pony and Expected Maximum CodeForces
- 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
- 在 javascript 中,为什么 [1,2] + [3,4] 不等于 [1,2,3,4]?
- java中的抽象类
- 前端工程师的修真秘籍(css、javascript和其它)
- 修改WordPress中上传附件2M大小限制的方法
- C++设计模式-Prototype原型模式
- Codeforces Div. 2 #259-C. Little Pony and Expected Maximum
- 写给新入IT的新人们
- 如何调试libc++abi.dylib handler threw exception错误
- java基础之内部类
- C程序设计语言(K&R)第五章学习笔记
- 程序员的这一天:也许永远不会到来
- MyEclipse中的SVN操作手册
- C++设计模式-Bridge桥接模式
- 直接拿来用!最火的Android开源项目整理