CF - 799A. Carrot Cakes - 暴力+模拟

53 篇文章 0 订阅
22 篇文章 0 订阅

1.题目描述:

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

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".

Examples
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.

2.题意概述:

现在有n个胡萝卜,一个炉子,一个炉子可以同时做k个胡萝卜,做好需要t分钟,现在允许用d分钟再造一个相同的炉子,两个炉子可以同时工作,判断再建一个炉子是否可以缩短总时间

3.解题思路:

直接暴力地模拟描述的过程。为了做到这一点,我们需要两个变量t1和t2。在他们中,我们将存储每个烤箱将变得空闲的时间。在开始时t1等于0,t2等于d。

在模拟过程之后,我们将获得一个可能的时间,使用2个烤箱(这个时间等于t 1和t 2的最大值)n个蛋糕。只能将这个时间与值(n  +  k  -1)/  k · t进行比较 - 这可以使用仅一个烘箱来制作n个蛋糕的时间。

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int n, t, k, d;
int main()
{
	while (~scanf("%d%d%d%d", &n, &t, &k, &d))
	{
		int t1 = (n + k - 1) / k * t;
		int t2 = t1 - 1;
		int cnt = k * (t2 / t);
		if (t2 > d)
			cnt += k * ((t2 - d) / t);
		if (cnt >= n)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值