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和入,入表示平均每天产生多少个物品,求产生物品在N以内的概率是多少?
思路:带入泊松分布定理即可
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cctype>
#include <sstream>
#include <climits>
#include <unordered_map>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
const double e=exp(1);
int n;
double p;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&n,&p);
double ans=pow(e,-p);
double ans1=1;
double k=p;
for(int i=2;i<=n+1;i++)
{
ans1+=k;
k=k*p/i;
}
ans=ans*ans1;
printf("%.3f\n",ans);
}
return 0;
}
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