zoukankan      html  css  js  c++  java
  • Codeforces Round #413 A. Carrot Cakes

    A. Carrot Cakes
    time limit per test  
    1 second
    memory limit per test  
    256 megabytes
     

    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.

    Input

    The only line contains four integers ntkd (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.

    Output

    If it is reasonable to build the second oven, print "YES". Otherwise print "NO".

     
    input
    8 6 4 5
    output
    YES
    input
    8 6 4 6
    output
    NO
    input
    10 3 11 4
    output
    NO
    input
    4 2 1 4
    output
    YES

    Note:

    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 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <stdlib.h>
     5 #include <algorithm>
     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
    "); 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
    ");
    29         else
    30             printf("YES
    ");
    31     }
    32     return 0;
    33 }

    思路比较麻烦,仅供参考哈!

  • 相关阅读:
    php 转化整型需要注意的地方
    生成6位随机数
    php://input
    ios常见问题 经验之谈
    ios 从前台返回到回台 从后台返回到前台 或者 支付宝支付订单后 对界面进行操作
    ios根据文本自适应 然后 搭建类似如下效果
    iosTableView 局部全部刷新以及删除编辑操作
    ios打开系统自带APP
    iOS通过URL Scheme启动app(收集了常用的app的URL Scheme)
    ios UIApplocation 中APP启动方式
  • 原文地址:https://www.cnblogs.com/yoke/p/6843808.html
Copyright © 2011-2022 走看看