1. 程式人生 > >Codeforces 454C - Little Pony and Expected Maximum

Codeforces 454C - Little Pony and Expected Maximum

pre log 如果 tdi precision als pos def ems

454C - Little Pony and Expected Maximum

思路:

m面的骰子擲n次,總共有m^n種情況,如果一種情況的最大值是m,那麽它肯定包含m,那我們在所有情況下挖掉不包含m的情況:(m-1)^n,所以最大值是m的情況數是m^n-(m-1)^n,同理可得最大值是m-1的情況數是(m-1)^n-(m-2)^n。。。。

代碼:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

int
main() { ios::sync_with_stdio(false); cin.tie(0); double m,n; cin>>m>>n; double ans=m; for(int i=1;i<=m-1;i++){ ans-=pow(((double)i)/m,n); } cout<<fixed<<setprecision(8)<<ans<<endl; return 0; }

Codeforces 454C - Little Pony and Expected Maximum