HDU 6693 Valentine's Day (概率)
2019 杭电多校 10 1003
题目链接:HDU 6693
比赛链接:2019 Multi-University Training Contest 10
Problem Description
Oipotato loves his girlfriend very much. Since Valentine's Day is coming, he decides to buy some presents for her.
There are \(n\) presents in the shop, and Oipotato can choose to buy some of them. We know that his girlfriend will possibly feel extremely happy if she receives a present. Therefore, if Oipotato gives \(k\) presents to his girlfriend, she has \(k\) chances to feel extremely happy. However, Oipotato doesn't want his girlfriend to feel extremely happy too many times for the gifts.
Formally, for each present \(i\), it has a possibility of \(P_i\) to make Oipotato's girlfriend feel extremely happy. Please help Oipotato decide what to buy and maximize the possibility that his girlfriend feels extremely happy for exactly one time.
Input
There are multiple test cases. The first line of the input contains an integer \(T (1\le T\le 100)\), indicating the number of test cases. For each test case:
The first line contains an integer \(n (1\le n\le 10 000)\), indicating the number of possible presents.
The second line contains \(n\) decimals \(P_i (0\le Pi\le 1)\) with exactly six digits after the decimal point, indicating the possibility that Oipotato's girlfriend feels extremely happy when receiving present \(i\).
It is guaranteed that the sum of \(n\) in all test cases does not exceed \(450000\).
Output
For each test case output one line, indicating the answer. Your answer will be considered correct if and only if the absolute error of your answer is less than \(10^{−6}\).
Sample Input
2
3
0.100000 0.200000 0.900000
3
0.100000 0.300000 0.800000
Sample Output
0.900000000000
0.800000000000
Solution
题意
有 \(n\) 种礼物,第 \(i\) 种礼物能让女朋友开心的概率为 \(P_i\),挑一些礼物,问让女朋友开心一次的概率最大为多少。
题解
概率 贪心
如果有概率大于等于 \(0.5\) 的礼物,输出其中最大的。
否则,对概率从大到小。暴力枚举选择前 \(k\) 大的礼物的的概率,求最大值即可。
此题有原题。见 CodeForces 442B
相关证明见官方题解:Codeforces #253 editorial
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int maxn = 100000 + 5;
double p[maxn];
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n;
scanf("%d", &n);
double ans = 0, maxa = -1;
int flag = 0;
for(int i = 0; i < n; ++i) {
scanf("%lf", &p[i]);
if(p[i] >= 0.5) {
flag = 1;
if(maxa = -1) maxa = p[i];
else maxa = max(maxa, p[i]);
}
}
if(flag) {
printf("%.6lf\n", maxa);
} else {
sort(p, p + n);
double tmp1 = p[n - 1];
double tmp2 = p[n - 1] * (1 - p[n - 2]) + p[n - 2] * (1 - p[n - 1]);
ans = tmp2;
int k = 3;
while(tmp1 < tmp2 && k <= n) {
ans = tmp2;
tmp1 = tmp2;
tmp2 = 0;
for(int i = n - 1; i >= n - k; --i) {
double tmp = 1;
for(int j = n - 1; j >= n - k; --j) {
if(j == i) {
tmp *= p[j];
} else {
tmp *= 1 - p[j];
}
}
tmp2 += tmp;
}
k ++;
}
printf("%.6lf\n", max(ans, tmp2));
}
}
return 0;
}
HDU 6693 Valentine's Day (概率)的更多相关文章
- HDU 3853:LOOPS(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description Akemi Homura is a M ...
- HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2
http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...
- HDU 5781 ATM Mechine (概率DP)
ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...
- hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...
- HDU 5985 Lucky Coins(概率)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5985 题意:有多种类型的硬币,每种类型的硬币都有一定的数量,现在每次抛硬币,除去朝下的硬币,知道最后 ...
- hdu 6305 RMQ Similar Sequence——概率方面的思路+笛卡尔树
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6305 看题解,得知: 0~1内随机取实数,取到两个相同的数的概率是0,所以认为 b 序列是一个排列. 两个 ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU 4865 Peter's Hobby --概率DP
题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实 ...
- HDU 4035:Maze(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4035 Maze Special Judge Problem Description When w ...
随机推荐
- STM32 系统架构
这里所讲的 STM32 系统架构主要针对的 STM32F103 这些非互联型芯片 STM32 主系统主要由四个驱动单元和四个被动单元构成. 四个驱动单元是: 内核 DCode 总线; 系统总线;通用 ...
- HTML-参考手册: 按字母顺序排列
ylbtech-HTML-参考手册: 按字母顺序排列 1.返回顶部 1. 按字母顺序排列 New : HTML5新标签 标签 描述 <!--...--> 定义注释 <!DOCTYPE ...
- 一个普通函数的冷僻属性(length、caller、arguments、name、[[Scopes]]和[[FunctionLocation]])
https://blog.csdn.net/qq_17175013/article/details/81915059
- 2019牛客多校第六场J-Upgrading Technology(枚举+单调队列)
Upgrading Technology 题目传送门 解题思路 对于这题,我们可以枚举一个k从0~m,表示当前我们把所有技能最少升到了k级,且至少有一个为k级. 此时我们刚好获得了前k个d[]的收益, ...
- compareTo冒泡比较时间字符串
public static void main(String[] args) { List<String> dates = new ArrayList<String>(); d ...
- 转 loadrunner11 录制 chrome 浏览器
chrome不设置代理的原始状态 图1 [LoadRunner]解决LR11无法录制Chrome浏览器脚本问题 LoadRunner录制脚本时,遇到高版本的IE.FireFox,或者Chrome浏 ...
- 【题解】An Easy Problem
题目描述 给定一个正整数N,求最小的.比N大的正整数M,使得M与N的二进制表示中有相同数目的1. 举个例子,假如给定的N为78,其二进制表示为1001110,包含4个1,那么最小的比N大的并且二进制表 ...
- 装完某些软件之后IE主页被https://www.hao123.com/?tn=93453552_hao_pg劫持
今天重装电脑,装完某些软件之后发现IE主页被https://www.hao123.com/?tn=93453552_hao_pg劫持,然后百度各种解决方法都没用,甚至是修改注册表依然没啥用 最后忽然看 ...
- Spring学习笔记(7)——Bean的基本配置
先从IOC说起,这个概念其实是从我们平常new一个对象的对立面来说的,我们平常使用对象的时候,一般都是直接使用关键字类new一个对象,那这样有什么坏处呢?其实很显然的,使用new那么就 ...
- LeetCode Array Easy 88. Merge Sorted Array
Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...