zoukankan      html  css  js  c++  java
  • ZOJ 3696 Alien's Organ(泊松定理,期望值)

    Alien's Organ

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    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

    Author: FAN, Yuzhe
    Contest: The 13th Zhejiang University Programming Contest

    //泊松定理
    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<stack>
    #include<map>
    #include<set>
    #include<queue>
    #include<cmath>
    #include<string>
    #include<vector>
    using namespace std;
    int n,t;
    double e=2.7182818285;
    double E,sum;
    
    int main()
    {
        //printf("%.10lf",exp(1));
       while(~scanf("%d",&t))
       {
       for(;t>0;t--)
       {
           scanf("%d %lf",&n,&E);
           sum=pow(e,-E);
           double a=1.0,b=1.0;
           for(int i=1;i<=n;i++)
           {
               a=a*E;
               b=b*i;
               sum=sum+a/b*pow(e,-E);
           }
          //sum=sum*pow(e,-E);
         //在最后一起乘会出现精度问题,数值不对
          printf("%.3lf
    ",sum);
       }
       }
    
        return 0;
    }
  • 相关阅读:
    [Effective Java读书笔记] 第二章 创建和销毁对象(1~7)
    [Guava官方文档翻译] 5. Guava的Object公共方法 (Common Object Utilities Explained)
    [Guava官方文档翻译] 4. 使用Guava Ordering排序 (Ordering Explained)
    iOS正则表达式
    ios UIKit动力
    iOS8 UISearchViewController搜索功能讲解
    APP被苹果APPStore拒绝的各种原因
    iOS tableViewCell plane格式下,接近section边缘不显示分割线却被复用解决办法
    企业证书APP发布流程
    iOS越狱包
  • 原文地址:https://www.cnblogs.com/stepping/p/6676055.html
Copyright © 2011-2022 走看看