题目:

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:

The input consists of a single line containing two integers n and p (2 ≤ 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.

题意:

有n个人,p个获奖名额。游戏规则为每个人往一个盒子中放一张带有自己名字的纸条,然后一次性从中拿出p张这条,这p个就是获奖的人。小明想往里边多放一些带有自己名字的纸条来提高自己中奖的概率,被发现作弊的情况为,抽出的p张纸条中有两条写着“小明”。问在不被发现的情况下,小明通过作弊最高的获奖率为多少。

思路:

嗯,,,,,,在队友的启发下,跟高中数学老师把概率这块的知识要回来后,终于自己推出了公式如下图(字丑不要喷啊):

图中圈出来的两部分的项是相等的。所以枚举a直接上暴力大法就可以了。写完交题,结果TLE,然后在取最大值之前输出了一下答案,发现到达最大后后边的值都是相等的就没有必要计算了,直接break就ok了。

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string.h>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <map>
#include <malloc.h>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + ;
typedef long long ll;
double m, p; int main() {
cin >> m >> p;
double ans = 1.0, sum = 0.0;
for(double k = ; k <= m; k++) {
ans = 1.0;
ans = ans*(k/(m+k));
for(double i = ; i < p-; i++) {
ans *= (m - i);
ans /= (m - i + k - );
}
if(ans > sum)
sum = ans;
else
break;
}
sum = sum*p;
cout << setprecision() << sum << endl;
return ;
}
/*
样例输入:
3 2
23 5
样例输出:
0.6
0.45049857550
*/

Fleecing the Raffle(NCPC 2016 暴力求解)的更多相关文章

  1. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  2. Urozero Autumn 2016. NCPC 2016

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

  3. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  4. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  5. Nordic Collegiate Programming Contest (NCPC) 2016

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

  6. CSU-2019 Fleecing the Raffle

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

  7. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  8. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  9. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

随机推荐

  1. HTTP要点概述:六,HTTP报文

    一,HTTP报文: 用于HTTP交互的信息称为HTTP报文.请求端(客户端)的HTTP报文叫做请求报文,响应端(服务器)的叫做响应报文.HTTP报文本身是由多行(用CR+LF换行)数据构成的字符串文本 ...

  2. Bootstrap Tooltip源码分析

    /* ======================================================================== * Bootstrap: tooltip.js ...

  3. 关于移动平台的viewport

    viewport是用来设置移动平台上的网页宽度,写device-width比较好,不然会和设备上不一样 在使用device-width之后,图片资源最好使用百分比布局,进行自动缩放. 文字大小是一样的 ...

  4. ViewPager嵌套ViewPager后子ViewPager滑动不正常问题

    ViewPager嵌套ViewPager后,滑动事件没法在子ViewPager里面响应. 解决办法是自定义子ViewPager. 以下代码是转载的,经本人测试,可以用!!! 转载地址:http://b ...

  5. obs nginx-rtmp-module搭建流媒体服务器实现直播 ding

    接下来我就简单跟大家介绍一下利用nginx来搭建流媒体服务器. 我选择的是腾讯云服务器 1.下载nginx-rtmp-module: nginx-rtmp-module的官方github地址:http ...

  6. Hadoop MapReduce 运行步骤

    步骤:[使用java编译程序,生成.class文件] [将.class文件打包为jar包] [运行jar包(需要启动Hadoop)] [查看结果] 具体实现:1.添加程序所需要的依赖vim ~/.ba ...

  7. jquery中$()的使用

    在jquery中最常使用的就是$这个符号了,在我没有系统的学习jquery之前,我用到的$都是用于对元素的选择,而这只是$的很简单的用法.在jquery$()函数一共有三种用法: $(selector ...

  8. E20171225-hm

    abstract  adj. 抽象的,理论上的; 难解的; 抽象派的; 茫然的;

  9. codeforces 402E - Strictly Positive Matrix【tarjan】

    首先认识一下01邻接矩阵k次幂的意义:经过k条边(x,y)之间的路径条数 所以可以把矩阵当成邻接矩阵,全是>0的话意味着两两之间都能相连,也就是整个都要在一个强连通分量里,所以直接tarjan染 ...

  10. Unity项目 - Boids集群模拟算法

    1987年Craig W.Reynolds发表一篇名为<鸟群.牧群.鱼群:分布式行为模式>的论文,描述了一种非常简单的.以面向对象思维模拟群体类行为的方法,称之为 Boids ,Boids ...