列表

详情


NC216006. Fireworks

描述

Kotori is practicing making fireworks for the upcoming hanabi taikai1. It takes her n minutes to make a single firework, and as she is not really proficient in making fireworks, each firework only has a probability of to be perfect.

After she finishes making a firework, she can just start making the next firework, or take m 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 m 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 T () indicating the number of test cases. For each test case:

The first and only line contains three integers n, m and p (, ).

输出描述

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 .

示例1

输入:

3
1 1 5000
1 1 1
1 2 10000

输出:

4.0000000000
10141.5852891136
3.0000000000

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(g++ 7.5.0) 解法, 执行用时: 413ms, 内存消耗: 652K, 提交时间: 2023-05-12 16:18:27

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
long double p;
double e(int x)
{
	return ((double)x*n+m)/(1.0-(pow(1.0-p,x)));
}
void solve()
{
	cin>>n>>m>>p;
	p=p*0.0001;
	int l=1,r=INT_MAX;
	while(l<r)
	{
		int ll=l+(r-l)/3,rr=r-(r-l)/3;
		if(e(ll)<e(rr))r=rr-1;
		else l=ll+1;
	}
	printf("%.9f\n",e(l));
}
signed main()
{
	int t;cin>>t;
	while(t--)solve();
	return 0;
}

C++ 解法, 执行用时: 85ms, 内存消耗: 632K, 提交时间: 2022-04-28 02:10:19

#include<bits/stdc++.h>
using namespace std;
int n,m,t;
double p;
double qout(int k)
{
	return (1.0*k*n+m)/(1-pow(1-p,k));
}
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>m>>p;
		p=p/10000;
		int l=1,r=1e9;
		while(l<r)
		{
			int mid=l+r>>1;
			if(qout(mid)<=qout(mid+1))
			r=mid;
			else
			l=mid+1;
		}
		printf("%.10lf\n",qout(r));
	}
	
}

上一题