Fleecing the Raffle(NCPC 2016 暴力求解)
题目:
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 暴力求解)的更多相关文章
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- Urozero Autumn 2016. NCPC 2016
A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- 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 ...
- 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 ...
- hdu6570Wave (暴力求解)
Problem Description Avin is studying series. A series is called "wave" if the following co ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
随机推荐
- 关于Time Series Database
今天观察了下clojure之父datomic.com的数据库 有点类似sequence数据库的变种 不过这类数据库,感觉用在移动端会更有市场: 1. 移动端需要这种可以本地存储,无删除,联网只增加,只 ...
- go语言---defer
go语言---defer https://blog.csdn.net/cyk2396/article/details/78885135 defer 是在函数退出前调用,多个defer遵循 先进后出 的 ...
- 【LNOI 2014】 LCA
[题目链接] 点击打开链接 [算法] 考虑求lca(x,y)的深度 我们可以将从根到x路径上的点都打上标记,然后,询问y到根上路径的权值和 那么,求sigma(depth(lca(i,z)))(l & ...
- [Advance] How to debug a program (上)
Tool GDB Examining Memory (data or in machine instructions) You can use the command x (for “examine” ...
- P3822 [NOI2017]整数
传送门 shadowice大佬已经写的非常详细了我就不再写一遍了-- //minamoto #include<bits/stdc++.h> #define u unsigned int # ...
- Elementui tabs组件内添加组件
1. Elementui tabs组件内添加组件 1.1. 需求 今天的一个需求是在后台框架的基础上添加tab页,结果页面如下 原本上述红框内的内容是不存在的,直接点击左侧菜单栏进行页面跳转,现加了t ...
- 洛谷P5055 【模板】可持久化文艺平衡树(FHQ Treap)
题面 传送门 题解 日常敲板子.jpg //minamoto #include<bits/stdc++.h> #define R register #define inline __inl ...
- [JOI2014] 小笼包
题面 : https://www.ioi-jp.org/joi/2013/2014-yo/2014-yo-t6/2014-yo-t6.html 题解 dp + 康托展开 一看这题不知道怎么处理 只能枚 ...
- 常见Z纯CSS小样式合集(三角形)
三角形 .sanjiao{ width:0px; height: 0px; overflow: hidden; border-width: 100px; border-color: transpare ...
- 为什么字符串类型可以调用构造函数String的方法,却又不是它的实例
从所周知,在js中定义一个字符串我们有两种办法: var a = new String("a"); var a = "a"; 第一种方法使用构造函数创建,作为S ...