链接

题目描述

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×10−4p \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.

Hanabi 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 TTT (1≤T≤104)(1 \le T \le 10^4)(1≤T≤104) indicating the number of test cases. For each test case:

The first and only line contains three integers nnn, mmm and ppp (1≤n,m≤109,1≤p≤104)(1 \le n, m \le 10^9, 1 \le p \le 10^4)(1≤n,m≤109,1≤p≤104).

输出描述:

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−410^{-4}10−4.

输入

3
1 1 5000
1 1 1
1 2 10000

输出

4.0000000000
10141.5852891136
3.0000000000

思路

设做好 xxx 个烟花再点燃是最策略,dpxdp_xdpx​ 代表这一策略花费时间的期望,那么有:dpx=n×i+m+(i−p)idpxdp_x=n\times i +m+(i-p)^idp_xdpx​=n×i+m+(i−p)idpx​ 。其中 (1−p)idpx(1-p)^idp_x(1−p)idpx​ 代表已经制作好的 iii 个烟花有 (1−p)i(1-p)^i(1−p)i 的概率都是不完美的,那么就需要再制造 kkk 个烟花来点燃。

那么 dpx=n×i+m1−(1−p)idp_x=\frac{n\times i+m}{1-(1-p)^i}dpx​=1−(1−p)in×i+m​。

令 f(x)=ax+b1−cxf(x)=\frac{ax+b}{1-c^x}f(x)=1−cxax+b​ ,(0<c<1)(0<c<1)(0<c<1),那么f′(x)=a(1−cx)+cxlnc(ax+b)(1−cx)2f'(x)=\frac{a(1-c^x)+c^xlnc(ax+b)}{(1-c^x)^2}f′(x)=(1−cx)2a(1−cx)+cxlnc(ax+b)​。先递减再递增,是个单峰函数,使用三分求出最值。

#include<bits/stdc++.h>
using namespace std;
int T,n,m; double p;double qpow(double a,int b){double ret=1;while(b){if(b&1) ret=ret*a;a=a*a; b>>=1;}return ret;
}double calc(int i){return ((double)n*i+m)/(1-qpow(1-p*1e-4,i));
}void solve(){cin>>n>>m>>p;int l=1,r=1e9;while(l<r){int midl=(l+r)>>1;int midr=midl+1;if(calc(midl)<calc(midr)) r=midr-1;else l=midl+1;}cout<<setprecision(10)<<fixed<<calc(l)<<"\n";
}int main(){ios::sync_with_stdio(false);for(cin>>T;T;T--) solve();
}

2020ICPC南京 F Fireworks(概率,三分)相关推荐

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

    链接:https://ac.nowcoder.com/acm/contest/10272/F 来源:牛客网 题目描述 Kotori is practicing making fireworks for ...

  2. 2020ICPC南京区域赛 补题 总结

    前言 第一次打线上 ICPC\text{ICPC}ICPC ,记录一下.听说鸭血粉丝汤很好吃,虽然我没吃到,衣服也不赖.比赛环境方面,由于使用自己的设备,还是比较舒服的. 不晓得怎么,一到正式赛,前期 ...

  3. F分布概率密度函数的推导

    推导过程整理自https://www.bilibili.com/video/BV1qf4y1R7FA. 文章目录 预备知识 Γ \Gamma Γ函数(伽马函数) 标准正态分布 卡方分布 推导目标 引理 ...

  4. 2020 ICPC 南京站 F Fireworks (概率论+三分)

    题目链接:F-Fireworks_第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京) 题目描述 Kotori is practicing making fireworks for the ...

  5. 2020ICPC(南京) - Just Another Game of Stones(吉司机线段树+博弈)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的数列 aaa,现在需要执行 mmm 次操作,每次操作分为两种类型: 1lrx1 \ l \ r \ x1 l r x:对于所有 i∈[l,r]i ...

  6. 2019 ICPC 南京 F题 Paper Grading

    题目链接 题意 给一些字符串,一个操作是交换两个串的位置,另一个是问编号介于 [l,r][l,r][l,r] 的字符串,与提问串的最长公共前缀(LCP)至少为 kkk 的个数 题解 将串建立 Trie ...

  7. Evil Coordinate(70行精简代码) 2020icpc南京站

    目录 大致题意: 思路: 代码: 南京站其余题目(点击进入) 大致题意: 在一个图中,一个人从(0,0)进行上下左右行走.有一个地雷点(mx,my).询问可不可以通过改变行走上下左右的顺序(不改变上下 ...

  8. 2019 ICPC 南京 F. Paper Grading(字典树dfs序上树套树)

    Paper Grading 题意:给定nnn个字符串,有两种操作: 一.给定i,ji, ji,j,交换第iii个跟第jjj个字符串. 二.给定 str ,k,l,rk, l, rk,l,r,问你在区间 ...

  9. 2020ICPC南京 E.Evil Coordinate(构造)

    题意: 有一个二维坐标系, 你开始你在(0,0)点,给定坐标(mx,my), 给定长度为n的字符串,只包含LRUD,对应上下左右, 现在你可以重排这个字符串,要求你按照重排的字符串走, 走的时候不能碰 ...

  10. 【数学与算法】如何通俗的理解概率密度函数

    概率分布函数就是概率密度函数. 累计分布函数: 对概率密度函数从负无穷到xxx积分,得到的是累计分布函数. 如何通俗的理解概率密度函数? 首先考虑这样一个问题,你点了一个外卖,外卖说会在两个小时送达. ...

最新文章

  1. 推荐7款冷门但是非常值得推荐的windows软件
  2. java swing 外观框架_【GUI】一、Swing外观框架BeautyEye使用
  3. boot sprint 项目结构_京淘项目03 08.28
  4. 设计模式 — 行为型模式 — 迭代器模式
  5. 仿个人税务 app html5_手机里发现这类APP,赶紧删!
  6. Android开发之虹软人脸识别活体检测基本步骤
  7. Java虚拟机-内存分配策略
  8. ARMv9刷屏 —— 号称十年最大变革,Realm机密计算技术有什么亮点?
  9. 如何系统地自学python100天_如何系统地自学 Python?
  10. python 并行_python并行处理任务时 该用多进程?还是该用多线程?
  11. 楼下邻居总偷网,改密码也没用,过一会他们又能连上,该怎么办?
  12. ffmpeg转MP4 moov头在前命令
  13. linux系统硬盘数据恢复软件下载,R-Linux|R-Linux(linux数据恢复软件)下载 v5.1中文免费版 - 121下载站...
  14. POJ 1006 同余方程组
  15. This project uses AndroidX dependencies, but the ‘android.useAndroidX‘ property is not enabled
  16. linux下telnet工具下载,telnet.exe下载
  17. python下载电影链接_Python:输入电影名,爬获取到阳光电影网中对应名称的迅雷下载链接,获取的链接有点问题(具体问题在内容里)...
  18. 《赖氏经典英语语法》第三集
  19. 你所不知道的Activity转场动画——ActivityOptions
  20. linux字体文件路径,Linux下安装字体

热门文章

  1. implement 和 extends 的区别
  2. 晶体二极管的主要参数
  3. Dell IDRAC服务器重装系统详解(远程连接)
  4. Redis-使用redis-trib构建集群
  5. 遍历数组-forEach
  6. 免费国外视频素材网站
  7. 前端实习生实习第一天
  8. 实验八 集成稳压器
  9. 2008 SCI 影响因子(Impact Factor)
  10. 简洁好用的Geek Unіnstaller