链接:https://ac.nowcoder.com/acm/contest/10272/F
来源:牛客网

题目描述
Kotori is practicing making fireworks for the upcoming hanabi taikai1. It takes her nn minutes to make a single firework, and as she is not really proficient in making fireworks, each firework only has a probability of p \times 10^{-4}p×10
−4
to be perfect.

After she finishes making a firework, she can just start making the next firework, or take mm minutes to light all the remaining fireworks finished before. If there is at least one perfect firework among the lit ones, she will be happy and go to rest. Otherwise, she will continue practicing. Can you tell her the minimum expected practicing time before she goes to rest if she takes the optimal strategy?

Notice that no matter how many fireworks remain, it always takes mm minutes to light them all.

1Hanabi taikai: Romaji of the Japanese word “花火大會”, which means the firework… err… party?
输入描述:
There are multiple test cases. The first line of the input contains an integer TT (1 \le T \le 10^41≤T≤10
4
) indicating the number of test cases. For each test case:

The first and only line contains three integers nn, mm and pp (1 \le n, m \le 10^91≤n,m≤10
9
, 1 \le p \le 10^41≤p≤10
4
).
输出描述:
For each test case, output one line containing one number indicating the minimum expected practicing time.

Your answer will be considered correct if and only if the absolute or relative error does not exceed 10^{-4}10
−4
.
示例1
输入复制

3
1 1 5000
1 1 1
1 2 10000

输出复制

4.0000000000
10141.5852891136
3.0000000000

1、F Fireworks

题意:

  • 制作一个烟花需要n分钟,成功的概率为p。完成一次制作后可以继续制作或花m分钟点燃之前所有的烟花,如果有一个烟花是成功的,那么就可以开始休息。
  • 求最小的期望开始休息时间(即期望的最早成功制作一个烟花的时间)

思路:

  • 因为每次都是做出来一批集中释放做好的看看有没有成功的,所以不妨设最优策略为每次做k个能最早休息。所以问题转化为每次制作k个释放,期望的最早制作成功的时间。
  • 每轮制作耗费时间kn+m,至少一个烟花制作成功的概率为(1−(1−p)k)(1-(1-p)^k)(1−(1−p)k),所以根据几何分布公式可以得到期望为kn+m1−(1−p)k\frac{kn+m}{1-(1-p)^k}1−(1−p)kkn+m​。
  • 对该式子打表或者求二阶导可以发现这是个单峰的凹函数。可以三分答案。
#include<bits/stdc++.h>
using namespace std;
typedef long double LD;
LD fun(int k, int n, int m, LD p){return ((LD)k*n+m)/((LD)1.0-pow(1.0-p,k));
}
int main(){int T;  cin>>T;while(T--){int n, m;  LD p;cin>>n>>m>>p;p *= (1e-4);int l = 1, r = 1e9+10;while(l < r){int mid1 = l+(r-l)/3, mid2 = r-(r-l)/3;if(fun(mid1,n,m,p)<fun(mid2,n,m,p))r = mid2-1;else l = mid1+1;}printf("%.10Lf\n", fun(l,n,m,p));}return 0;
}

附算法:

  • 什么是凹函数?
  • 什么是三分?
    二分查找 适用于单调函数中逼近求解某点的值。
    三分查找可以用于求凹凸函数的那个凸点或凹点

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京)签到题F Fireworks相关推荐

  1. 第45届国际大学生程序设计竞赛(ICPC)银川站太原理工大学收获4枚奖牌

    第45届国际大学生程序设计竞赛(ICPC)银川站,由宁夏理工学院承办,于2021年5月15-16日在宁夏的石嘴山市进行. 太原理工大学在比赛中获得2银2铜共4枚奖牌的好成绩. 参加本次比赛的四个队,涵 ...

  2. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)(重现赛)

    第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)(重现赛) 导语 涉及的知识点 题目 C D G J M 参考文献 导语 日常的队内集训,开始的时候状态其实很好,但是到了后两题就出现了 ...

  3. 第45届国际大学生程序设计竞赛(ICPC)沈阳站太原理工大学收获1枚铜牌

    第45届ICPC沈阳区域赛,于2021年7月18日在东北大学南湖校区举行.太原理工大学2个队参加比赛,由20级中学没有学过编程的3名同学组成的队,首次参加现场赛并获得铜奖.

  4. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京)签到题K Co-prime Permutation,L Let‘s Play Curling

    序 emmm因为没时间补题(虽然签到有四题),所以只能先放两个签到. 这是比赛链接:https://ac.nowcoder.com/acm/contest/10272 这是题解链接:2020年ICPC ...

  5. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 题解(除了C、G之后补)

    整理的算法模板合集: ACM模板 这次比赛好多原题呀-(就是那种稍微拓展了一点的原题) 目录 A.Easy Equation B.XTL's Chessboard D.Pokemon Ultra Su ...

  6. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题HIL

    H. Hard Calculation 链接:https://ac.nowcoder.com/acm/contest/12548/H 来源:牛客网 题目描述 Hooray! It is the fir ...

  7. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲网上区域赛模拟赛 B.XTL‘s Chessboard(思维)

    题目链接:https://ac.nowcoder.com/acm/contest/8688/B 题目描述 Xutianli is a perfectionist, who only owns &quo ...

  8. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题4题

    文章目录 H. Hard Calculation I. Mr. Main and Windmills L. Simone and graph coloring J.Parallel Sort 补题链接 ...

  9. 【第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛】Simone and Graph Coloring

    #include <bits/stdc++.h> using namespace std; const int maxn = 1000005, INF = 0x7f7f7f7f; int ...

  10. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明) AC(带悔贪心)

    下面两个题都是选择iii有个价值如果选择iii则不能选择i−1,i+1i-1,i+1i−1,i+1,让价值最大或最小 P1792 [国家集训队]种树 野心qwq 的博客 #include<bit ...

最新文章

  1. java连接sqlserver 2005执行存储过程的几种情况
  2. 网站建设需要遵守的三大原则!
  3. 通过投影增强数据模型
  4. 大数据新手之路四:联合使用Flume和Kafka
  5. HTML5 device access 设备访问
  6. java瞎子_Java学习路线,及各方面知识点
  7. ssas 分区 设置_如何在Analysis Services多维中对SSAS多维数据集进行分区
  8. linux服务器单向ping不通,Linux下的单向ping通问题
  9. lvgl chart
  10. 计算机上机日志如何查找,如何查看金蝶KIS记账王上机日志
  11. SPRD Camera sensor
  12. 【云原生之Docker实战】使用Docker部署家庭个人在线音乐平台
  13. MPAndroidChart3使用详解4:BarChart(柱形图)
  14. 计算机图形学常用算法实现11 扫描线z-buffer算法
  15. emq无法启用mysql_EMQ开启mysql认证
  16. VScode CMake 编写 Boost Asio Chat程序----记录6
  17. 如何用python统计英语文章词频?
  18. 基于JAVAWeb产品管理系统计算机毕业设计源码+数据库+lw文档+系统+部署
  19. pnpm创建vite + vue + ts项目
  20. gnu coreutils utime.c 源码分析

热门文章

  1. 数学归纳法在数据结构与算法分析设计中的应用
  2. 经济学的概念、术语与常识
  3. 阶乘与 pi 的关系 —— 斯特林公式(Stirling formula)
  4. Python 面向对象 —— 特殊函数(setattr、getattr、hasattr)
  5. Python 进阶 —— defaultdict
  6. 机器学习基础(十六)—— bootstrap
  7. latex 基本用法(四)
  8. 昆仑通态复制的程序可以用吗_昆仑通态触摸屏如何做时间记录
  9. python3.6安装步骤-python3.6、opencv安装环境搭建过程(图文教程)
  10. python必背100源代码-学会这个Python库,至少能减少100行代码