zoukankan      html  css  js  c++  java
  • Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题

    A. Little Pony and Expected Maximum

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/453/problem/A

    Description

    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 m dots. 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.

    Sample Input

    6 1

    Sample Output

    3.500000000000

    HINT

     

    题意

    给你一个m面的筛子,然后扔N次,求最大值的期望是多少

    题解:

    一开始还以为是个概率dp,哎
    原来是一道数学题
    我们这样想,相当于求一个长度为n的序列,然后问序列中最大值的期望是多少
    对于最大值为k的序列,总共有k^n-(k-1)^n这么多个
    然后我们递推搞一搞就好啦

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    //const int inf=0x7fffffff;   //无限大
    const int inf=0x3f3f3f3f;
    /*
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int buf[10];
    inline void write(int i) {
      int p = 0;if(i == 0) p++;
      else while(i) {buf[p++] = i % 10;i /= 10;}
      for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
      printf("
    ");
    }
    */
    //**************************************************************************************
    
    int main()
    {
        int m,n;
        cin>>m>>n;
        double pre=0;
        double ans=0;
        for(int i=1;i<=m;i++)
        {
            double now=pow((double(i)/double(m)),double(n));
            //cout<<now<<endl;
            ans+=(now-pre)*i;
            pre=now;
        }
        printf("%.10f
    ",ans);
    }
  • 相关阅读:
    Vue.js 模板指令
    51nod 1007 正整数分组【01背包变形】
    Codeforces Round #444 (Div. 2)A. Div. 64【进制思维】
    51nod 1096 距离之和最小【中位数】
    51nod 1433 0和5【数论/九余定理】
    51nod 1596 搬货物【贪心/二进制】
    51nod 1873 初中的算术【Java BigDecimal/高精度小数】
    51nod 1094 和为k的连续区间【前缀和/区间差/map】
    51nod 1095 Anigram单词【hash/map/排序/字典树】
    Educational Codeforces Round 31 B. Japanese Crosswords Strike Back【暴力】
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4411069.html
Copyright © 2011-2022 走看看