CodeFroces 解题报告-799-A

CodeFroces 解题报告

Problem - A - Codeforces

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

Output

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

Examples

input

Copy

8 6 4 5

output

Copy

YES

input

Copy

8 6 4 6

output

Copy

NO

input

Copy

10 3 11 4

output

Copy

NO

input

Copy

4 2 1 4

output

Copy

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 6 minutes 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. 解题思路

这道题的整体思路不难,是一道模拟题,读完题目可以发现题目要求的就是比较不加炉子和加炉子的时间哪个更短。

我最开始的想法:直接计算两个的时间,不加炉子的时间是很好解决的,直接对整体时间上取整,但是问题来了(加两个炉子不好求,因为得需要先判断在一个炉子做完蛋糕的时候,另一个炉子是否建完(总之,比较复杂))

看了AC的代码之后发现,其实不用这么麻烦,根据常识可以推之,之所以需要加第二个炉子,是因为只用第一个炉子产出完成所用的时间t1是大于再建一个炉子的时间d的,如果t1>d,那么显然两个炉子工作的时间显然会短于一个炉子工作的时间,所以就是以下的AC代码。

3. 代码

1.错误代码(WA: in test 10)

// Problem: A. Carrot Cakes
// Contest: Codeforces - Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/799/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t,k,d;
	cin>>n>>t>>k>>d;
	int s1=0,s2=0;
	if(n%k)s1=n/k*t;
	else s1=(n/k+1)*t;
	s2=d;
	if(t==d&&k==n/2){
		cout<<"NO"<<endl;
		return 0;
	}
	if(s1>s2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

AC代码

// Problem: A. Carrot Cakes
// Contest: Codeforces - Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/799/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t,k,d;
	cin>>n>>t>>k>>d;
	int s=0;
	while(s<=d){
		n-=k;
		s+=t;
	}
	if(n>0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

4.复盘

可以看出,思维训练还是不足够的,接下来会继续更新(记录)思维题训练。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值