读书人

10056 - What is the Probability -水

发布时间: 2012-10-05 15:34:34 作者: rapoo

10056 - What is the Probability --水题

#include<cstdlib>#include<iostream>#include<cstdio>#include<cmath>#include<set>#include<cstring>#include <algorithm>#define inf 0x7fffffff#define N 10000#define MIN 1e-6//至少是6,5的话就错了!#define M 100#define LL long longusing namespace std;//int n,k,h,t,m;int ma[N];int main(){#ifndef ONLINE_JUDGE    freopen("ex.in","r",stdin);#endif    int t;    scanf("%d",&t);    int s,n;    double p;    while(t--)    {        scanf("%d%lf%d",&s,&p,&n);        double T=1.0,ans=0.0;        for(int i=0; i<s; i++)        {            T*=1.0-p;        }        double temp=1.0;        for(int i=0; i<n-1; i++)            temp*=1-p;        temp*=p;        ans+=temp;        temp*=T;        while(temp>MIN)        {            ans+=temp;            temp*=T;        }        printf("%.4lf\n",ans);    }    return 0;}

读书人网 >编程

热点推荐