Codeforces Round #259(div2)C(数学期望)

数学题。

关键是求最大值为k时有多少种情况,结果是kn-(k-1)n-1。可以这么想:每一次都从1至k里选,共kn种,这里需要再减去每一次都从1至k-1里面选的情况。当然也可以分类计数法:按出现几次k来分类,然后逆着用一下二项式定理得出结论。

整个的期望是Σk(kn-(k-1)n-1)/mn,其中k=1......n。

这里的技巧在于:由于n<=105,   kn显然会RE,那么就先把分母除上,每次算一个小于1的浮点数的n次方,肯定不会RE。C++中乘方用pow函数算是很快的。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
#define INF 1000000000
#define eps 1e-8
#define pii pair<int,int>
#define LL long long int
double m,n,ans=0;
int main()
{
    //freopen("in3.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%lf%lf",&m,&n);
    for(int i=1;i<=m;i++)
    {
        ans+=i*(pow(i/m,n)-pow((i-1)/m,n));
    }
    printf("%.12f\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Codeforces Round #259(div2)C(数学期望)

时间: 2024-08-26 14:42:42

Codeforces Round #259(div2)C(数学期望)的相关文章

codeforces round#259 div2 B题(KMP)

先上链接:http://codeforces.com/contest/454/problem/B B. Little Pony and Sort by Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day, Twilight Sparkle is interested in how to sort a se

codeforces Round #259(div2) C解题报告

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

codeforces Round #259(div2) B解题报告

B. Little Pony and Sort by Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day, Twilight Sparkle is interested in how to sort a sequence of integers a1,?a2,?...,?an in non-decreas

codeforces Round #259(div2) D解题报告

D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony

codeforces Round #259(div2) E解题报告

E. Little Pony and Summer Sun Celebration time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Ce

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) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

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 Round #259 (Div. 1) (A,B,C)

Codeforces Round #259 (Div. 1) A题:最大值为i的期望为(in?(i?1)n)?i/mn,那么总期望为∑m1(in?(i?1)n)?i/mn,然后化简一下公式,答案为m?∑m?11i/mn B题:状压DP,只需要用到小于59的素数,一共有16个,dp[n][s]表示当前放到第n个数字,素数使用的集合为s的最小值,S[k]表示k数字对应会用掉哪几个素数,然后进行状态转移 dp(n, s) = dp(n - 1, s^S[k]) + abs(k - num[n]) C题