题目链接: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. SVN的log,cat,list,diff的使用

     svn log          展示给你主要信息:每个版本附加在版本上的作者与日期信息和所有路径修改. svn diff          显示特定修改的行级详细信息. svn cat       ...

  2. 【SSH 基础】浅谈Hibernate关系映射(4)

    继上篇博客 多对多关联映射(单向) 多对多对象关系映射,须要增加一张新表完毕基本映射. Hibernate会自己主动生成中间表 Hibernate使用many-to-many标签来表示多对多的关联,多 ...

  3. Java 二次MD5 32位小写加密算法与php页面加密结果相同

    最近做的一个项目需要使用MD5加密算法,需要加密的参数有两个.自己先试了几次,算的结果为php页面的不一样,后来与写php页面的同事沟通后,了解到php页面的算法如下: action = " ...

  4. 我的Android进阶之旅------>经典的大牛博客推荐(排名不分先后)!!

    本文来自:http://blog.csdn.net/ouyang_peng/article/details/11358405 今天看到一篇文章,收藏了很多大牛的博客,在这里分享一下 谦虚的天下 柳志超 ...

  5. as 的妙用

    个人理解:as跟is is 相当于判断里的“==” 是与否 if(e.OriginalSource is Button) as 一般用来转换另一种object e.OriginalSource as ...

  6. 重新启动IIS服务的方法

    WINDOWS提供WEB服务的IIS有时候会出现訪问过大导致站点打不开,这时重新启动IIS是最好的选择. 1.界面操作 打开"控制面板"->"管理工具"- ...

  7. 开源 自由 java CMS - FreeCMS1.8 网上申报

    项目地址:http://code.google.com/p/freecms/ 在线申报 1. 转交申报 用户能够把申报转交给其它人办理,系统会记录此申报的转交记录. 注意:同一时候仅仅能转交一个申报. ...

  8. OCP-1Z0-051-名称解析-文章7称号

    7. Which two  statements are true regarding the USING and ON clauses in table joins? (Choose two.) A ...

  9. java Socket使用详细解释

    客户/server通信模式, client需要主动创造和server Socket(套接字), server端收到了client的连接请求, 也会创建与客户连接的 Socket. Socket可看做是 ...

  10. Django操作model时刻,一个错误:AttributeError:’ProgrammingError’ object has no attribute ‘__traceback__’

    原因:在Django项目下对应的应用以下的models.py配置的model(也就是class)没有创建成对应的表. 这是怎么回事呢? 首先,将models.py里面的model创建成相应的数据库表的 ...