Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
The single line contains three integers k, d and t (1 ≤ k, d, t ≤ 1018).
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.
Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if .
3 2 6
6.5
4 2 20
20.0
题意:现在你要烹饪一只鸡,给你k,d,t代表:锅的加热时间k,每隔d时间开启加热,煮熟鸡所需的总时间t。
思路:加热时,每分钟增加1分钟的烹饪时间,保温时,每分钟增加0.5的烹饪时间。
1:先特判一下直接输出t的:k==d时和k%d==0时,此时永久在加热,所以直接输出t。
2:如果k<d,那么从加热到保温结束,算一个周期,此时d就是周期长度,用t除以这个周期长度下的烹饪时间,直接取整得到需要几个整数周期,然后看烹饪时间够不够,不够那么剩下的时间必然不满一个周期,此时在加就可以了。
3:k>d,那么依然可以求出周期,周期长度不是d,而是d*x,x是使d*x刚好大于k时的值,(等于的情况我们在特判),这个值就是周期长度,然后和上面一样,用t整除取整求解。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
double k,d,t,r,len,ans,as;
int main()
{
while(~scanf("%lf%lf%lf",&k,&d,&t))
{
if(k==d||((ll)k%(ll)d==0))printf("%.1f\n",t); //特判直接输出t的
else
{
if(k<d){r=k+(d-k)/2.0;len=d;} //k<d时周期长度len,r是鸡的实际烹饪时间
else
{
r=k+((ll)(k/d)*d+d-k)/2.0; //此时k>d的情况
len=(ll)(k/d)*d+d;
}
as=(ll)((t/r))*r; //整数周期下已煮鸡的烹饪时间
ans=len*(ll)(t/r); //所花时间
if(t-as<=k)ans+=t-as; //最后不足一个周期所需时间
else ans+=k+(t-as-k)/0.5;
printf("%.1f\n",ans);
}
}
return 0;
}