Codeforces Round #413 A. Carrot Cakes
1 second
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.
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代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define ll long long using namespace std; int main ()
{
int n,t,k,d;
int i,a,j;
while (scanf("%d %d %d %d",&n,&t,&k,&d)!=EOF)
{
if (k >= n){ // 新机器建造完成之前 蛋糕就能全部完成
printf("NO\n"); continue;
}
int len = (n+k-)/k;
i = d/t; // 建造新机器的过程中旧机器完成了几次任务(包括正在完成的)
if (i == ) i == ; // 正在完成的
if (d%t) i ++; j = len - i; // 还剩余几次任务
a = min(max(i*t+t*(j/),d+t*(j-j/)),max(i*t+t*(j-j/),d+t*(j*))); // 有可能是新机器最后完成 也有可能是旧机器最后完成 if (a >= len*t)
printf("NO\n");
else
printf("YES\n");
}
return ;
}
思路比较麻烦,仅供参考哈!
Codeforces Round #413 A. Carrot Cakes的更多相关文章
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round#413 Div.2
A. Carrot Cakes 题面 In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, al ...
- Codeforces Round#413 Problem A - C
Problem#A Carrot Cakes vjudge链接[here] (偷个懒,cf链接就不给了) 题目大意是说,烤面包,给出一段时间内可以考的面包数,建第二个炉子的时间,需要达到的面包数,问建 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生
我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...
- Codeforces Round #413(Div. 1 + Div. 2, combined)——ABCD
题目在这里 A.Carrot Cakes 乱七八糟算出两个时间比较一下就行了 又臭又长仅供参考 #include <bits/stdc++.h> #define rep(i, j, k) ...
- Codeforces Round #542 B Two Cakes
B. Two Cakes time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)
http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 ...
- C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)
题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...
随机推荐
- 主流服务器虚拟化技术简单使用——KVM(二)
通过Linux工具管理KVM 主流服务器虚拟化技术简单使用——KVM(一)部署了一台KVM主机,提到KVM可以通过命令行工具(virt-install.virsh)和GUI工具(virt-manage ...
- Oracle之索引
简介 1.说明 1)索引是数据库对象之一,用于加快数据的检索,类似于书籍的索引.在数据库中索引可以减少数据库程序查询结果时需要读取的数据量,类似于在书籍中我们利用索引可以不用翻阅整本书即可找到想要的信 ...
- gcc 常用命令
gcc编译器 $ gcc -o XX.exe XXX.c ddd.c $ gcc -o XX.asm -S XXX.c 编译生成可执行文件,并执行程序,缺省的时候,gcc 编译出来的文件是a.out ...
- 更改kindeditor编辑器,改用支持h5的video标签替换原有embed标签
kindeditor是一款不错的可视化编辑器,不过最近几年似乎没在更新,现在h5趋于主流,正好有个业务需要编辑器支持mp4视频的播放,考虑到现在h5中的video标签的强大,于是决定将原来系统中的em ...
- restsharp 组件调用返回 gbk 编码的api,中文乱码解决方法。(restsharp response 中文乱码 gbk)
最近要调一个restful风格的api 用了 一个开源第三方组件,组件还是蛮好用的, 支持直接按参数定义实体类,然后发起请求之前直接 addobject 的方式就把请求参数给添加进去了, 解码的时候可 ...
- vue-webpack项目中调试的问题
在使用devtools的过程中,可以使用debugger.
- Python RawSocket Syn
#!/bin/env python # -*- coding: UTF-8 -*- # 必须以root权限运行 import socket import sys import time import ...
- Imgproc.findContours函数
OpenCV里支持很多边缘提取的办法,可是如何在一幅图像里得到轮廓区域的参数呢,这就需要用到findContours函数,这个函数在OpenCV4Android的原型为: void org.openc ...
- html控件
checkbox val = "<li class='layer'><label><input type='checkbox' checked name='la ...
- gihub简单学习 步步操作(简单易学)
一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...