zoukankan      html  css  js  c++  java
  • NCPC 2016 Fleecing the Raffle

    Description

    A tremendously exciting raffle is being held, with some tremendously exciting prizes being given out. All you have to do to have a chance of being a winner is to put a piece of paper with your name on it in the raffle box. The lucky winners of the p prizes are decided by drawing p names from the box. When a piece of paper with a name has been drawn it is not put back into the box – each person can win at most one prize. Naturally, it is against the raffle rules to put your name in the box more than once. However, it is only cheating if you are actually caught, and since not even the raffle organizers want to spend time checking all the names in the box, the only way you can get caught is if your name ends up being drawn for more than one of the prizes. This means that cheating and placing your name more than once can sometimes increase your chances of winning a prize. You know the number of names in the raffle box placed by other people, and the number of prizes that will be given out. By carefully choosing how many times to add your own name to the box, how large can you make your chances of winning a prize (i.e., the probability that your name is drawn exactly once)?

    Input

    There will be several test cases. Each case consists of a single line containing two integers n and p ( 2pn1062≤p≤n≤106 ), where n is the number of names in the raffle box excluding yours, and p is the number of prizes that will be given away.

    Output

    Output a single line containing the maximum possible probability of winning a prize, accurate up to an absolute error of 10−6.

    Sample Input

    3 2
    23 5
    

    Sample Output

    0.6
    0.45049857550

    题解:这道题是根据

    概率f(k)={Ck 1 * C n p-1} / Cn+k p

    而 f(k+1) = (k+1)/k * (n+k+1-p)/(n+k+1) * f(k);

    一直推下去直到f(k+1)<f(k)的时候输出f(k) 的值即为最大概率;


    AC代码为:

    #include<iostream>
    using namespace std;

    int main()
    {
    int n,p;
    while(~scanf("%d%d",&n,&p))
    {
    double x=p/(double)(n+1.0);
    double cx=0.0;

    for(int i=1;;i++)
    {
    if(cx<=x)
    cx=x;
    else
    break;
    x*=(i+1.0)/i*(n+i+1.0-p)/(n+i+1.0);
    }

    printf("%0.8lf ",cx);
    }
    return 0;
    }







  • 相关阅读:
    2016年3月至9月随笔
    带大三个hybird app项目的设计管理笔记
    小议新人的培养
    GitHub上整理的一些工具,求补充——转的,先mark了
    AutoMapper(一)——实现数据契约和实体类之间的转换
    GitHub上整理的一些工具
    我最常用的7个Web在线工具
    在线团队协作工具+在线UML工具
    轻量级SaaS在线作图工具(继之前介绍后完整介绍)
    分享自己使用的在线UML画图工具
  • 原文地址:https://www.cnblogs.com/csushl/p/9386581.html
Copyright © 2011-2022 走看看