codeforces 442B B. Andrey and Problem(贪心)
题目链接:
2 seconds
256 megabytes
standard input
standard output
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.
Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi(0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.
Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.
4
0.1 0.2 0.3 0.8
0.800000000000
2
0.1 0.2
0.260000000000 题意: 给出n个人想出问题的概率,现在问选哪些人才能使正好想出一个问题的概率最大; 思路: 贪心,ans表示当前选一个得到的最大的概率,pre表示什么都不选的概率.然后判断当前这个如果加进来来会不会使ans变大,否则就不选; AC代码:
#include <bits/stdc++.h>
using namespace std; int n;
double a[110];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lf",&a[i]);
sort(a+1,a+n+1);
double ans=a[n],pre=1-a[n];
for(int i=n-1;i>0;i--)
{
if(ans*(1-a[i])+a[i]*pre>=ans)
{
ans=ans*(1-a[i])+a[i]*pre;
pre=pre*(1-a[i]);
}
}
printf("%.12f",ans);
return 0;
}
codeforces 442B B. Andrey and Problem(贪心)的更多相关文章
- 【codeforces 442B】 Andrey and Problem
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...
- 【Codeforces 442B】Andrey and Problem
[链接] 我是链接,点我呀:) [题意] n个朋友 第i个朋友帮你的概率是pi 现在问你恰好有一个朋友帮你的概率最大是多少 前提是你可以选择只问其中的某些朋友不用全问. [题解] 主要思路是逆向思维, ...
- codeforces#253 D - Andrey and Problem里的数学知识
这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...
- Codeforces 798C - Mike and gcd problem(贪心+数论)
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1, ...
- Codeforces 442B Andrey and Problem(贪婪)
题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够 ...
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- cf442B Andrey and Problem
B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 442B
题目链接 B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
随机推荐
- Java中处理异常中return关键字
Java中,执行try-catch-finally语句需要注意: 第一:return语句并不是函数的最终出口,如果有finally语句,这在return之后还会执行finally(return的值会暂 ...
- 【GOF23设计模式】代理模式
来源:http://www.bjsxt.com/ 一.[GOF23设计模式]_代理模式.静态代理 package com.test.proxy.staticProxy; public interfac ...
- Vue数据绑定
gitHub地址:https://github.com/lily1010/vue_learn/tree/master/lesson04 一 双括号用来数据绑定 (1)写法一: {{message}}, ...
- JS 节流
作为前端的小白,在做项目的过程中,一般只考虑到实现功能,并没有考虑到性能的问题. 比如说,下拉加载更多的这个功能和resize()是特别耗费性能的.此时就要想到节流了. 节流:就是然一个函数无法在短时 ...
- RGui的http代理设置
办公电脑环境需要http代理访问大网,使用R语言安装包时老是无法连接网络,后来从网上发现解决方法很简单,只需在启动RGui.exe的命令行上加上启动参数就可以了. "C:\Program F ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q66-Q69)
Question 66You have a custom theme named MyTheme. The theme is defined in a file named MyTheme.thmx. ...
- C安全编码--预处理
建议和规则 建议: 用内联函数或静态函数代替与函数相似的宏 在宏参数名两边加上括号 宏替换列表应该加上括号 应该使用typedef定义编码类型 不要复用标准头文件名 理解连接标记或执行字符串化时的宏替 ...
- ios 计算缓存大小
- (void)getSize2 { // 图片缓存 NSUInteger size = [SDImageCache sharedImageCache].getSize; // NSLog(@&qu ...
- iOS之通过PaintCode快速实现交互动画的最方便方法 未解问题
需求: 问题: 源码百度云下载链接: http://pan.baidu.com/s/1o7r4hCm 密码: 8atd 其他学习链接:http://www.jianshu.com/p/90d6cd35 ...
- C语言错误之--初始值(低级错误)
今天犯了一个低级错误,虽然低级,但是也不能忽视,一个低级错误以后可能小则浪费时间和精力,大则酿成整个app的项目bug.