A - Alien's Organ ZOJ - 3696(泊松分布)

本文介绍了一个名为Marjar的外星人,它来自遥远的Highrich星球,通过不断生成新的战斗器官来对抗地球上道德衰败的问题。文章提供了一个数学模型,用于计算Marjar在一天内生成不超过N个战斗器官的概率,并附带了使用泊松分布实现该计算的C++代码。

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
题意:输入N和(入)lanta,(入)lanta表示平均每天产生多少个物品,求产生物品在N以内的概率是多少?

下面是泊松分布的概率公式:

BZ:首先,膜一下我强大的队友,我推了一堆没推出来,被他一个泊松分布搞定了。。。。orzzzz,,,膜,膜,膜。。。

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 200010;
const ll mod = 1000000007;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        double n, lamuda;
        cin >> n >> lamuda;
        double a = exp(-lamuda);
        double sum = 0;
        for(int k = 0; k <= n; ++k)
        {
            double ans = 1;
            for(int i = k; i > 0; --i)
            {
                ans = lamuda * ans;
                ans = ans / i;
            }
            sum += ans * a;
        }
        printf("%.3f\n", sum);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值