zoukankan      html  css  js  c++  java
  • zoj3696(泊松分布)

    p(k)=(y^k) / (k!) * e^(-y)

    其中的y就是平均值

    k就是我们要求的大小。

    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

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <algorithm>
    #include <math.h>
    #include <map>
    #include <queue>
    #include <sstream>
    #include <iostream>
    using namespace std;
    #define INF 0x3fffffff
    
    int main()
    {
        //freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
        //freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n;
            double l;
            scanf("%d%lf",&n,&l);
            double sum=0;
            for(int k=0;k<=n;k++)
            {
                double tmp;
                tmp=exp(-l);
                for(int i=k;i>=1;i--)
                {
                    tmp=tmp*l;
                    tmp=tmp/i;
                }
                sum+=tmp;
            }
            printf("%.3lf
    ",sum);
        }
        return 0;
    }

  • 相关阅读:
    前方高能!!!一大泼干货来袭。。。。
    spring-cloud-gateway(三)自定义lb实现
    spring-cloud-gateway(二)es代理功能需求
    spring-cloud-gateway(一)代码分析
    一个spark MurmurHash map类加器
    hbase RegionTooBusyException报错异常处理
    hbase HexStringSplit 预分区
    spark读写hbase的几种方式,及读写相关问题
    实现elasticsearch网关,兼容不同版本es,滚动升级-功能验证开发
    k8s平台集成kong ingress 布署konga集成ui
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/3153075.html
Copyright © 2011-2022 走看看