zoukankan      html  css  js  c++  java
  • Codeforces 937.C Save Energy!

    C. Save Energy!
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 kminutes 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
    Note

    In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready .

    In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.

    题目大意:炉子每过k分钟关掉,你每过d分钟去把炉子打开,炉子开着时,每分钟完成烧鸡的1/t,关着时,完成1/2t,求需要的用时.

    分析:一道比较繁琐的模拟题.关键是找出周期,也就是找到炉子第一次从关到开的状态所经过的时间. 先处理整个的循环节,然后再单独处理剩下的部分.

       需要对k和d的大小分类讨论.

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long ll;
    
    ll k,d,t,cnt,tot;
    double ans;
    
    void solve1()
    {
        tot = k * 2 + (d - k);
        ll jishu = cnt / tot;  //循环要弄多少次
        ll yushu = cnt % tot;  //余下的部分
        ans += jishu * d;
        if (yushu <= k * 2)
        {
            double temp = (double)(yushu / (double)2);
            ans += temp;
        }
        else
        {
            ans += k;
            yushu -= k * 2;
            ans += yushu;
        }
    }
    
    void solve2()
    {
        if (k % d == 0)
        {
            ans = (double)(cnt / (double)2);
            return;
        }
        else
        {
            ll cishu = k / d;
            cishu++;   //周期
            ll leftt = cishu * d - k;  //最后一个周期剩下的用余温的
            ll temp1 = cishu * d * 2 - leftt * 2;  //用火烧的能量
            ll temp2 = leftt;  //余温的能量
            ll temp = temp1 + temp2;  //总的能量
            ll zhouqi = cishu * d;  //周期多少分钟
            ll cishu2 = cnt / temp;  //烧多少个周期
            ans += zhouqi * cishu2;
            cnt %= temp;
            if (cnt <= temp1)
            {
                ans += (double)(cnt / (double)2);
                return;
            }
            else
            {
                cnt -= temp1;
                ans += cishu * d - leftt;
                ans += cnt;
            }
        }
    }
    
    int main()
    {
        cin >> k >> d >> t;
        cnt = 2 * t;
        if (d >= k)
            solve1();
        else
            solve2();
        printf("%.1lf
    ",ans);
    
        return 0;
    }
  • 相关阅读:
    有多少程序员超过四十岁呢?
    乔布斯的演讲技巧:教你站在讲台上怎样化腐朽为神奇
    想要好看的WORDPRESS模板
    多些时间能少写些代码
    java播放au音频程序
    明星软件工程师的10种特质
    中国互联网创业的四个机遇
    Android环境搭建
    想写代码?离开你的电脑吧!
    深讨Java SE 6 在 HTTP 方面的新特性(NTLM)
  • 原文地址:https://www.cnblogs.com/zbtrs/p/8473786.html
Copyright © 2011-2022 走看看