fzu2132

分析得公式为

枚举i,对于M<=i<=N都累加上 C(N, i) * (x^i) * ((1-x)^(N-i))

因为精度问题,我决定先取对数。

但是发现还是有问题,有精度问题的题不加SPJ简直是丧心病狂!!!

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<map>
#include<set>
using namespace std;
#define MP(x,y) make_pair((x),(y))
#define PB(x) push_back(x)
typedef long long LL;
typedef unsigned long long ULL;
/* ****************** */
//const int INF=1000111222;
const double INFF=1e100;
const double eps=1e-8;
//const LL mod=1000000007;
const int mod=1000000007;
const int NN=100010;
const int MM=100010;
/* ****************** */

int main()
{
    int cas;
    int n,m,i;
    double ans,temp,p,p1;
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d%d%lf",&n,&m,&p);
        p1=1.0-p;

        temp=log(p)*(n+0.0);
        ans=exp(temp);
        //ans=C(n,n)*( p^n )*( p1^0 )

        for(i=n;i>m;i--)
        {
            temp-=log(p);
            temp+=log(p1);
            temp+=log(i+0.0);
            temp-=log(n-i+1.0);

            ans+=exp(temp);
        }

        printf("%.4lf\n",ans+1e-12);//不加1e-12居然是WA!
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值