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 ...
随机推荐
- [quartusⅡ] 使用quartusⅡ的过程中,遇到过的一些“软件上的问题”
1.USB blaster的驱动在设备管理器上点“更新驱动软件”,更新不了,说什么哈希值不在指定目录下,如下图, 解决方法是,https://blog.csdn.net/rdgfdd/article/ ...
- 安卓手机运行fedora
安卓手机使用容器运行其他linux,一般两种: 1. termux + rootfs.img + proot,依赖api>=21,不必root但受限. 2. linuxdeploy + proo ...
- firefox浏览器中使用vux的x-input报错TypeError: _this3.$refs.input.scrollIntoViewIfNeeded is not a function
最近做公众号项目,想着统一风格,所以决定使用vux. 在调试时发现,只要鼠标点击x-input输入框,就会报错 TypeError: _this3.$refs.input.scrollIntoView ...
- ubuntu 16.04上源码编译dlib教程 | compile dlib on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/c6ead512/,欢迎阅读! compile dlib on ubuntu 16.04 Series Part 1: compil ...
- 手把手带你一键部署 Kubernetes + KubeSphere 至 Linux
本文介绍一个最快安装 Kubernetes 和体验 KubeSphere 核心功能的方式,all-in-one 模式可一键安装 Kubernetes v1.15.5 和 KubeSphere 至一台 ...
- php中 continue break exit return 的区别
php 中的循环有 for foreache while do{} whlie这几种. 1.continue continue是用来在循环结构中,控制程序放弃本次循环continue: 之后的语句,并 ...
- 使用原生javaScript绘制带图片的二维码---js
使用链接生成二维码主要是使用qr.js或者其他,把链接转化为二维码的形式,在使用canvas时需要设置画布的尺寸,生成的颜色. <div class="qr_code"> ...
- Java Web登录界面
非常激动的开通了我的第一个博客,在这里希望大家能多多指点,相互学习. 一个简单的登录界面 首先我们先把这个登录分为三块: 一.数据库 数据库我用的是MYSQL: 二.前端 三.后台 1. 后台代码的 ...
- 用Helm3构建多层微服务
Helm是一款非常流行的k8s包管理工具.以前就一直想用它,但看到它产生的文件比k8s要复杂许多,就一直犹豫,不知道它的好处能不能抵消掉它的复杂度.但如果不用,而是用Kubectl来进行调式真的很麻烦 ...
- 【2018寒假集训 Day1】【位运算】桐桐的运输方案
桐桐的运输方案(transp) [问题描述] 桐桐有 N 件货物需要运送到目的地,它们的重量和价值分别记为: 重量:W1,W2,…,Wn: 价值:V1,V2,…,Vn: 已知某辆货车的最大载货量为 X ...