zoukankan      html  css  js  c++  java
  • CF453A Little Pony and Expected Maximum

    CF453A 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 mm faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the mm -th face contains mm dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability img. 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 nn times.

    输入格式

    A single line contains two integers mm and nn ( 1<=m,n<=10^{5}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}10−4 .

    题意翻译

    暮暮刚刚在和她的朋友——AJ(苹果杰克)、FS(小蝶)、RD(云宝黛西)玩Ludo游戏。但是她马品没攒够总是输。回到城堡过后,她对游戏用的骰子产生了兴趣。

    题目描述

    这个骰子有M面:骰子的第一面有一个点,第二面有两个点,以此类推,第m面含有M点。暮暮确信的是,当掷骰子时,每一面都有1/m的可能性出现,并且每次投掷的概率都是都是独立的。请你帮助她计算掷N次骰子后每次得到的点数中最大值的期望。

    输入输出格式

    输入格式:

    一行两个整数 m 和 n (1 ≤ m, n ≤ 10^5).

    输出格式:

    输出一行一个实数,与答案误差不大于10^-4


    题解:

    对于这种数学期望类的题目,思路往两个方向去:第一种思考可不可以递推地DP转移,也就是我们常说的期望DP。第二种就是直接从期望的定义进行探究,用数学方法推导一个公式然后求解。

    这道题首先想到期望DP,但是没有设置出一个比较好的状态来进行转移。

    那么直接考虑可不可以推导。

    期望的定义:概率乘权值。

    那么现在权值已知,我们只需要找每个权值的概率即可。

    首先总事件数为(m^n),很好理解。

    假设扔了n次之后,扔到的最大值是k。那么在这(m^n)种情况中,符合要求的情况就是(k^n-(k-1)^n)种。

    为什么呢?

    扔到1-k的情况是(k^n),扔到1-(k-1)的情况是((k-1)^n),容斥可得。

    所以期望就是:

    [sum_{i=1}^mfrac{i imes (i^n-(i-1)^n)}{m^n} ]

    化简可得代码:

    注意,不要用long double

    #include<cstdio>
    #include<cmath>
    using namespace std;
    double n,m,ans;
    int main()
    {
    	scanf("%lf%lf",&m,&n);
    	for(double i=1;i<=m;i++)
    	    ans+=i*(pow(i/m,n)-pow((i-1)/m,n));
    	printf("%.12lf
    ",ans);
        return 0;
    }
    
  • 相关阅读:
    开放GIS标准OGC之路(4)之 解密Filter(摘抄)
    在WCF中使用async/await 关键字的简化的异步编程模型(译)
    WinCE仿真器设置
    oracle PL/SQL编程详解
    oracle 日期格式
    钢笔工具使用教程
    使用Signature Tool自动生成P/Invoke调用Windows API的C#函数声明
    利用bitmap将图片部分颜色透明
    PS圆角图片并保留透明背景
    Script Debugger的使用
  • 原文地址:https://www.cnblogs.com/fusiwei/p/13856807.html
Copyright © 2011-2022 走看看