题目链接: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(贪婪)的更多相关文章

  1. Codeforces 442B. Andrey and Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

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

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

  3. codeforces#253 D - Andrey and Problem里的数学知识

    这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...

  4. 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 ...

  5. Codeforces 442B

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

  6. [codeforces 528]B. Clique Problem

    [codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...

  7. cf442B Andrey and Problem

    B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  8. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  9. CodeForces 867B Save the problem

    B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...

随机推荐

  1. UVA 1513 - Movie collection(树状数组)

    UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=5 ...

  2. [Unity3D]转让Android介面

    简单介绍 有一些手机功能.Unity没有提供对应的接口.比如震动,比如不锁屏,比如GPS.比如... 有太多的特殊功能Unity都没有提供接口.这时候,我们就须要通过使用Android原生的ADT编辑 ...

  3. java reflect反思总结

    --------------TestBean package lh.demo.bean; public class TestBean {  private String userName;  priv ...

  4. Portlet MVC框架

    Portlet MVC框架 16.1. 介绍   Spring不仅支持传统(基于Servlet)的Web开发,也支持JSR-168 Portlet开发. Portlet MVC框架尽可能多地采用Web ...

  5. Ibatis之3个不经常使用的Query方法

    1.queryForObject /** * Executes a mapped SQL SELECT statement that returns data to populate * the su ...

  6. poj 3259(bellman最短路径)

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30169   Accepted: 10914 Descr ...

  7. 银行家算法java实现

    关于银行家算法的理论知识,课本或者百度上有好多资料,我就不再多说了,这里把我最近写的银行家算法的实现带码贴出来. 由于这是我们的一个实验,对系统资源数和进程数都指定了,所以这里也将其指定了,其中系统资 ...

  8. Spring它不支持依赖注入static静态变量

    在springframework在,我们不能@Autowired静态变量,制作spring bean,例如,没有那么: @Autowired private static YourClass your ...

  9. 用golang写的 分解x86 intel boot/recovery工具

    源代码地址: https://github.com/sndnvaps/pack-unpack-intel

  10. .NET API for RabbitMQ and ActiveMQ

    EasyNetQ: .NET API for RabbitMQ: https://github.com/mikehadlow/EasyNetQ/wiki/Quick-Start Or: http:// ...