题目链接: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的PackageManager的使用

    Android系统提供了很多服务管理的类,包括ActivityManager.PowerManager(电源管理).AudioManager(音频管理)以及PackageManager管理类.Pack ...

  2. php中遍历数组的方法

    参考网址:http://www.jb51.net/article/29949.htm 这三种方法中效率最高的是使用foreach语句遍历数组.从PHP4开始就引入了foreach结构,是PHP中专门为 ...

  3. 基于 Groovy 的自动化构建工具 Gradle 入门(转)

    本人工作之初没有使用自动化构建,后来敏捷了,开始使用 Ant - 完全面向过程的定义步骤,不进行依赖管理.再发展到 Maven,面向对象的方式管理工程,有了依赖的管理,JAR 包统一从中央仓库获得,保 ...

  4. start_kernel——boot_init_stack_canary

    /* * Initialize the stackprotector canary value. * * NOTE: this must only be called from functions t ...

  5. 【甘道夫】Win7x64环境下编译Apache Hadoop2.2.0的Eclipse小工具

    目标: 编译Apache Hadoop2.2.0在win7x64环境下的Eclipse插件 环境: win7x64家庭普通版 eclipse-jee-kepler-SR1-win32-x86_64.z ...

  6. Kendo UI开发教程(16): Kendo MVVM 数据绑定(五) Events

    本篇和Kendo UI开发教程(14): Kendo MVVM 数据绑定(三) Click类似,为事件绑定的一般形式.Events绑定支持将ViewModel的方法绑定到DOM元素的事件处理(如鼠标事 ...

  7. devstack安装使用openstack常见问题与解决的方法

    声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结.如有雷同,实属荣幸! 安装执行create-sta ...

  8. 黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级)

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级) 企业库验证应用程序模块之配置文件模式: ...

  9. PyUnit框架学习

    http://www.oschina.net/question/12_27127#INSTALL http://www.360doc.com/content/11/0606/23/54470_1221 ...

  10. 高性能 TCP &amp; UDP 通信框架 HP-Socket v3.2.2 正式公布

    HP-Socket 是一套通用的高性能 TCP/UDP 通信框架,包括服务端组件.client组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C++.C#. ...