In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
The only line contains four integers n, t, k, d (1 ≤ n, t, k, d ≤ 1 000) — the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
8 6 4 5
YES
8 6 4 6
NO
10 3 11 4
NO
4 2 1 4
YES
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
题目大意:
有一个面包机每t分钟可以完成一次任务,每次任务可以制作k个蛋糕。
现在有n个蛋糕需要被制作,为了提高效率他可以在花费d分钟再制作一个面包机
在制作新机器的同时,旧机器依旧可以运作。新机器制作完成之后两台机器可以同时运转
他最多可以制作一台新面包机。
问重新制作一台面包机能否提高效率? 可以 YES 、 否NO
解题思路:
大致思路就是分别计算出制作一台新机器完成任务所花费的总时间和只使用旧机器完成任务的总时间,然后比较。
因为在制作新机器的同时,旧机器依旧可以运转,因为不好判断到底是新机器完成最后一次任务
还是旧机器完成最后一次任务。所以分两种情况计算,找出最优情况(即花费时间最少的)
AC代码:
1 #include2 #include 3 #include 4 #include 5 #include 6 #define ll long long 7 8 using namespace std; 9 10 int main ()11 {12 int n,t,k,d;13 int i,a,j;14 while (scanf("%d %d %d %d",&n,&t,&k,&d)!=EOF)15 {16 if (k >= n){ // 新机器建造完成之前 蛋糕就能全部完成17 printf("NO\n"); continue;18 }19 int len = (n+k-1)/k;20 i = d/t; // 建造新机器的过程中旧机器完成了几次任务(包括正在完成的)21 if (i == 0) i == 1; // 正在完成的22 if (d%t) i ++;23 24 j = len - i; // 还剩余几次任务25 a = min(max(i*t+t*(j/2),d+t*(j-j/2)),max(i*t+t*(j-j/2),d+t*(j*2))); // 有可能是新机器最后完成 也有可能是旧机器最后完成26 27 if (a >= len*t)28 printf("NO\n");29 else30 printf("YES\n");31 }32 return 0;33 }
思路比较麻烦,仅供参考哈!