NCPC 2016 Fleecing the Raffle(推导)

来源:互联网 发布:广州多迪网络要交钱吗 编辑:程序博客网 时间:2024/06/03 14:47

题目:https://nanti.jisuanke.com/t/17415
题意:有n个名字在盒子中,抽奖的时候抽p个名字,你可选择作弊来提高自己的中奖几率,就是在盒子中多放些自己的名字(已有一个),求最大几率(赛下看真难懂
思路:
这里写图片描述
所有题解:NCPC 2016 Presentation of solutions - NTNU
代码:

#include<bits/stdc++.h>using namespace std;int main(){    int n,p;    cin >> n >> p;    double maxn = 1.0*p/(n+1),cur;    for(int i = 2; ;i++)    {        cur = maxn*i/(i-1) * (n-p+i)/(n+i);        if(cur >= maxn)            maxn = cur;        else            break;    }    cout << fixed << setprecision(8) << maxn << "\n";    return 0;}
阅读全文
0 0