Andrey and Problem
来源:互联网 发布:linux oracle sqlplus 编辑:程序博客网 时间:2024/05/21 14:44
Description
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.
Input
The first line contains a single integer n(1 ≤ n ≤ 100) — the number of Andrey's friends. The second line containsn 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.
Output
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 most10 - 9.
Sample Input
40.1 0.2 0.3 0.8
0.800000000000
20.1 0.2
0.260000000000
Sample Output
Hint
In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.
In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is0.1·0.8 + 0.9·0.2 = 0.26.
#include<stdio.h>#include<string.h>#include<queue>#include<stack>#define lson l,m,rt <<1#define rson m+1,r,rt << 1 | 1#include<algorithm>using namespace std;bool cmp(double a,double b){ return a>b;}double a[105];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0; i<n; i++) scanf("%lf",&a[i]); sort(a,a+n,cmp); double mm=0,sum; for(int i=1; i<=n; i++) { sum=0; for(int j=0; j<i; j++) { double x=a[j]; for(int k=0; k<i; k++) { if(j!=k) x*=1-a[k]; } sum+=x; } if(sum>mm) mm=sum; } printf("%.12lf\n",mm); }}
- cf442B Andrey and Problem
- Andrey and Problem
- CodeforcesRound#253(Div2) D Andrey and Problem
- Codeforces 442B Andrey and Problem(贪心)
- codeforces#253 D - Andrey and Problem
- codeforces 443D Andrey and Problem
- [Codeforces442B]Andrey and Problem(贪心+概率)
- Codeforces 443D Andrey and Problem
- codeforces#253 D - Andrey and Problem里的数学知识
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
- 606第三周周三赛 E - Andrey and Problem
- CodeForces 443D - Andrey and Problem(贪心)
- Codeforces 443D Andrey and Problem【排序+概率dp】
- CF 443D. Andrey and Problem 贪心 or DP
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- codeforces 442 B. Andrey and Problem (概率与期望+贪心)
- Contestant and Gladiator problem
- Monkey and Banana Problem
- 内存分配:栈内存 堆内存
- 【php】注册系统和使用Xajax即时验证用户名是否被占用
- 解决本机不能访问虚拟机web服务器网站的问题
- duilib底层机制剖析:窗体类与窗体句柄的关联
- 简单工厂 vs 工厂方法
- Andrey and Problem
- UVA 10369(求第K长的边,kruskal算法模板)
- ECshop彻底去版权(同时适用于2.7.3) 前台部分: 1:去掉头部TITLE部分的ECSHOP演示站 Powered by ecshop 前者”ECSHOP演示站
- 第16周上机实践项目2--有相同数字?
- 数据结构(c++)魔术师发牌问题
- JAVA注解
- 关于MySQL数据库设计的几点优化措施
- WampServer配置
- linux cpu 信息分析