zoukankan      html  css  js  c++  java
  • luogu P1943 LocalMaxima_NOI导刊2009提高(1)

    upd 19.11.15

    分 段 打 表


    又是有关于(1-n)排列的题,考虑从大到小依次插入构造排列

    对于第(i)个数(也就是(n-i+1)),只有当它插在当前排列最前面时才会使那个什么数的个数+1,而在最前面的概率为(frac{1}{i}),所以插入(i)增加的什么数的期望个数为(frac{1}{i}),所以答案就是(sum_{i=1}^n frac{1}{i})

    但是这题(n)(2^{31}-1)那么多,,,

    这时要用到一个新东西--调和级数

    这个数就是(sum_{i=1}^n frac{1}{i}=ln (n+1)+gamma(gamma)欧拉-马歇罗尼常数())

    证明是不可能证明的,这辈子都不可能的

    当然(n)过大才能用调和级数,不然会炸精度

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<cmath>
    #include<ctime>
    #include<queue>
    #include<map>
    #define LL long long
    #define il inline
    #define re register
    
    using namespace std;
    const LL mod=1000000;
    const double EMc=0.577215664901;
    il LL rd()
    {
        re LL x=0,w=1;re char ch;
        while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
        while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
        return x*w;
    }
    int n;
    double ans;
    
    int main()
    {
      n=rd();
      if(n<=1000000) for(double i=1;i<=n;i++) ans+=1.00/i;
      else ans=log(n+1)+EMc;
      printf("%.8lf
    ",ans);
      return 0;
    }
    
    
  • 相关阅读:
    2017.3.13-afternoon
    2017.3.13-morning
    2017.3.10-afternoon
    2017.3.10-morning
    2017.3.9-afternoon
    2017.3.9-morning
    神经网络入门
    webpack 安装
    git 常用命令
    mysql 用户管理和权限设置
  • 原文地址:https://www.cnblogs.com/smyjr/p/9430799.html
Copyright © 2011-2022 走看看