Codeforces 442B Andrey and Problem(贪心)
2014-06-30 09:04
316 查看
题目链接:Codeforces 442B Andrey and Problem
题目大意:Andrey有一个问题,想要朋友们为自己出一道题,现在他有n个朋友,每个朋友想出题目的概率为pi,但是他可以同时向多个人寻求帮助,不过他只能要一道题,也就是如果他向两个人寻求帮助,如果两个人都成功出题,也是不可以的。
解题思路:贪心,从概率最大的人开始考虑,如果询问他使得概率变大,则要询问。
题目大意: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 ; double s, p ; 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 390D Inna and Sweet Matrix(贪心)
- Codeforces 651A Joysticks【贪心】
- CodeForces 732D Exams 二分+贪心
- CodeForces 137C【贪心+优先队列】
- codeforces 387C George and Number(贪心)
- 【Codeforces 贪心】Far Relative’s Problem
- 【Codeforces 733D】 Kostya the Sculptor【贪心】
- CodeForces_937C Save Energy!(贪心)
- CodeForces 698A —Vacations(贪心)
- CodeForces 507A Amr and Music (贪心)
- CodeForces 288A--贪心
- Codeforces 401A Vanya and Card【贪心】水题
- CodeForces 949A Zebras【贪心 字符串】
- Codeforces 437D The Child and Zoo(贪心+并查集)
- CodeForces 637D Running with Obstacles(贪心模拟)
- codeforces-796C-Bank Hacking(贪心)
- Codeforces 413C Jeopardy!(贪心)
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
- CodeForces 659C Tanya and Toys(贪心)
- CodeForces 342B Xenia and Spies(贪心)