codeforces 936A Save Energy(数学思维)
2018-02-26 18:21
621 查看
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 k, d 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 .
题意: 要用微波炉烤一个面包,已知此微波炉开一次能烤k分钟,而每过d分钟,jury都会检查一次微波炉是否在工作,如果在工作则什么都不做,如果不在工作则把它打开。已知整个面包在微波炉工作的时候需要t分钟才能烤熟,若微波炉不工作的时候,依靠余温需要2t分钟才能烤熟,问总共需要多少分钟可以烤熟。(初始微波炉是开着的,并且只要一熟就可以拿出来)。
解法: 这道题主要要想到周期,微波炉开和关组成一个周期,然后只需计算出一个周期可以把面包烤成几成熟(这里几成熟可以用时间替代),需要经过几个周期,最后只需特殊处理要最后一个不完整的周期即可。
周期 T = ((k-1)/d+1)*d , 这里 (k-1)/d+1 代表向上取整。
例如 k = 3 d = 5 , T = 5 。 k = 5 d = 3 , T = 6 。
注意整形和浮点型的转换!!! 以及取整的细节
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 k, d 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 .
题意: 要用微波炉烤一个面包,已知此微波炉开一次能烤k分钟,而每过d分钟,jury都会检查一次微波炉是否在工作,如果在工作则什么都不做,如果不在工作则把它打开。已知整个面包在微波炉工作的时候需要t分钟才能烤熟,若微波炉不工作的时候,依靠余温需要2t分钟才能烤熟,问总共需要多少分钟可以烤熟。(初始微波炉是开着的,并且只要一熟就可以拿出来)。
解法: 这道题主要要想到周期,微波炉开和关组成一个周期,然后只需计算出一个周期可以把面包烤成几成熟(这里几成熟可以用时间替代),需要经过几个周期,最后只需特殊处理要最后一个不完整的周期即可。
周期 T = ((k-1)/d+1)*d , 这里 (k-1)/d+1 代表向上取整。
例如 k = 3 d = 5 , T = 5 。 k = 5 d = 3 , T = 6 。
注意整形和浮点型的转换!!! 以及取整的细节
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <queue> #include <vector> #include <cmath> using namespace std; #define fre freopen("/Users/user/Desktop/in.txt","r",stdin); #define ofre freopen("/Users/user/Desktop/out.txt","w",stdout); #define CLR(s) memset(s,0,sizeof(s)); #define all(x) x.begin(), x.end() typedef long long ll; int main(){ ll k,d,t; 4000 cin >> k >> d >> t; ll T = ((k-1)/d+1)*d; double ans = 0; double oneT = (T-k)*0.5+k; // 1个周期可以烤成 oneT ans += ll(t/oneT)*T; ll ht = t/oneT; double st = t-ht*oneT; // 剩余还需 st if(st < k) ans += st; else{ ans = ans+k+(st-k)*2; } printf("%.1lf\n", ans); return 0; }
相关文章推荐
- Codeforces 807C Success Rate【二分+数学思维】
- Codeforces 233B:Non-square Equation(数学+思维)
- (CodeForces 883A) The Meaningless Game 纯正的数学思维题(有点卡cin时间)
- 51nod 1421 最大MOD值 & codeforces 485D Maximum Value(思维 数学)
- Codeforces 550C Divisibility by Eight【数学思维题】好题!
- codeforces 560C Gerald's Hexagon (数学+思维)
- CodeForces 626B Cards(数学思维)
- Codeforces 570B Simple Game 概率求解,简单数学思维
- Codeforces 789A Anastasia and pebbles(数学,思维题)
- CodeForces - 899D Shovel Sale 数学+思维
- 【Codeforces-402B】-Weird Rounding(数学,思维)
- Codeforces400E - Inna and Binary Logic - 思维、数学
- Codeforces - 500D. New Year Santa Network - 树形dp、数学、思维
- Codeforces 233B Non-square Equation (数学+思维)
- Codeforces 599D Spongebob and Squares【思维枚举+数学方程】
- CodeForces 876B Divisiblity of Differences(思维 + 数学)
- CodeForces - 540B School Marks (数学思维题 中位数)
- Codeforces 758C Unfair Poll 【数学】【思维】
- 【Codeforces 869 C The Intriguing Obsession】& 组合数学 & 思维
- Codeforces 357D Xenia and Hamming【数学+思维】