After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered
n specialty steaks. Each steak is cooked by frying each of its sides on a frying pan for one minute.
Unfortunately, the chef has only one frying pan, on which at most
k steaks can be cooked simultaneously. Find the time the chef needs to cook the steaks.
Input
The only input line contains the integers
n and
k separated with a space (1 ≤
n,
k ≤ 1000).
Output
Output the minimal number of minutes in which the chef can cook
n steaks.
Sample
input | output |
---|---|
3 2 | 3 |
看起来很简单的题目,但是却会让不少人栽跟斗。
主要考审题能力,理解能力,IQ。再次教训我读题要仔细,理解透切才好解题。
考点: 牛排是不能同时煎两面的
所以,如果写3*2/2 = 3这样的公式就肯定错了。
思路:先处理一面牛排,然后处理没有煎的牛排的一面和处理过的牛排的另一面,然后再翻没翻面的牛排,最后再得出结果。
#include <iostream>
using namespace std;
void UralSteaks()
{
int a = 0, b = 0, t = 0;
cin>>a>>b;
if (a <= b) cout<<2<<endl;
else
{
t = a / b;//第一面
int left = a % b;//剩下一面都没处理的
a = t * b + left;//优先处理没处理过的
t += a / b;
a = a % b + left;//反转left
t += a / b;
if ( a % b ) t++;
cout<<t<<endl;
}
}