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 ...
随机推荐
- PHP declare 之 strict_types=1
PHP中申明 declare(strict_types=1)的作用: strict_types=1 及开启严格模式.默认是弱类型校验.具体严格模式和普通模式的区别见下面代码. code1: < ...
- (视频分辨率介绍)混淆的概念:SIF与CIF、4CIF与D1
http://www.microjie.com/index.php/professional-knowledge/82-standards-parterns/26-profession-knowled ...
- SpringData初探
前言 项目中用到这个,没有学过,手动搭建,测试执行流程, 理论的东西有时间再补充 Maven依赖 <?xml version="1.0" encoding="UTF ...
- IO流13 --- 转换流实现文件复制 --- 技术搬运工(尚硅谷)
InputStreamReader 将字节输入流转换为字符输入流 OutputStreamWriter 将字符输出流转换为字节输出流 @Test public void test2() { //转换流 ...
- 交叉熵-loss-理解
参考链接: https://blog.csdn.net/tsyccnh/article/details/79163834
- 通过BlukLoad的方式快速导入海量数据
http://www.cnblogs.com/MOBIN/p/5559575.html 摘要 加载数据到HBase的方式有多种,通过HBase API导入或命令行导入或使用第三方(如sqoop)来导入 ...
- python在WIN下CMD运行中文乱码及python 2.x python 3.x编码问题
在CMD中运行python代码时,我们会发现,即使在代码中加入# -*- coding:utf-8 -*- 这段代码,中文仍然会乱码.如下: # -*- coding:utf-8 -*- conten ...
- Leetcode82. Remove Duplicates from Sorted List II删除排序链表中的重复元素2
给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 示例 1: 输入: 1->2->3->3->4->4->5 输出: 1-&g ...
- Composer项目安装依赖包
说明:一般用Composer的项目中,目录下都有一个composer.json文件,安装这些依赖,只需要输入命令即可 步骤: cmd进入项目目录,运行命令即可 composer install 文章参 ...
- 2016中国人工智能企业TOP100, CBinsight2016年100家人工智能公司
2016中国人工智能企业TOP100 不论在学界还是业界,均有代表人物对人工智能表示了担忧,如史蒂芬·霍金和比尔·盖茨.尽管如此,国内外科技巨头都积极发力人工智能,一波波创业者也相继涌入.人工智能成为 ...