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条路可以修,修每条路要一定的金币,现在这个国家只 ...
随机推荐
- System Center Configuration Manager 2016 域准备篇(Part3)
步骤2.将CM16加入域 注意:在ConfigMgr服务器(CM16 )上以本地管理员身份执行以下操作 手动加入域,请登录CM16.启动Windows文件资源管理器 右键单击This-PC,然后选择 ...
- 使用tooltip显示jquery.validate.unobtrusive验证信息
通过重写CSS实现使用tooltip显示jquery.validate.unobtrusive验证信息,效果如图: 1. 在ViewModel中定义验证规则 [Display(Name = " ...
- ASP.NET的三种开发模式
前言 ASP.NET 是一个免费的Web开发框架,是由微软在.NET Framework框架中所提供的,或者说ASP.NET是开发Web应用程序的类库,封装在System.Web.dll 文件中.AS ...
- oc语言基础整理
objc.h---------------- typedef struct objc_class *Class; struct objc_object { Class isa OBJC_ISA_AV ...
- 2018.6.27 Ajax实现异步刷新
Servlet获取URL地址.在HttpServletRequest类里,有以下六个取URL的函数: getContextPath 取得项目名 getServletPath 取得Servlet名 ge ...
- python_9_for
#1 for i in range(10):#默认从0开始,步长为1 print("loop",i) #2 for i in range(0,10,1):#步长为1 print(& ...
- java web用户登录界面
做这次实验,主要用到了mysql java web 的 内容 实验代码: IUserDao.java package com.jaovo.msg.dao; import java.util.List ...
- 51nod——2478 小b接水(预处理 思维)
我本来想把每个谷都处理了,想了下觉得不好办.后来看其他人写的是处理每个位置,把每个位置可以接的水累加起来.整挺好. #include <bits/stdc++.h> using names ...
- 关于html标签的两种隐藏方式
做一个文章管理模块 有一个功能是需要根据文章分类来显示内容的标签 刚开始以为很简单 ,手放键盘上就是一顿敲. 如果类型是文章就是没问题 可是另外几种就有问题了 红框的标签一直不出来 后来找了半天然来 ...
- 自动化测试 ubuntu多设备连接不识别
环境: ubuntu系统 usb2.0 16个口集线器 遇到问题: 连接手机到第11台设备时出现adb devices不显示的现象导致无法通过adb操作 问题排除思路; 1.通过dmesg查看设备连接 ...