Codeforces Round #467 (Div. 2) C. Save Energy!

C. Save Energy!

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.

Input

The single line contains three integers kd and t (1 ≤ k, d, t ≤ 1018).

Output

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 .

Examples
input
Copy
3 2 6
output
6.5
input
Copy
4 2 20
output
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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值