zoukankan      html  css  js  c++  java
  • 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. 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.

    Examples
    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

    【分析】

      【一开始打了一个DP。。f[i]表示弄了i次的期望然后转移】

      【第二个样例就错了】

      ↑不要说你学过概率好么?

      好吧,清醒之后就知道,枚举最大值,然后算最大值是i的概率,是$i^n-(i-1)^n$,算一个小容斥吧,要求一定含一个i嘛。。

      累加就好了。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<cmath>
     7 using namespace std;
     8 #define Maxn 100010
     9 
    10 double qpow(double x,int b)
    11 {
    12     double ans=1;
    13     while(b)
    14     {
    15         if(b&1) ans=ans*x;
    16         x=x*x;
    17         b>>=1;
    18     }
    19     return ans;
    20 }
    21 
    22 int main()
    23 {
    24     int m,n;
    25     scanf("%d%d",&m,&n);
    26     double ans=0;
    27     for(int i=1;i<=m;i++)
    28     {
    29         ans+=i*(qpow(1.0*i/m,n)-qpow(1.0*(i-1)/m,n));
    30     }
    31     printf("%.5lf
    ",ans);
    32     return 0;
    33 }
    View Code

    2017-04-21 19:44:52

  • 相关阅读:
    Hadoop命令手册
    HDFS配额管理指南
    HDFS权限管理用户指南
    Hadoop分布式文件系统使用指南
    Hadoop分布式文件系统:架构和设计
    ImageLoader 图片加裁
    发送 一个无序广播
    Intent 转向
    Volley Get Post 方法
    Android 动态设置控件宽高度
  • 原文地址:https://www.cnblogs.com/Konjakmoyu/p/6745201.html
Copyright © 2011-2022 走看看