题解:P13244 [GCJ 2014 Qualification] Cookie Clicker Alpha
P3244 题解:
主要思路:
从不买任何农场的情况开始,存储当前情况的时间,然后逐一枚举如果购买一所农场所需要的曲奇的生产时间,如果小于上一个情况,更新当前最优解。
代码实现:
定义一个变量
AC Code:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T;
int32_t main(){
cout.tie(nullptr)->ios::sync_with_stdio(false);
cin.tie(nullptr)->ios::sync_with_stdio(false);
cin>>T;
cout<<fixed<<setprecision(7);//保留七位小数。
for(int cas=1;cas<=T;cas++){
double c,f,x;
cin>>c>>f>>x;
double e=0.0;
double r=2.0;
double tz=x/r;
while(1){
double tx=c/r;
e+=tx;
r+=f;
double ty=e+x/r;
if(ty<tz) tz=ty;//如果有更优解,更新当前值。
else break;
}
cout<<"Case #"<<cas<<": "<<tz<<endl;//注意输出格式。
}
}
~求过。~