Codeforces 442B Andrey and Problem(贪婪)
题目链接:Codeforces 442B Andrey and Problem
题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友。每一个朋友想出题目的概率为pi,可是他能够同一时候向多个人寻求帮助。只是他仅仅能要一道题,也就是假设他向两个人寻求帮助,假设两个人都成功出题,也是不能够的。
解题思路:贪心,从概率最大的人開始考虑。假设询问他使得概率变大,则要询问。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 105;
const double eps = 1e-9;
int n, c, rec[N];
double s, p[N];
double solve (int x) {
double ans = s * p[x];
double tmp = s * (1-p[x]);
for (int i = 0; i < c; i++)
ans += tmp / (1-p[rec[i]]) * p[rec[i]];
return ans;
}
int main () {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lf", &p[i]);
sort (p, p + n);
c = 0;
double ans = p[n-1];
s = 1 - p[n-1];
rec[c++] = n-1;
for (int i = n-2; i >= 0; i--) {
double tmp = solve(i);
if (tmp > ans) {
ans = tmp;
rec[c++] = i;
s *= (1 - p[i]);
}
}
printf("%.12lf\n", ans);
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
Codeforces 442B Andrey and Problem(贪婪)的更多相关文章
- Codeforces 442B. Andrey and Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 442B B. Andrey and Problem(贪心)
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...
- codeforces#253 D - Andrey and Problem里的数学知识
这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 442B
题目链接 B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- cf442B Andrey and Problem
B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- CodeForces 867B Save the problem
B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...
随机推荐
- [Oracle] - 性能优化工具(4) - AWRDD
AWRDD是用于比較两个AWR快照,从而获得不同一时候期的性能. 运行例如以下语句获得AWRDD: @?/rdbms/admin/awrddrpt.sql 2025 23 2月 2014 07:12 ...
- atitit.java方法属性赋值and BeanUtils 1.6.1 .copyProperty的bug
atitit.java分配给属性值方法and BeanUtils 1.6.1 .copyProperty的bug 1. core.setProperty(o, "materialId&quo ...
- 查看mysql当前表使用的存储引擎(转)
说明:当我们创建表 “test”表时 CREATE TABLE test ( id INT(11) default NULL auto_increment, s char(60) default NU ...
- 状态压缩dp(hdu2167,poj2411)
hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...
- 构建轻量级的Table View注意事项[UIKit]
參考文章来自objcio站点 一.使用ChildViewController 将Table ViewController作为Child View Controller加入到其它View Control ...
- VirtualBox安装ubuntu14.04和文件共享
因为机器的VMware使用很卡,占用更多的内存,所以我想,以取代VirtualBox.已安装ubuntu14.04使用与VMware在相同的. VirtualBox下载链接:https://www.v ...
- 设计模式(一)工厂模式Factory(创建类型)
设计模式一 工厂模式Factory 在面向对象编程中, 最通常的方法是一个new操作符产生一个对象实例,new操作符就是用来构造对象实例的.可是在一些情况下, new操作符直接生成对象会带来一些问题. ...
- Unity3D之Vector3.Dot和Vector3.Cross采用
在Unity3D中.Vector3.Dot表示求两个向量的点积;Vector3.Cross表示求两个向量的叉积. 点积计算的结果为数值,而叉积计算的结果为向量.两者要注意差别开来. 在几何数学 ...
- nodeValue的兼容问题
nodeValue获取Text或Comment元素的文本值. 在IE6.IE7.IE8中游览器会自作聪明的去掉前面的空白字符text,而其它现代游览器则会保留空白 <body> <s ...
- 在WPF中使用PlaneProjection模拟动态3D效果
原文:在WPF中使用PlaneProjection模拟动态3D效果 虽然在WPF中也集成了3D呈现的功能,在简单的3D应用中,有时候并不需要真实光影的3D场景.毕竟使用3D引擎会消耗很多资源,有时候使 ...