您的位置:首页 > 其它

URAL 1820 Ural Steaks (贪心)

2015-03-04 14:38 316 查看


Ural Steaks

Time limit: 0.5 second

Memory limit: 64 MB

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

inputoutput
3 2

3


题意:n块饼,一个每次可以煎k块饼的平底锅,每块饼需要煎两面,每面煎一分钟即可,问煎完n块饼的最少时间。

解析:先让所有的饼都先煎一面,然后再考虑煎第二面,同时尽量让锅的空间尽可能利用。当2*n%k == 0时,通过这样的顺序调整,我们可以让所有锅空间都利用上,直接计算总面数即可;否则,我们就要加上一次多余的。

AC代码:

#include <iostream>
using namespace std;

int main(){
    int n, k, ans;
    while(cin>>n>>k){
        if(n <= k) ans = 2;
        else{
            ans = 2 * n / k;             //直接按面数计算即可
            if(2 * n % k) ans ++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: