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\times p}{n+1}\prod_{i=2}^x\frac{n-p+i}{n+i}
\]

当从x-1到x,概率乘以\(\frac{x}{x - 1}\times\frac{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
**********************************************************************/

CSU-2019 Fleecing the Raffle的更多相关文章

  1. Fleecing the Raffle(NCPC 2016 暴力求解)

    题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...

  2. NCPC 2016 Fleecing the Raffle

    Description A tremendously exciting raffle is being held, with some tremendously exciting prizes bei ...

  3. Urozero Autumn 2016. NCPC 2016

    A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...

  4. Nordic Collegiate Programming Contest (NCPC) 2016

    A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...

  5. 2019年台积电进军AR芯片,将用于下一代iPhone

    近日,有报道表示台积电10nm 芯片可怜的收益率可能会对 2017 年多款高端移动设备的推出产生较大的影响,其中自然包括下一代 iPhone 和 iPad 机型.不过,台积电正式驳斥了这一说法,表明1 ...

  6. csu 1812: 三角形和矩形 凸包

    传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...

  7. CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...

  8. CSU 1120 病毒(DP)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...

  9. CSU 1116 Kingdoms(枚举最小生成树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...

随机推荐

  1. A011 Activiti工作流程开发的一些统一规则和实现原理(完整版)

    注意:以下规则是我为了规范流程的处理过程,不是Activiti公司的官方规定. 1.流程启动需要设置启动者,在Demo程序中,“启动者变量”名统一设置为initUserId 启动时要做的: ident ...

  2. Vultr VPS建站攻略 – 一键安装LNMP无面板高性能WEB环境

    在"Vultr VPS建站攻略 - 一键安装宝塔面板架设LNMP/LAMP Web环境"文章中,VULTR中文网分享到我们常用的可视化面板宝塔面板安装在VULTR VPS主机中建站 ...

  3. java Vamei快速教程08 继承

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 继承(inheritance)是面向对象的重要概念.继承是除组合(composit ...

  4. linux 命令——ls

    一.  ls命令 ls 命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文 件及文件夹清单. 通过ls 命 ...

  5. 2018.5.23 创建用户并授权&&&序列

    作业一 视图的创建 1.分页查询2-3范围之间的数据,并用视图(view_student_page)保存. create view view_student_page as select * from ...

  6. 私人定制,十款最佳Node.js MVC框架

    Node.js是JavaScript中最为流行的框架之一,易于创建可扩展的Web应用.本文分享十款最佳的JavaScript框架. Node.js是JavaScript中最为流行的框架之一,易于创建可 ...

  7. Load事件中控件Focus()无效解决办法

    原因:Load窗体时,窗体未显示 解决:1.Focus()之前添加this.Show(); 2.在Shown事件中添加Focus()

  8. leetcode笔记(一)309. Best Time to Buy and Sell Stock with Cooldown

    题目描述 (原题目链接) Say you have an array for which the ith element is the price of a given stock on day i. ...

  9. pycharm 语言配置

    在pycharm 安装所在位置找到 lib 文件夹 打开后找到 rescources_**.jar 文件 **为语言类型,英语为en 中文为cn, 用相应语言文件替换,便可变成相应语言 https:/ ...

  10. 异步解决方案----Promise与Await

    前言 异步编程模式在前端开发过程中,显得越来越重要.从最开始的XHR到封装后的Ajax都在试图解决异步编程过程中的问题.随着ES6新标准的到来,处理异步数据流又有了新的方案.我们都知道,在传统的aja ...