codefoces-A. Feed the cat
题目链接
A. Feed the cat
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there’s only one cat). The cat’s current hunger level is H points, moreover each minute without food increases his hunger by D points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn’t take time to get to the store and back). One such bun costs C roubles and decreases hunger by N points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.
Input
The first line contains two integers hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59) — the time of Andrew’s awakening.
The second line contains four integers H, D, C and N (1 ≤ H ≤ 105, 1 ≤ D, C, N ≤ 102).
Output
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10 - 4.
Formally, let your answer be a, and the jury’s answer be b. Your answer is considered correct if .
Examples
input
19 00
255 1 100 1
output
25200.0000
input
17 41
1000 6 15 11
output
1365.0000
Note
In the first sample Andrew can visit the store at exactly 20:00. The cat’s hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it’s optimal to visit the store right after he wakes up. Then he’ll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.
题意:就是一个数学问题,让你计算买东西的钱怎样才最节减。
这算是一个高中时很容易做的算术题吧。
首先,给的条件是:一个人买吃的喂猫,猫每分钟的饥饿度会增加。当时间再八点之后(包含八点)买,给一个优惠八折。
那么数据是这样的,给一个你去买的时间,h(点),m(分);
再给你初始猫的饥饿度H,每分钟增加的饥饿度D,买一个面包需要用的钱C(只有面包),最后是花费C这么多钱可以让猫减少的饥饿度为N;
买的时间和猫吃面包的时间都不用考虑;
问你是什么时候去买能更少的花钱让猫吃饱;
解题:
分析问题:
其实就是考虑八点前去买和八点后(包含八点)去买那个更花费少的钱就能喂饱猫;
考虑八点前是有两种的,一种是直接买,另一种的等到刚刚好八点再买;然后比较它们那个花钱更少;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll hh,mm,h,d,c,n;
cin >> hh >> mm >> h >> d >> c >> n;
if(hh < 20)
{
double cur = (h / n + (h%n != 0))*1.0 * c;//这个是考虑直接买需要用的钱,如果差一点点够,也需要买多一个;
double cut = (((20 * 60 - hh*60 - mm)*d + h)/n + (((20 * 60 - hh*60 - mm)*d+h)%n != 0)) * c * 0.8;//不够八点但可以凑够八点再买,这个是一个贪心策略;
printf("%.4f\n",min(cur,cut));
}
else
printf("%.4f\n", (h / n + (h%n != 0))*0.8 * c);//直接是八点和八点以后;
}