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 * + (d - k);
ll jishu = cnt / tot; //循环要弄多少次
ll yushu = cnt % tot; //余下的部分
ans += jishu * d;
if (yushu <= k * )
{
double temp = (double)(yushu / (double));
ans += temp;
}
else
{
ans += k;
yushu -= k * ;
ans += yushu;
}
} void solve2()
{
if (k % d == )
{
ans = (double)(cnt / (double));
return;
}
else
{
ll cishu = k / d;
cishu++; //周期
ll leftt = cishu * d - k; //最后一个周期剩下的用余温的
ll temp1 = cishu * d * - leftt * ; //用火烧的能量
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));
return;
}
else
{
cnt -= temp1;
ans += cishu * d - leftt;
ans += cnt;
}
}
} int main()
{
cin >> k >> d >> t;
cnt = * t;
if (d >= k)
solve1();
else
solve2();
printf("%.1lf\n",ans); return ;
}

Codeforces 937.C Save Energy!的更多相关文章

  1. CodeForces 937C Save Energy! 水题

    题意: 一个炉子烤鸡,炉子打开的时候一共$T$分钟可以烤完,关闭的时候一共$2T$分钟可以烤完,炉子每$K$分钟自动关闭,厨师每$D$分钟回来检查,打开炉子 问多长时间烤完.. 题解: 用整数写比较稳 ...

  2. Codeforces 937 D. Sleepy Game(DFS 判断环)

    题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...

  3. Codeforces 937.D Sleepy Game

    D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces 937.B Vile Grasshoppers

    B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. 【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)

    没有参加,但是之后几天打了哦,第三场AK的CF比赛. CF大扫荡计划正在稳步进行. [A]Olympiad 题意: 给\(n\)个人颁奖,要满足: 至少有一个人拿奖. 如果得分为\(x\)的有奖,那么 ...

  6. Codeforces Round #467 (div.2)

    Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...

  7. Overview and Evaluation of Bluetooth Low Energy: An Emerging Low-Power Wireless Technology

    转自:http://www.mdpi.com/1424-8220/12/9/11734/htm Sensors 2012, 12(9), 11734-11753; doi:10.3390/s12091 ...

  8. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  9. Codeforces Round #467 Div.2题解

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

随机推荐

  1. idea 普通文件夹 转换成 module

    经常会遇到从GitHub上download的progect在idea里面打开是普通文件夹形式,而并不是我们想要的module形式(文件夹图标右下角有个蓝色的tag),那么如何快速转换成我们想要的mod ...

  2. 记一次MD5妙用

    记一次MD5妙用 最近项目组中在做历史记录的改造工作,主持讨论了多次,但每次讨论完都觉的很完美了,但实际在写这部分逻辑的时候还是会发现一些问题出来,很难受,反反复复的暴露智商是硬伤,人艰不拆,暂先不扯 ...

  3. $.ajax()各方法详解(转)

    jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(p ...

  4. Unity 对象的批处理

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52813834 作者:car ...

  5. 年薪20万Python工程师进阶(7):Python资源大全,让你相见恨晚的Python库

    我是 环境管理 管理 Python 版本和环境的工具 pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. virtualenv – 创建独立 Python 环 ...

  6. mysql 5.7.19 zip版本 windows安装步骤

    请注意此文档用于msyql5.7系列及以后版本(包括最新 mysql 8.0.11)zip版本windows下的安装1.下载mysql省略2.解压mysql到D:\Program Files\mysq ...

  7. leetcode笔记--6 Add Digits

    question: Given a non-negative integer num, repeatedly add all its digits until the result has only ...

  8. Spring MVC 开发 配置

    1.首先在web.xml中配置一个DispatcherServlet,并通过<servlet-mapping>指定需要拦截的url. 下面xml中配置一个拦截.html为后缀的url. & ...

  9. Django笔记 —— 基础部分总结

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  10. iOS笔记054 - 核心动画

    注意事项 :locationInView和translationInView // 返回相对于控件自身内部触摸点的位置 [pan locationInView:self]; // 返回两个触摸点之间的 ...