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的更多相关文章

  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. 大数据HDFS相关的一些运维题

    1.在 HDFS 文件系统的根目录下创建递归目录“1daoyun/file”,将附件中的BigDataSkills.txt 文件,上传到 1daoyun/file 目录中,使用相关命令查看文件系统中 ...

  2. Windows下编译最新版ChezScheme

    据说ChezScheme是最快的神级编译器,一秒钟几百万行,王垠说的2秒内编译自身绝不是夸张(看这里<揭秘Chez Scheme>,Scheme中文社区).ChezScheme由美国印第安 ...

  3. python 做一个简单的登录接口

    # -*- conding :utf-8 -*-# File Name: homewoe# Create Date: 2019/11/20 / 9:15# Change Activity: 2019/ ...

  4. 通过ESP8266调节继电器时间

    通过ESP8266调节继电器时间 1.继电器选择(可调节时间的继电器) 2.继电器与esp8266的接线[set --- D6,UP --- D5,DOWN --- D1] 3.Arduino 程序 ...

  5. stdClass Object 数据的处理

    stdClass Object 数据的处理 在调用接口的时候往往返回的是 stdClass Object 类型的数据,我们在取数据值的时候就阔以直接使用对象->属性值的方式操作值 $ret = ...

  6. 阿里云ECS服务器部署HADOOP集群(三):ZooKeeper 完全分布式集群搭建

    本篇将在阿里云ECS服务器部署HADOOP集群(一):Hadoop完全分布式集群环境搭建的基础上搭建,多添加了一个 datanode 节点 . 1 节点环境介绍: 1.1 环境介绍: 服务器:三台阿里 ...

  7. gin索引优化实例1

    GIN(Generalized Inverted Index, 通用倒排索引) 是一个存储对(key, posting list)集合的索引结构,其中key是一个键值,而posting list 是一 ...

  8. java课笔记

    http://127.0.0.1:8088/ http://127.0.0.1:8088/test/index.jsp http://127.0.0.1:8088/test/show 用户 (请求) ...

  9. ganglia 客户端部署

    #!/bin/bash #配置参数 #serverIP=192.168.1.16 #network=ens32 #关闭selinux #setenforce #sed -i 's/SELINUX=en ...

  10. Java基础面试题及答案(二)

    容器 18. java 容器都有哪些? 常用容器的图录: 19. Collection 和 Collections 有什么区别? java.util.Collection 是一个集合接口(集合类的一个 ...