Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
来源:互联网 发布:h5登陆界面源码 编辑:程序博客网 时间:2024/05/16 01:46
题意:
就是小a要他的n个朋友为比赛出题。他的朋友能出题的概率已知,小a仅需要一个题,
如果一个题都出不了或者出了一道题以上他都会upset,他可以找他的一些朋友出题,
问他不会感到upset的最大概率。
算法:
贪心咯。。这种数学题我做的很少额。。。基本见到什么概率啊什么的就蒙了- -
幸好有提示,如果选2个人出题,a和b,他不upset的概率就是pa*(1-pb)+pb*(1-pa)。
而当只有一个人出题时,总是那个概率最大的人使得小a不upset的概率最大。
这样就可以将概率从大到小排序,然后枚举1-n个人出题,看只出出一个题的概率,比较得到最大值。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;double f[110];bool cmp(double x,double y){ return x>y;}int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) scanf("%lf",&f[i]); sort(f,f+n,cmp); double ans = 0; for(int i=1;i<=n;i++) { double sum = 0,tmp; for(int j=0;j<i;j++) { tmp = f[j]; for(int k=0;k<i;k++) { if(j!=k) tmp*=(1-f[k]); } sum+=tmp; } ans = max(sum,ans); } printf("%.12lf\n",ans); } return 0;}
0 0
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
- CodeForces 443D - Andrey and Problem(贪心)
- [Codeforces442B]Andrey and Problem(贪心+概率)
- codeforces#253 D - Andrey and Problem
- Codeforces 443D Andrey and Problem【排序+概率dp】
- codeforces 442 B. Andrey and Problem (概率与期望+贪心)
- Codeforces 442B Andrey and Problem(贪心)
- codeforces#253 D - Andrey and Problem里的数学知识
- codeforces 443D Andrey and Problem
- Codeforces 443D Andrey and Problem
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心
- Codeforces Round #394 (Div. 2)D. Dasha and Very Difficult Problem【贪心】
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心,二分
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem —— 贪心
- Codeforces Round #296 (Div. 2) - D. Clique Problem(贪心)
- Codeforces Round #374 (Div. 2)D. Maxim and Array(贪心)
- Codeforces Round 374 (Div 2)D Maxim and Array 【贪心】
- PLSQL Developer工具的使用
- C语言数据结构之线性表(续)
- CSS编写指导规范和建议
- Android 最火的快速开发框架XUtils
- 阿里巴巴集团2014秋季校园招聘笔试题
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Gloox 注册用户
- sed总结
- Android 最火快速开发框架AndroidAnnotations简介
- java RC4加密解密
- 【Linux】lvm基础操作
- UVa 11461 - Square Numbers (水题)
- TCP滑动窗口协议
- linux 驱动-----字符设备驱动的组成