URAL 1820. Ural Steaks

来源:互联网 发布:教学软件介绍 编辑:程序博客网 时间:2024/06/06 04:49

1820. 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 ≤ nk ≤ 1000).

Output

Output the minimal number of minutes in which the chef can cook n steaks.

Sample

inputoutput
3 2
3

用最短的时间内煎牛排,算法个人觉得不是很好想。

如果n小于等于k的话就很好办了,2分钟就可以煎完。

n大于k时,如果2*n%k=0的话,2*n/k的时间就可以全部完成;如果不等于0的话就在2*n/k的基础上加1就行了。

#include <cstdio>#include <iostream>using namespace std;int main(){    int n,k,t,m;    while(cin>>n>>k)    {        t=2*n/k;        m=2*n%k;        if(n<=k)            cout<<2<<endl;        else{        if(m==0)            cout<<t<<endl;        else            cout<<t+1<<endl;        }    }    return 0;}


0 0
原创粉丝点击