【链接】 我是链接,点我呀:)

【题意】

n个朋友
第i个朋友帮你的概率是pi
现在问你恰好有一个朋友帮你的概率最大是多少
前提是你可以选择只问其中的某些朋友不用全问.

【题解】

主要思路是逆向思维,转换成一个一个地加上去
然后看看概率的改变值在何时为正数,显然只有为正数的时候才能加
然后概率大的和概率小的,哪一个加上去会比较优一点,也比较一下.
但是因为加上去之后S也会变化,所以只知道概率大的加上去比较优还不够.
可以再看看下面那个反证法.
它指出为何一定是选择末尾最大的若干个(也即优先选择p[i]最大的)
(反证的思想就是,假设i

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)100;
static class Task{
int n;
double p[];
double P=1,S,ans; public void solve(InputReader in,PrintWriter out) {
p = new double[N+10];
n = in.nextInt();
for (int i = 1;i <= n;i++) p[i] = in.nextDouble();
Arrays.sort(p, 1,1+n);
if (Math.abs(p[n]-1)<(1e-9)) {
out.println(1);
return;
}
for (int i = n;i >= 1;i--) {
if (S<1) {
P = P*(1-p[i]);
S = S + p[i]/(1-p[i]);
ans = P*S;
}
}
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public double nextDouble() {
return Double.parseDouble(next());
}
}
}

【Codeforces 442B】Andrey and Problem的更多相关文章

  1. 【codeforces 442B】 Andrey and Problem

    http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...

  2. 【codeforces 776D】The Door Problem

    [题目链接]:http://codeforces.com/contest/776/problem/D [题意] 每个门严格由两个开关控制; 按一下开关,这个开关所控制的门都会改变状态; 问你能不能使所 ...

  3. codeforces 442B B. Andrey and Problem(贪心)

    题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 一本通1548【例 2】A Simple Problem with Integers

    1548:[例 2]A Simple Problem with Integers 题目描述 这是一道模板题. 给定数列 a[1],a[2],…,a[n],你需要依次进行 q 个操作,操作有两类: 1 ...

  6. 【codeforces 527D】Clique Problem

    [题目链接]:http://codeforces.com/contest/527/problem/D [题意] 一维线段上有n个点 每个点有坐标和权值两个域分别为xi,wi; 任意一对点(i,j) 如 ...

  7. 【codeforces 798C】Mike and gcd problem

    [题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...

  8. 【codeforces 793C】Mice problem

    [题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...

  9. 【codeforces 807D】Dynamic Problem Scoring

    [题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...

随机推荐

  1. javascript DOM基本操作

    javascript DOM基本操作 1.DOM(Document Object Model 文档对象模型) 2.节点: 文档节点:document 元素节点:html.head.body.title ...

  2. Git简介(转载)

    转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137396284551 ...

  3. Flask-SQLAlchemy - 不使用外键连表查询。记得常回来看我

    前言 相比于 Django 的 ORM ,SQLAlchemy "不依靠外键进行跨表联查" 的解决方案就比较多. 没啥好说的,只能怪自己学艺不精..  _(:з」∠)_ 解决办法 ...

  4. 自动生成 html5 小页面

    StringBuilder htmltext = new StringBuilder();            try            {                //var readP ...

  5. 232 Implement Queue using Stacks 用栈来实现队列

    使用栈来实现队列的如下操作: push(x) -- 将一个元素放入队列的尾部.pop() -- 从队列首部移除元素.peek() -- 返回队列首部的元素.empty() -- 返回队列是否为空.注意 ...

  6. Kerberos 简介——教你做个好人

    文章导读: 对称加密 非对称加密 数字证书 Kerberos认证流程 Hadoop生态利用Kerberos认证机制来识别可靠的服务和节点,保障Hadoop集群的安全,那么Kerberos到底是什么?为 ...

  7. 中国移动Lumia机强制升级Windows10手机开发者预览版的方法

    [最新消息4-9]微软已经确定将于PST太平洋标准时间周五上午十点也就是北京时间本周六(4-11)凌晨一点推送更新Windows10手机预览版 但是推送更新的机型不包括Lumia Icon 和930 ...

  8. 用Martini、websocket实现单机版聊天室

    ChatRoom A stand-alone ChatRoom in Martini Please Star https://github.com/renleimlj/ChatRoom Interfa ...

  9. Django--4、认证系统

    cookie与session 概念 因http协议无法保存状态,但是又需要保存状态,所以有了cookie.它不属于http协议范畴 工作原理:相当于一段标识数据.在访问服务器产生标识内容(cookie ...

  10. JS求斐波那契数列的N项

    第一种求法: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF- ...