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. PHP线程安全和非线程安全有什么区别

    我们先来看一段PHP官网的原话: Which version do I choose? IIS If you are using PHP as FastCGI with IIS you should ...

  2. mybatis-关联关系

    在实现实列中我们在学生表里面增加了一个地址表用于与学生表的一对一 1.创建地址实体类: package com.java1234.mappers; import com.java1234.model. ...

  3. Graylog+elasticsearch+mongodb集群+nginx负载均衡前端

    网上有张图画的很好,搜索有关它的配置文章,google里有几篇英文的,都是依靠haproxy等或别的什么实现,没有纯粹的Graylog+elasticsearch+mongodb集群,项目需要,只有自 ...

  4. Samuraiwtf-的确是很好的渗透学习平台

    有人问我要渗透测试平台学习,我想到了Samurai ,记得里面带有很多的,这里来推广一下. Samurai Web 测试框架很多人说是live CD测试环境,但是现在似乎不是了,至少目前最新版的只有这 ...

  5. [Asp.Net] Global.asax

    Global.asax.cs文件会被编译到对应的dll 但部署是还需要Global.asax文件  class Global中的方法才会在程序启动时执行

  6. 百度地图API 基础入门

    一.注册账号,获取密钥 流程-注册-登录-控制台-创建应用-获取密钥: 1.你想要调取百度地图,首先,你需要注册一个百度账号,获取密匙. 2.密钥获取以后,引入到你需要调用百度地图的界面中. 二.创建 ...

  7. 将数据库数据添加到ListView控件中

    实现效果: 知识运用: ListView控件中的Items集合的Clear方法 //从listView控件的数据项集合中移除所有数据项 补充:可以使用Remove或RemoveAt方法从集合中移除单个 ...

  8. flex在众多手机浏览器上的兼容方案(亲测华为手机自带浏览器)

    如果项目使用构建工具,可加autoprefixer来处理,[autoprefixer使用指南] 纯手写css兼容代码,需给每个使用的属性加上属性前缀 /*display: flex;写法*/ span ...

  9. PHP中可变变量到底有什么用?

    转自:http://blog.csdn.net/engine_1124/article/details/8660291 什么是可变变量? PHP提供了一种其他类型的变量——可变变量.可变变量允许我们动 ...

  10. 解决Mycat对自增表不支持(第一种已测试通过)

    表 INSERT INTO news_class (`class_id`,`class_name`) VALUES (next VALUE FOR MYCATSEQ_GLOBAL,'1'); sequ ...