NC216006. Fireworks
描述
输入描述
There are multiple test cases. The first line of the input contains an integer(
) indicating the number of test cases. For each test case:
The first and only line contains three integers,
and
(
,
).
输出描述
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)); } }