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 ...
随机推荐
- 一文教你快速读懂MQTT网关
MQTT是一种发布(publish)/订阅(subscribe)协议,MQTT协议采用发布/订阅模式,所有的物联网终端都通过TCP连接到云端,云端通过主题的方式管理各个设备关注的通讯内容,负责将设备与 ...
- boost.asio新框架的设计概念总结
1.66版本,boost.asio库重新设计了框架,目前最新版为1.71.读了几天代码后,对框架中相关概念总结.因为是泛型编程的库,所以分析的概念层的设计. 可通过boost官方文档,strand的1 ...
- MySQL 备份数据那点事
mysqldump 什么是 mysqldump ? mysqldump 是 MySQL 用于执行逻辑备份的一款工具,可以根据原始数据库对象以及表的定义和数据来生成一系列可以被执行的 SQL 语句. 通 ...
- 读取JDK API文档,并根据单词出现频率排序
1,拿到 API 文档 登录 https://docs.oracle.com/javase/8/docs/api/ , 选中特定的类,然后 copy 其中的内容, 放入 TXT 文件中 , 2,读取T ...
- vux组件的全局注册引入
安装好vux后,要引入全局组件是要在main.js中使用Vue.component引入的,不能直接使用Vue.use,不能直接使用Vue.use,不能直接使用Vue.use import router ...
- 万恶之源-python的进化
列表 列表的增删改查 3. 列列表的嵌套 元组和元组嵌套 5. range ⼀一. 列表 1.1 列表的介绍 列表是python的基础数据类型之⼀一 ,其他编程语⾔言也有类似的数据类型. 比如JS中的 ...
- C# 8.0的计划特性
虽然现在C# 7才发布不久,并且新的版本和特性还在增加中,但是C# 8.0已经为大家公开了一些未来可能出现的新特性. *注:以下特性只是计划,可能在将来的正式版本会有一些差异 1.Nullable R ...
- 安卓Android碎片fragment实现静态加载
静态加载好后的界面如下,两个碎片分别位于一个活动的左边和右边: 左边和右边分别为一个碎片,这两个碎片正好将一整个活动布满.一个活动当中可以拥有多个碎片,碎片的含义就是可以在同一个UI界面下,将这个界面 ...
- Java流程控制之(四)中断
目录 break continue return 标签 在程序设计时,循环直接的跳转显得十分重要,虽然Java没有提供goto语句去控制程序的跳转,但为了控制循环,Java提供了continue,br ...
- linuxRAID(软)
RAID是一种存储机制,英文全名为“RedundantArrays of Inexpensive Disks”,即容错廉价磁盘阵列.RAID可以通过一些技术(硬件或者软件)将多个磁盘整合起来,不仅是一 ...