NCPC 2016 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
题解:这道题是根据
概率f(k)={Ck 1 * C n p-1} / Cn+k p
而 f(k+1) = (k+1)/k * (n+k+1-p)/(n+k+1) * f(k);
一直推下去直到f(k+1)<f(k)的时候输出f(k) 的值即为最大概率;
AC代码为:
#include<iostream>
using namespace std;
int main()
{
int n,p;
while(~scanf("%d%d",&n,&p))
{
double x=p/(double)(n+1.0);
double cx=0.0;
for(int i=1;;i++)
{
if(cx<=x)
cx=x;
else
break;
x*=(i+1.0)/i*(n+i+1.0-p)/(n+i+1.0);
}
printf("%0.8lf\n",cx);
}
return 0;
}
NCPC 2016 Fleecing the Raffle的更多相关文章
- 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 ...
- CSU-2019 Fleecing the Raffle
CSU-2019 Fleecing the Raffle Description A tremendously exciting raffle is being held, with some tre ...
- Fleecing the Raffle(NCPC 2016 暴力求解)
题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...
- Game Rank(NCPC 2016 大模拟)
题目: The gaming company Sandstorm is developing an online two player game. You have been asked to imp ...
- NCPC 2016:简单题解
A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量.(N,M<1e3, Q<1e4) sol:倒着离线做,并查集即可. (在线做法:http ...
- NCPC 2016 October 8,2016 Artwork
Problem A Artwork Problem ID: artwork Time limit: 4 seconds A template for an artwork is a white gri ...
- 【倒跑并查集维护连通块】NCPC 2016 A. Artwork
http://codeforces.com/gym/101550/attachments [AC] #include<bits/stdc++.h> using namespace std; ...
- Exponial~(欧拉函数)~(发呆题)
Description Everybody loves big numbers (if you do not, you might want to stop reading at this point ...
随机推荐
- 创建python的虚拟环境
为什么需要虚拟环境?如果你现在用Django 1.10.x写了个网站,然后你的领导跟你说,之前有一个旧项目是用Django 0.9开发的,让你来维护,但是Django 1.10不再兼容Django 0 ...
- 008.Kubernetes二进制部署Nginx实现高可用
一 Nginx代理实现kube-apiserver高可用 1.1 Nginx实现高可用 基于 nginx 代理的 kube-apiserver 高可用方案. 控制节点的 kube-controller ...
- 淘宝小练习#css
* { margin: 0; padding: 0; } a { text-decoration: none; } .box { background: #f4f4f4; } /* 头部样式STAR ...
- hdu 2063 过山车 (二分图,最大匹配)
过山车Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- 022.掌握Pod-Pod升级和回滚
一 deploymentPod升级和回滚 1.1 deployment升级 若Pod是通过Deployment创建的,可以在运行时修改Deployment的Pod定义(spec.template)或镜 ...
- 【目标检测实战】目标检测实战之一--手把手教你LMDB格式数据集制作!
文章目录 1 目标检测简介 2 lmdb数据制作 2.1 VOC数据制作 2.2 lmdb文件生成 lmdb格式的数据是在使用caffe进行目标检测或分类时,使用的一种数据格式.这里我主要以目标检测为 ...
- 使用shiro做权限管理的学习笔记整理
Shiro权限管理 参考:https://www.cnblogs.com/jpfss/p/8352031.html Shiro解决的问题 授权和鉴别的问题:Authenrization(授权) Aut ...
- mysql--时区表问题(Windows环境下)
自己用Django开发个人博客是,数据库用的是mysql,期间遇到一个时间不一致的问题,具体解决过程: 1.问题原因:Windows没有时区表 2.去mysql官网下载相应版本的时区表:https:/ ...
- Win10如何快速截屏
Win10不用QQ,如何快速截屏? 年轻的时候想截图总是需要把QQ打开,但是直到我遇到了一种尴尬的场景:就是需要我把鼠标放着标签上,才会有下一步内容出现,这就很难搞. 经过查找资料,做出一些总结. 第 ...
- JavaScript笔记五
1.条件分支语句 - switch语句 - 语法: switch(条件表达式){ case 表达式: 语句... break; case 表达式: 语句... break; case 表达式: 语句. ...