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;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4722936.html,如需转载请自行联系原作者


相关文章
UVa10484 - Divisibility of Factors(数论)
UVa10484 - Divisibility of Factors(数论)
58 1
|
C++
【PAT甲级 - C++题解】1096 Consecutive Factors
【PAT甲级 - C++题解】1096 Consecutive Factors
72 0
|
Windows
German Collegiate Programming Contest 2019 H . Historical Maths (二分 大数)
German Collegiate Programming Contest 2019 H . Historical Maths (二分 大数)
80 0
German Collegiate Programming Contest 2019 H . Historical Maths (二分 大数)
AtCoder Beginner Contest 221 E - LEQ(组合数学 树状数组)
AtCoder Beginner Contest 221 E - LEQ(组合数学 树状数组)
148 0
UCF 2021 Practice F.Balanced Strings (思维 组合数学)
UCF 2021 Practice F.Balanced Strings (思维 组合数学)
99 0
|
人工智能 BI
[Atcoder ARC124] XOR Matching 2-小思维 | 暴力
题意: 给出n,两个数列a[1] -> a[n],b[1] -> b[n] 问有多少个x,可以使得在我们任意一种方式排列b[]之后,有a[i] ^ b[i] == x (1 <= i <= n) 思路: 首先我们可以确定所有的答案一定在a[1] ^ b[i] (1 <= i <= n)之内,所以我们只需要将这些个x的解空间单独放到数组c[]里,然后遍历x的解空间c[],将c[i] ^ a[i]的结果记录在d[]里面,然后判断b[],d[]是否完全相同即可,如果完全相同,就可以记录答案,注意最终答案要进行去重
113 0
[Atcoder ARC124] XOR Matching 2-小思维 | 暴力
|
机器学习/深度学习 物联网
[Codeforces 1586] Omkar and Determination | 思维前缀和
题意 给定一个n ∗ m 的方格,在这个方格中有一些点被标记为′ . ′ 说明这个点是没有障碍的,而′ X ′ 代表这个点是有障碍的,不能通过这个点,对于每个点,只能向上或者是向左走。如所说有的′ . ′ 点不能走出去,那么这样的′ . ′ 点就不是e x i t a b l e exitable 问题是:给定一个矩阵里面所有的 exitable点,如果给出的矩阵能够唯一确定,就是YES,否则输出 NO 所以问题就变成了给定的矩阵范围中有没有是′ . ′但是不能够 exitable的点,如果有就无法唯一确定(YES),反之就可以唯一确定(NO) 数据范围太大,可以开 vector 来模拟二维数
581 0
HDU-1048,The Hardest Problem Ever(字符串处理)
HDU-1048,The Hardest Problem Ever(字符串处理)