Codeforces 442B
B. Andrey and Problemtime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputPrint 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.
Sample test(s)Input4
0.1 0.2 0.3 0.8Output0.800000000000Input2
0.1 0.2Output0.260000000000NoteIn 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 is 0.1·0.8 + 0.9·0.2 = 0.26.
Accepted Code:
/*************************************************************************
> File Name: 442B.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年06月23日 星期一 14时19分19秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define eps 1e-9
int n;
double p[]; double cal(int x) {
double result = 0.0;
for (int i = x; i < n; i++) {
double tmp = p[i];
for (int j = x; j < n; j++) {
if (i == j) continue;
tmp *= (1.0 - p[j]);
}
result += tmp;
}
return result;
} int
main(void) {
while (~scanf("%d", &n) && n) {
for (int i = ; i < n; i++) scanf("%lf", p+i);
sort(p, p + n);
double ans = p[n-];
for (int i = n-; i >= ; i--) {
double tmp = cal(i);
if (tmp - ans < eps) break;
ans = tmp;
}
printf("%.17f\n", ans);
} return ;
}
Codeforces 442B的更多相关文章
- Codeforces 442B Andrey and Problem(贪婪)
题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够 ...
- 【codeforces 442B】 Andrey and Problem
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...
- codeforces 442B B. Andrey and Problem(贪心)
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 【Codeforces 442B】Andrey and Problem
[链接] 我是链接,点我呀:) [题意] n个朋友 第i个朋友帮你的概率是pi 现在问你恰好有一个朋友帮你的概率最大是多少 前提是你可以选择只问其中的某些朋友不用全问. [题解] 主要思路是逆向思维, ...
- Codeforces 442B. Andrey and Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- HDU 6693 Valentine's Day (概率)
2019 杭电多校 10 1003 题目链接:HDU 6693 比赛链接:2019 Multi-University Training Contest 10 Problem Description O ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- xlwt/xlwt/Style.py excel样式源文件
from __future__ import print_function # -*- coding: windows-1252 -*- from . import Formatting from . ...
- 【HAOI2015】树上染色—树形dp
[HAOI2015]树上染色 [题目描述]有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并将其他的N-K个点染成白色.将所有点染色后,你会获得 ...
- 由于没有公钥,无法验证下列签名 ppa
出现以上错误提示时,只要把后八位拷贝一下来,并在[终端]里输入以下命令并加上这八位数字回车即可! sudo apt-key adv --recv-keys --keyserver keyserver. ...
- linux管道和tee命令
ps -ef | grep docker 等价于 ps -ef &> >(grep docker) cat a.log | tee b.txt 等价于 cat a.log & ...
- IDEA快速定位错误快捷键
- HttpComponents了解
原文地址:http://blog.csdn.net/jdluojing/article/details/7300428 1 简介 超文本传输协议(http)是目前互联网上极其普遍的传输协议,它为构建功 ...
- Math concepts / 数学概念
链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...
- Django项目:CRM(客户关系管理系统)--33--25PerfectCRM实现King_admin添加出错修复
{#table_change.html#} {## ————————19PerfectCRM实现King_admin数据修改————————#} {#{% extends "king_mas ...
- LUOGU P1779 魔鬼杀手_NOI导刊2010提高(03)
传送门 解题思路 背包,首先先用aoe都打残然后单伤补刀,用f[i]表示AOE打了i的伤害的最小花费,g[i]表示单伤打了i的伤害的最小花费. 代码 #include<iostream> ...
- leyou_01_环境搭建
1.乐优商城项目搭建 前端技术: 基础的HTML.CSS.JavaScript(基于ES6标准) JQuery Vue.js 2.0以及基于Vue的框架:Vuetify 前端构建工具:WebPack ...