题目链接: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. android各种资源的详细解释

    1.字符数组      使用字符串数组资源<string-array>标签定义,在<string-array>包括一些标签<item>数组元素标记.   例如 &l ...

  2. 有关信息ACM/ICPC竞争环境GCC/G++叠插件研究记录的扩展

    0.起因 有时.DFS总是比BFS受人喜爱--毕竟DFS简单粗暴,更,而有些东西BFS不要启动,DFS它似乎是一个可行的选择-- 但是有一个问题,DFS默认直接写入到系统堆栈.系统堆栈和足够浅,此时O ...

  3. asp.net用户身份验证时读不到用户信息的问题 您的登录尝试不成功。请重试。 Login控件

    原文:asp.net用户身份验证时读不到用户信息的问题 您的登录尝试不成功.请重试. Login控件 现象1.asp.net使用自定义sql server身份验证数据库,在A机器新增用户A,可以登录成 ...

  4. hdu1754(splay)

    给n个数,有两种操作    Q a b   询问区间[a,b]的最大值,  U a b 将第a个数的值改成b splay树的中序遍历是我们所维护的序列.如果要询问区间[a,b]的最大值,那么只要将第a ...

  5. 通信协议:HTTP、TCP、UDP(转)

    原文出处: 碧雪轩的博客 TCP   HTTP   UDP: 都是通信协议,也就是通信时所遵守的规则,只有双方按照这个规则“说话”,对方才能理解或为之服务. TCP   HTTP   UDP三者的关系 ...

  6. shell编程三大神器之awk

  7. How to import the www.googleapis.com SSL CA certification to the jks store file?

    Assumed that you have installed JDK and configured JAVA_HOME for your current operation system. (1)  ...

  8. cocos2d-x V3.0 呼叫加速度计 Acceleration

    今天克服了一个问题,我觉得非常酷 哈哈. 今天得到解决cocos2d-x 3.0 呼叫重力加速器问题,上网查了很多资料 发现是不够,不解决这个问题,我不知道如果我使用3.0 这一问题的版本号,但是,这 ...

  9. datagrid标题头粗体

    //标题头粗体        //$("#R_datagrid .datagrid-header-row td div span").each(function (i, th) { ...

  10. win10无法新建文件夹怎么办 win10右键新建菜单设置方法

    有朋友安装了win10系统后发现右键菜单中没有新建项,而平时使用新建 - 文件夹项的机率很高.如何才能恢复桌面右键菜单中的新建项呢? 右键点击桌面空白处,在右键菜单中发现没有新建项: 桌面右键菜单没有 ...