Fleecing the Raffle

Fleecing the Raffle
Nordic Collegiate Programming Contest 2016.

题意

已经有n张名片,加入x张你的名片,一次取出p张牌,求取出的p张牌中有且只有一张你的名片的最大概率是多少

分析

参考代码

int main(void)
{
    std::ios::sync_with_stdio(false);
    LL n,p ;
    while(cin>>n>>p)
    {
        double x = n/(p-1);
        double ans = 1;
        ans *= p*x;
        ans *= exp(lgamma(n+1)-lgamma(n-p+2)-lgamma(n+x+1)+lgamma(n+x-p+1));
        printf("%0.8f\n",ans);


    }
   return 0;
}

2
gamma函数的应用

int main(void)
{
    LL n,p ;
    while(cin>>n>>p)
    {
        double x = n/(p-1);
        double ans = 1;
        ans *= (double)p*x/(n+1);
        for(int i = 2;i <= p+1;++i)
            ans *= (double)(n-p+i)/(n + x -p+i-1);
        printf("%0.8f\n",ans);
    }
   return 0;
}
全部评论

相关推荐

06-27 18:45
中山大学 Ruby
25届应届毕业生,来广州2个礼拜了,找不到工作,绝望了,太难过了…
应届想染班味:9爷找不到工作只能说明,太摆了或者太挑了。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-25 17:22
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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