一、题目

  Valentine's Day

二、分析

  假设$ s_0 $代表不开心的概率,$ s_1 $代表开心一次的概率。

  那么随便取一个物品,那么它的开心概率为$ p _i $,可以推导加入之后使女朋友不开心和开心一次的概率为$$ s_0 = s_0(1-p_i) $$ $$ s_1 = s_1 + (s_0 - s_1)p$$

  通过式子可以推导出,如果$  s_0 \le s_1 $,则开心一次的概率就不会有任何增长。

  所以,可以将概率从大到小排序,然后不断加入,判断一下就可以了。

三、AC代码

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4 #define ll long long
5 #define Min(a,b) ((a)>(b)?(b):(a))
6 #define Max(a,b) ((a)>(b)?(a):(b))
7 #define P pair<int, int>
8
9 int main()
10 {
11 int T;
12 scanf("%d", &T);
13 while(T--) {
14 int n;
15 double p;
16 vector<double> vec;
17 scanf("%d", &n);
18 for(int i = 0; i < n; i++) {
19 scanf("%lf", &p);
20 vec.push_back(p);
21 }
22 sort(vec.begin(), vec.end(), greater<double>());
23 double ans1 = 1.0, ans2 = 0;
24 for(int i = 0; i < vec.size(); i++) {
25 if(vec[i] == 1.0) {
26 ans2 = 1.0;
27 break;
28 }
29 else {
30 double res1 = ans1 * (1.0 - vec[i]);
31 double res2 = ans2 + vec[i]*(ans1 - ans2);
32 ans1 = res1, ans2 = res2;
33 if(ans1 <= ans2)
34 break;
35 }
36 }
37 printf("%.12lf\n", ans2);
38
39 }
40 return 0;
41 }

HDU_6693 Valentine's Day 【概率问题】的更多相关文章

  1. HDU 6693 Valentine's Day (概率)

    2019 杭电多校 10 1003 题目链接:HDU 6693 比赛链接:2019 Multi-University Training Contest 10 Problem Description O ...

  2. [概率] HDU 2019 Multi-University Training Contest 10 - Valentine's Day

    Valentine's Day Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others ...

  3. 【HDOJ6693】Valentine's Day(概率)

    题意:给定n件物品,每件物品让周驿东开心的概率为a[i] 要求从中选一些,使得周驿东恰好开心一次的概率最大 n<=1e4,0<=a[i]<=1 思路: #include<bit ...

  4. hdu多校第十场 1003 (hdu6693) Valentine's Day 贪心/概率

    题意: 有许多物品,每个物品有一定概率让女朋友开心.你想让女朋友开心且只开心一次,让你挑一些物品,使得这个只开心一次的概率最大,求最大概率. 题解: 设物品i让女朋友开心的概率为$p_i$ 若你挑选了 ...

  5. [bzoj2152][聪聪和可可] (点分治+概率)

    Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好 ...

  6. sqlserver中根据表中的配置概率取到数据

      create proc pr_zhanglei_test1 /*功能描述: 根据t_zhanglei_test1中perc设置的概率,取到相应数据old_id */ as declare @per ...

  7. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  8. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  9. UVA1637Double Patience(概率 + 记忆化搜索)

    训练指南P327 题意:36张牌分成9堆, 每堆4张牌.每次拿走某两堆顶部的牌,但需要点数相同.如果出现多种拿法则等概率的随机拿. 如果最后拿完所有的牌则游戏成功,求成功的概率. 开个9维数组表示每一 ...

随机推荐

  1. ArcGIS处理栅格数据(三)

    六.制作镶嵌数据集(栅格数据集优点:a.浏览速度快:b.入库速度快:c.可指定区域显示) 1.右键目录中的数据库,新建"镶嵌数据集". 2.添加栅格数据. 3.定义金字塔. 4.构 ...

  2. Gym102361A Angle Beats(直角三角形 计算几何)题解

    题意: \(n\)个点,\(q\)个询问,每次问包含询问点的直角三角形有几个 思路: 代码: #include<bits/stdc++.h> using namespace std; co ...

  3. translate.js

    http://www.openxrest.com/translatejs/index.html translate.js translate.js is a jQuery plugin to tran ...

  4. Cocos Creator 游戏开发

    Cocos Creator 游戏开发 https://www.cocos.com/products#CocosCreator 一体化编辑器: 包含了一体化.可扩展的编辑器,简化了资源管理.游戏调试和预 ...

  5. how to using Linux pipe command output another command's help content to a file

    how to using Linux pipe command output another command's help content to a file Linux tee > >& ...

  6. Linux & terminal color & command line color

    Linux & terminal color & command line color how to change Linux terminal color https://askub ...

  7. LGTM & code review

    LGTM & code review LGTM is an acronym meaning looks good to me, frequently used when reviewing d ...

  8. export excel

    export excel sheet.js https://sheetjs.com/ https://github.com/SheetJS/sheetjs excel.js https://www.n ...

  9. Dart: 请求graphql数据

    import 'package:http/http.dart' as http; const url = "http://127.0.0.1:4000/graphql"; main ...

  10. 微信小程序:单选框radio和复选框CheckBox

    单选框radio: 可以通过color属性来修改颜色. 复选框checkbox: