Codeforces Div. 2 #259-C. Little Pony and Expected Maximum

来源:互联网 发布:战舰世界克利夫兰数据 编辑:程序博客网 时间:2024/05/16 05:52
C. Little Pony and Expected Maximum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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 test(s)
input
6 1
output
3.500000000000
input
6 3
output
4.958333333333
input
2 2
output
1.750000000000
Note

Consider the third test example. If you've made two tosses:

  1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
  2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
  3. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
  4. 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;}


 

0 0
原创粉丝点击