Codeforces 937.C Save Energy!
1 second
256 megabytes
standard input
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.
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
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!的更多相关文章
- CodeForces 937C Save Energy! 水题
题意: 一个炉子烤鸡,炉子打开的时候一共$T$分钟可以烤完,关闭的时候一共$2T$分钟可以烤完,炉子每$K$分钟自动关闭,厨师每$D$分钟回来检查,打开炉子 问多长时间烤完.. 题解: 用整数写比较稳 ...
- Codeforces 937 D. Sleepy Game(DFS 判断环)
题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...
- Codeforces 937.D Sleepy Game
D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 937.B Vile Grasshoppers
B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)
没有参加,但是之后几天打了哦,第三场AK的CF比赛. CF大扫荡计划正在稳步进行. [A]Olympiad 题意: 给\(n\)个人颁奖,要满足: 至少有一个人拿奖. 如果得分为\(x\)的有奖,那么 ...
- Codeforces Round #467 (div.2)
Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...
- 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 ...
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #467 Div.2题解
A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
随机推荐
- pyecharts数据分析及展示
仅仅从网上爬下数据当然是不够用的,主要还得对数据进行分析与展示,大部分人都看重薪资,但是薪资数据有的是*k/月,有的是*万/月,还有*万/年等等,就要对数据进行清理 将所有单位统一化,全部换算成统一单 ...
- DJANGO2.0 关联表的必填 ON_DELETE
DJANGO2.0 关联表的必填 ON_DELETE 参数的含义 - BUXIANGHEJIU 的博客 - CSDN 博客 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...
- 使用source命令解决mysql导入乱码问题
设定编码格式:mysql -u root -p --default-character-set=utf8 use dbname source /root/newsdata.sql
- (译)JavaScript 中的正则表达式(RegEx)实操——快速掌握正则表达式,伴有随手可练的例子————(翻译未完待续)
(原文:https://blog.bitsrc.io/a-beginners-guide-to-regular-expressions-regex-in-javascript-9c58feb27eb4 ...
- Zookeeper系列(二) Zookeeper配置说明
在配置ZooKeeper配置文件时,有些参数是必需的,有些参数是可选的,这些必需的参数构成了Zookeeper配置文件的最低配置要求,如果需要对ZooKeeper进行更详细的配置,可以 ...
- WPF中InkCanvas(墨水面板)用法
原文:WPF中InkCanvas(墨水面板)用法 WPF中InkCanvas(墨水面板)用法 ...
- Spring研磨分析、Quartz任务调度、Hibernate深入浅出系列文章笔记汇总
Spring研磨分析.Quartz任务调度.Hibernate深入浅出系列文章笔记汇总 置顶2017年04月27日 10:46:45 阅读数:1213 这系列文章主要是对Spring.Quartz.H ...
- 如何从海量IP中提取访问最多的10个IP
算法思想:分而治之+Hash 1.IP地址最多有2^32=4G种取值情况,所以不能完全加载到内存中处理: 2.可以考虑采用分而治之的思想,按照IP地址的Hash(IP) % 1024的值,把海量IP日 ...
- 零基础学习Vim编辑器
**********************************************************************0.这篇教程的简介:Vim是Linux/Unix下的经典编辑 ...
- jmeter对请求参数的签名处理
1.首先在本地写好签名的算法,本文采用RSA签名. public final class Base64 { static private final int BASELENGTH = 128; sta ...