zoj3696(泊松分布)

Alien’s Organ
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

用到了泊松分布公式https://wenku.baidu.com/view/3b125d7f8e9951e79b89276f.html
刚才用 lf输出,一直不对,才改成了f

#include<bits/stdc++.h>
using namespace std;
int main()
{
   
    int t,n,i;
    double p,ans,tmp,m;
    scanf("%d",&t);
    while(t--)
    {
   
        cin>>n>>p;
        ans=1;
        tmp=1;
        for(i=1;i<=n;i++)
        {
   
            tmp*=p;
            tmp/=i;
            ans+=tmp;
        }
        ans*=exp(-p);
        printf("%.3f\n",ans);
    }
    return 0;
}

全部评论
tql
点赞 回复 分享
发布于 2020-09-30 14:07

相关推荐

合不合适,我自己说了才算
码农索隆:hr:“真执着啊,来我公司当法人吧”
点赞 评论 收藏
分享
酷酷我灵儿帅:这去不去和线不线下面说实话没啥关系
点赞 评论 收藏
分享
07-05 16:23
门头沟学院 Java
mengnankk:我投了300,约了5 6个面试。感觉项目写的太多了。一个项目就写五六个亮点,不是把整个项目的功能描述下。其他的没啥,简历看起来有点长
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务