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);
    }
  • 相关阅读:
    c# 启动线程的方式
    c# 打开文件夹获取所有文件
    windows server 2008 R2 SP1 安装SQL Server 2008 R2时提示 "此操作系统不支持此版本的 SQL Server 版本"
    mongodb 备份 指定用户名密码
    c# 线程启动的两种方式与传参
    vs 2015 密钥
    c# 时间格式yyyy-MM-ddTHH:mm:ss
    c# oledb sql 报错 标准表达式中数据类型不匹配
    CentOS下yum安装dnsmasq,并强制替换为最新版
    使用QUOTA(磁盘配额)来限制用户空间
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4411069.html
Copyright © 2011-2022 走看看