zoukankan      html  css  js  c++  java
  • CSU-2019 Fleecing the Raffle

    CSU-2019 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 ( 2≤p≤n≤1062≤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
    

    题解

    题意:抽奖活动,可以放入任意张有自己名字的纸片参与抽奖,当且仅当带有自己名字的纸片被抽取两次时会被抓住,视作失败。共抽取p件奖品,参与抽奖的有n个人,问自己最大获奖概率是多少

    设x为放入的自己名字的纸片个数,则放入x张获奖概率为

    [frac{C_x^1Cn^{p-1}}{C_{n+x}^p}=frac{x imes p}{n+1}prod_{i=2}^xfrac{n-p+i}{n+i} ]

    当从x-1到x,概率乘以(frac{x}{x - 1} imesfrac{n-p+x}{n+x}),递推求概率,当概率开始变小时终止循环,输出答案

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
    	int n, p;
    	while (scanf("%d%d", &n, &p) != EOF) {
    		double now = (double)p / (double)(n + 1.0);
    		double ans = 0.0;
    		int x = 2;
    		while (1) {
    			if (ans > now) break;
    			else ans = now;
    			now *= (double)x / (double)(x - 1.0) * (double)(n + x - p) / (double)(n + x);
    			x++;
    		}
    		printf("%.11lf", ans);
    	}
    }
    /**********************************************************************
    	Problem: 2019
    	User: Artoriax
    	Language: C++
    	Result: AC
    	Time:28 ms
    	Memory:2024 kb
    **********************************************************************/
    
    
  • 相关阅读:
    移动桌面文件
    软件项目经理素质能力的必备要求
    如何管理时间
    《明日歌》
    浏览网页出现iexplore.exe应用程序错误为:"0x03e620b0"指令引用的"0x00000000"内存.该内存不能为"read"?
    css网站布局学习笔记
    因为爱,人生除了理智,还有情感!
    35岁之前成功的12条黄金法则
    VS2005中没有DataGrid控件的解决方案
    先装VS2005再装IIS,出现访问IIS元数据库失败解决方案
  • 原文地址:https://www.cnblogs.com/artoriax/p/10351654.html
Copyright © 2011-2022 走看看