zoukankan      html  css  js  c++  java
  • zoj 3696 Alien's Organ (泊松分布(概率))

    Alien's Organ
     

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3696

     

    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 than N 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


    解题思路:泊松分布:
        

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

            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,…)

     

    AC 代码:
     1 #include<iostream>
     2 #include<math.h>
     3 #include<stdio.h>
     4 
     5 using namespace std;
     6 
     7 typedef long long LL;
     8 
     9 int main()
    10 {
    11     LL n, t, i;
    12     double y, final, mul;
    13     cin >> t;
    14     while(t--) {
    15         cin >> n >> y;
    16         final = 0.0;
    17         mul = 1;
    18         for(i = 1; i <= n; ++i) {       //P(1)~ P(n) 的情况
    19             mul *= (i*1.0);
    20             final += (pow(y, i) / mul * exp(-y));
    21         }
    22         final += exp(-y);           // P(0) 的情况
    23         printf("%.3lf\n", final);
    24     }
    25     return 0;
    26 }






  • 相关阅读:
    CSS浏览器兼容性问题集()两
    HTML5 Introduction
    poj 2449 Remmarguts&#39; Date 【SPFA+Astar】【古典】
    LwIP学习笔记——STM32 ENC28J60移植与入门
    在四川大学的第二个冠军游戏在线编程:Peter的X
    ArcEngine下一个TIN生成的轮廓
    精彩理发头盔
    UBUNTU如何改变mysql默认文件夹数据文件夹
    第一章 词汇陷阱
    LINUX2.4.x网络安全框架
  • 原文地址:https://www.cnblogs.com/Duahanlang/p/3065472.html
Copyright © 2011-2022 走看看