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

  1. 3 2
  2. 23 5

Sample Output

  1. 0.6
  2. 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的更多相关文章

  1. Urozero Autumn 2016. NCPC 2016

    A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...

  2. Nordic Collegiate Programming Contest (NCPC) 2016

    A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...

  3. CSU-2019 Fleecing the Raffle

    CSU-2019 Fleecing the Raffle Description A tremendously exciting raffle is being held, with some tre ...

  4. Fleecing the Raffle(NCPC 2016 暴力求解)

    题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...

  5. Game Rank(NCPC 2016 大模拟)

    题目: The gaming company Sandstorm is developing an online two player game. You have been asked to imp ...

  6. NCPC 2016:简单题解

    A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量.(N,M<1e3, Q<1e4) sol:倒着离线做,并查集即可. (在线做法:http ...

  7. 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 ...

  8. 【倒跑并查集维护连通块】NCPC 2016 A. Artwork

    http://codeforces.com/gym/101550/attachments [AC] #include<bits/stdc++.h> using namespace std; ...

  9. Exponial~(欧拉函数)~(发呆题)

    Description Everybody loves big numbers (if you do not, you might want to stop reading at this point ...

随机推荐

  1. JVM原理速记复习Java虚拟机总结思维导图面试必备

    良心制作,右键另存为保存 喜欢可以点个赞哦 Java虚拟机 一.运行时数据区域 线程私有 程序计数器 记录正在执行的虚拟机字节码指令的地址(如果正在执行的是Native方法则为空),是唯一一个没有规定 ...

  2. T-SQL Part IV: ORDER BY

    ORDER BY 返回一个Cursor,并不返回结果集.而试图将Cursor作为输入将产生了错误. 所以,下列的SQL语句将产生错误: SELECT VerID, IsComplete VerID, ...

  3. 回声消除中的LMS和NLMS算法与MATLAB实现

    自适应滤波是数字信号处理的核心技术之一,在科学和工业上有着广泛的应用领域.自适应滤波技术应用广泛,包括回波抵消.自适应均衡.自适应噪声抵消和自适应波束形成.回声对消是当今通信系统中普遍存在的现象.声回 ...

  4. ESP8266 智能配网 断电重连

    ESP8266 智能配网 断电重连 #include <ESP8266WiFi.h> bool autoConfig() { WiFi.begin(); for (int i = 0; i ...

  5. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. Python3.7.1学习(三)求两个list的差集、并集与交集

    在python3.7.1对列表的处理中,会经常使用到Python求两个list的差集.交集与并集的方法. 下面就以实例形式对此加以分析. # 求两个list的差集.并集与交集# 一.两个list差集# ...

  7. mysql基础之约束

    约束的目的: 1.约束保证数据的完整性和一致性. 2.约束分为表级约束 和 列级 约束.(针对约束字段的数目的多少来确定的) 3.约束类型包括 not null (非空约束) primary key( ...

  8. jsp页面使用EL表达式 使用Jstl标签库中的标签,需要引入jstl.jar和standard.jar

    spring boot 中使用jstl 首先在pom中加入 <dependency> <groupId>jstl</groupId> <artifactId& ...

  9. Java虚拟机详解(十)------类加载过程

    在上一篇文章中,我们详细的介绍了Java类文件结构,那么这些Class文件是如何被加载到内存,由虚拟机来直接使用的呢?这就是本篇博客将要介绍的——类加载过程. 1.类的生命周期 类从被加载到虚拟机内存 ...

  10. GentOS 7 安装步骤

    附上原作者的博客网址: https://blog.csdn.net/qq_42570879/article/details/82853708 1.CentOS下载CentOS是免费版,推荐在官网上直接 ...