zoukankan      html  css  js  c++  java
  • ****K

    K - Alien's Organ
    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
    Submit Status

    Description

    There's an alien whose name is Marjar. It is an universal solder came from planet Highrich a long time ago.

    Marjar is a strange alien. It needs to generate new organs(body parts) to fight. The generated organs will provide power to Marjar and then it will disappear. To fight for problem of moral integrity decay on our earth, it will randomly generate new fighting organs all the time, no matter day or night, no matter rain or shine. Averagely, it will generate λ new fighting organs every day.

    Marjar's fighting story is well known to people on earth. So can you help to calculate the possibility of that Marjar generates no more thanN organs in one day?

    Input

    The first line contains a single integer T (0 ≤ T ≤ 10000), indicating there are T cases in total. Then the following T lines each contains one integer N (1 ≤ N ≤ 100) and one float number λ (1 ≤ λ ≤ 100), which are described in problem statement.

    Output

    For each case, output the possibility described in problem statement, rounded to 3 decimal points.

    Sample Input

    3
    5 8.000
    8 5.000
    2 4.910

    Sample Output

    0.191
    0.932
    0.132

    题意:一个外星人每时每刻都能制造出随机数量的器官。已知平均每天能制造出λ数量器官,求一天内制造器官不超过n的概率。

     

    思路:由于他每时每刻都在随机制造一定数量的器官。所以我们考虑一个瞬间,要么制造出一个器官,要么是0。这显然是一个二项分布。但是要满足上述说法,必须把时间划分精确到一个瞬间,也就是二项分布的n必须无穷大。这时候就要用到Poisson分布当二项分布的n很大而p(λ=np,λ为均值)很小时,泊松分布可作为二项分布的近似显然这题的n相对p来说很大,p很小。值得注意的是你并不能直接用Poisson分布的公式算出每一项P(x),因为那样你不得不面临计算高次幂而产生的精度问题。所以用递推式即可。

    泊松分布的概率质量函数为:

            P(X=k)=frac{e^{-lambda}lambda^k}{k!}

          泊松分布的参数 λ 是单位时间(或单位面积)内随机事件的平均发生率。

           泊松分布的数学期望和方差均为  λ;

    此题关键在于数学公式的感知,起初以为是正态分布,纠结了好久,没能写出来,最后还是找了下概率论的书,套了下所有觉得可能的分布,最终发现泊松分布最恰当。

    此题求解的是 P(X <= K) 的概率

        P(X <= K) = P(0) + P(1) + P(2) + ··· + P(K)(X= 0,1,2,…)

    PS:注意阶乘太大,只能用浮点型~

    代码:

     1 #include <stdio.h>
     2 #include <math.h> 
     3 int main()
     4 {
     5     int t,i,n;
     6     double m;
     7     scanf("%d",&t);
     8     while (t--)
     9     {
    10         scanf("%d%lf",&n,&m);
    11         double k=1.000;
    12         double s=exp(-m); 
    13         for (i=1;i<=n;i++)
    14         {
    15             k*=(i*1.000);
    16             s+=exp(-m)*pow(m,i)/k;
    17         }
    18         printf("%0.3lf
    ",s);
    19     }
    20     return 0;
    21 } 
    View Code
  • 相关阅读:
    linux两数相除计算百分数
    安装lombok
    STS(spring tool suite)修改默认编码
    eclipse项目中的java文件导入后变为空心J问题
    说Gradle
    window下安装git与git使用
    windows下安装git
    Javaweb 实现分页功能
    Xshell连接不上Ubuntu解决方式
    ubuntu下中文乱码解决
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3454282.html
Copyright © 2011-2022 走看看