CodeFroces 解题报告
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.复盘
可以看出,思维训练还是不足够的,接下来会继续更新(记录)思维题训练。