【Codeforces 442B】Andrey and Problem
【链接】 我是链接,点我呀:)
【题意】
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的更多相关文章
- 【codeforces 442B】 Andrey and Problem
http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...
- 【codeforces 776D】The Door Problem
[题目链接]:http://codeforces.com/contest/776/problem/D [题意] 每个门严格由两个开关控制; 按一下开关,这个开关所控制的门都会改变状态; 问你能不能使所 ...
- codeforces 442B B. Andrey and Problem(贪心)
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 一本通1548【例 2】A Simple Problem with Integers
1548:[例 2]A Simple Problem with Integers 题目描述 这是一道模板题. 给定数列 a[1],a[2],…,a[n],你需要依次进行 q 个操作,操作有两类: 1 ...
- 【codeforces 527D】Clique Problem
[题目链接]:http://codeforces.com/contest/527/problem/D [题意] 一维线段上有n个点 每个点有坐标和权值两个域分别为xi,wi; 任意一对点(i,j) 如 ...
- 【codeforces 798C】Mike and gcd problem
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...
- 【codeforces 793C】Mice problem
[题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...
- 【codeforces 807D】Dynamic Problem Scoring
[题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...
随机推荐
- nodejs实现验证码
http://www.9958.pw/post/nodejs_lesson http://www.9958.pw/post/nodejscapp
- 通过CSS控制页面中的内容垂直居中的方法
方法一:通过行高(line-height)定位 line-height通常是用于调节一段文字的行与行之间的距离,或者说两行文字之间的距离,如果行高是500px,那么每一行中的文字距离本行的顶部就是25 ...
- matlab绘制曲线对比图
>> clear;>> x1=[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8];>> y1=[0,0.55,0.69,0.86,0.93,0. ...
- Google C++编程规范 – 第十九条 -《前置声明》
转自:http://roclinux.cn/?p=3285 本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc wu == [规范] ...
- 数组去重----es6&es5&数组对象去重
es6方法: 普通数组: 1.使用Array.from(new Set(arr)); /* * @param oldArr 带有重复项的旧数组 * @param newArr 去除重复项之后的新数组 ...
- 371 Sum of Two Integers 两整数之和
不使用运算符 + 和-,计算两整数a .b之和.示例:若 a = 1 ,b = 2,返回 3. 详见:https://leetcode.com/problems/sum-of-two-integers ...
- c# 线程浅析(代理 、Invoke、Lock)
前言:本来想根据自己的经验总结一下c#线程相关的知识点, 写之前看了一些其他人的博客,发现自己也就掌握了不到三分之一....希望通过这次的博客将自己的知识点补充一下,写出更直白的博客和初学者分享. 这 ...
- CAD控件:梦想CAD控件功能更新 清除图上的所有高亮实体
1,修正得组里面的实体,把删除实体也返回的错误 2,修正代理实体改不了颜色问题. 3,修正捕捉块插入点,有时会跑到很远的位置问题. 4.MxDrawChange类增加ToBlockRefe ...
- CSS 类名的问题
以下以数字开头的 CSS 类名不会生效: .1st{ color: red; } 一个合法的 CSS 类名必需以下面其中之一作为开头: 下划线 _ 短横线 - 字母 a-z 然后紧跟其他 _,- 数字 ...
- Unity中播放带有alpha通道格式为Mp4的视频
问题: Unity中实现播放透明的MP4视频时出现黑点 解决办法: 使用Unity自带的shader去除黑点 1:shader代码如下所示 Shader "Unlit/NewUnlit ...