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 ...
随机推荐
- python之打印九九乘法表
配置环境:python 3.6 python编辑器:pycharm 整理成代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- #九九乘法表 #分析:九 ...
- linux文件操作篇 (三) 文件状态和操作属性
#include <sys/stat.h> int fstat(int fildes, struct stat *buf); 获取文件信息 int lstat(const char* ...
- C++ 指针初始化要注意的地方
1. 声明多个指针的时候: int* P1,P2; 如上所示,声明的是创建一个指针P1和一个int型的变量P2.而不是声明的两个指针. 对每个指针变量名,都需要使用一个*. 在C++中,int* 是一 ...
- Android面试收集录 网络与加密
1.创建Socket对象需要至少指定哪些信息? IP(或域名)和端口号 Socket socket=new Socket("www.baidu.com",80); 2.如何使用So ...
- 介绍PHP的自动加载
昨天面试被问到了 PHP 的自动加载机制,因为很多概念模糊啦,没回答好,今天特意来总结一下. include 和 require 是PHP中引入文件的两个基本方法,但是每个脚本的开头,都需要包含(in ...
- Android开发——Google关于Application Not Responding的建议
秒内没有执行完毕. 2. 避免ANR的一些建议 Android applications normally run entirely on asingle (i.e. main) thre ...
- 初步学习pg_control文件之三
接前文,初步学习pg_control文件之二 继续学习: 研究 DBState,先研究 DB_IN_PRODUCTION ,看它如何出现: 它出现在启动Postmaster时运行的函数处: /* * ...
- ReentrantLock类的hasQueuedPredecessors方法和head节点的含义
部分启发来源自文章:Java并发编程--Lock PART 1 1.如果h==t成立,h和t均为null或是同一个具体的节点,无后继节点,返回false.2.如果h!=t成立,head.next是否为 ...
- 【数据库】 SQL SERVER 2012 实用新特性
[数据库] SQL SERVER 2012 实用新特性 官方链接 一. ALWAYS ON - 灾难恢复 二. 列存储索引 - 比非聚集索引效率高,但有索引表不允许修改数据(插入,更新,删除),用于读 ...
- python下的自动化测试--selenium 验证码输入问题
之前一直在研究scrapy下数据抓取,在研究ajax数据抓取时碰巧研究了一下selenium,确实很实用,不过只做scrapy下的数据抓取,不怎么合适,一是性能的损耗,一直需要开一个浏览器,二是对于爬 ...