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张获奖概率为
\]
当从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的更多相关文章
- Fleecing the Raffle(NCPC 2016 暴力求解)
题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...
- NCPC 2016 Fleecing the Raffle
Description A tremendously exciting raffle is being held, with some tremendously exciting prizes bei ...
- Urozero Autumn 2016. NCPC 2016
A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...
- Nordic Collegiate Programming Contest (NCPC) 2016
A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...
- 2019年台积电进军AR芯片,将用于下一代iPhone
近日,有报道表示台积电10nm 芯片可怜的收益率可能会对 2017 年多款高端移动设备的推出产生较大的影响,其中自然包括下一代 iPhone 和 iPad 机型.不过,台积电正式驳斥了这一说法,表明1 ...
- csu 1812: 三角形和矩形 凸包
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
- CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...
- CSU 1120 病毒(DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...
- CSU 1116 Kingdoms(枚举最小生成树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...
随机推荐
- 飞塔Web应用防火墙-FortiWeb
飞塔Web应用防火墙-FortiWeb 平台: fortiweb 类型: 虚拟机镜像 软件包: linux basic software Fortinet security SSL offloadin ...
- Winform调整DEV控件高度
- cms-帖子静态化
实现帖子静态化和实现友情链接静态化一致, 1.首先建立帖子类别的实体类: package com.open1111.entity; /** * 帖子类别实体 * @author user * */pu ...
- bit Byte KB MB GB TB 单位换算
1TB = 1024G 1G = 1024M 1M = 1024K 1K = 1024 byte 1 byte = 8 bit
- [Rodbourn's Blog]How to export Excel plots to a vector image (EPS, EMF, SVG, etc.)
This is a bit of a workaround, but it's the only way I know of to export an Excel plot into a vector ...
- servlet层调用biz业务层出现浏览器 500错误,解决方法 dao数据访问层 数据库Util工具类都可能出错 通过新建一个测试类复制代码逐步测试查找出最终出错原因
package com.swift.jztk.servlet; import java.io.IOException; import javax.servlet.ServletException; i ...
- GVIM——简直美如画,有没有!
"========================================== " Author: wklken " Version: 9.1 " Em ...
- 三十一、MySQL 及 SQL 注入
MySQL 及 SQL 注入 如果您通过网页获取用户输入的数据并将其插入一个MySQL数据库,那么就有可能发生SQL注入安全的问题. 本章节将为大家介绍如何防止SQL注入,并通过脚本来过滤SQL中注入 ...
- 麦子学院python开发全套完整无加密课程
点击了解更多Python课程>>> 麦子学院python开发全套完整无加密课程 第一阶段:Python基础准备 1.Web前端开发之HTML+CSS基础入门 2.Javascript ...
- 卸载Redhat 7自带的yum,安装并使用网易163源
由于redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,安装CentOS yum工具,再配置其他源,以下为详细过程:删除redhat原有的yum ...