codeforces——Little Pony and Expected Maximum

 1 /*
 2    我们枚举每次选择最大数值的情况:m个数, 投掷n次
 3    最大值是1:    1种
 4            2:    2^n-1
 5            3:     3^n-2^n
 6            .....
 7            m:     m^n-(m-1)^n
 8
 9     所以最后的结果=sum((k/m)^n - ((k-1)/m)^n)  (1<=k<=m)
10     不要这样求(k^n/m^n)数据可能会很大!
11 */
12 #include<iostream>
13 #include<cstdio>
14 #include<cmath>
15 using namespace std;
16
17 int main(){
18    int n, m;
19
20    while(cin>>m>>n){
21           double sum, cur=pow(1.0/m, n), nt;
22           sum=cur;
23        for(int i=2; i<=m; ++i){
24           nt=pow(i*1.0/m, n);
25           sum+=(nt-cur)*i;
26           cur=nt;
27        }
28        printf("%.12lf\n", sum);
29    }
30    return 0;
31 } 

codeforces——Little Pony and Expected Maximum

时间: 2024-08-26 14:47:44

codeforces——Little Pony and Expected Maximum的相关文章

Codeforces 453A Little Pony and Expected Maximum 概率题Orz

题目链接:点击打开链接 #include <stdio.h> #include <iostream> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-8 #define pi acos(-1.0) typedef long long ll; int main() { int i, j; double m,n; while(cin>>m>>

Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)

题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是所有最大值是xi的情况数/总情况数一共是m^n种,掷n次,所有最大值是xi的情况数应该是xi^n,但是这里边却包含着最大值非xi且不超过xi的种数,所以再减去最大值是xi-1或者最大值不超过这个的情况数.即sum += xi * (xi^n-(xi-1)^n)/m^n,但是这样求肯定是不行,因为m

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

题目链接 题意: 分析: 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstdio> 6 #include <vector> 7 #include <algorithm> 8 #define LL long long 9 using namespace std; 10 11 in

Codeforces Round #259 (Div. 1)——Little Pony and Expected Maximum

题目连接 题意: 输入n.m,表示一个n面的色子(面上的值为1-n),投掷m次,求得到的最大值的期望(1?≤?m,?n?≤?105). 分析: 假设当前得到的最大值是Max,那么对应的概率是:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ),(1 <= k <= n):化简就可以得到:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ) - ((Max - 1

Codeforces 454C - Little Pony and Expected Maximum

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

Little Pony and Expected Maximum

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 firs

CodeForces 454C——数学——Little Pony and Expected Maximum

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 firs

CodeForces 453A Little Pony and Expected Maximum

题意: n面骰子掷m次,求最大值的期望. 别人的做法:最大值为i的概率=所有点数<=i的概率-所有点数<=i-1的概率,然后直接算. sb做法:精度要求1e-4,而m较大时最大值是一个较小数的概率非常小,精度范围内不影响答案,所以直接dp,f[i][j]表示掷了i次之后最大值为j的概率,通过前缀和优化做到O(n)转移 方程为f[i][j]=(f[i-1][1]+f[i-1][2]+f[i-1][3]+-.+f[i][j-1])*(1/n)+f[i-1][j]*(j/n) 因为点数越小概率越小所

codeforces C. Little Pony and Expected Maximum

题意:一个筛子有m个面,然后扔n次,求最大值的期望; 思路:最大值为1 有1种,2有2n-1种,  3有3n -2n 种   所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这个值求和就可以. 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <cmath> 5 #include <algorithm> 6 using nam