URAL 1820 Ural Steaks (机智)

Description

\(n\)块牛排要烤,每块牛排要正反两面各烤一次,每次用时\(1\)分钟,烤炉一次最多放\(k\)块牛排,问烤完这\(n\)块牛排最少用几分钟。

Input

两个整数\(n\)\(k\)\(1 \leqslant n,k \leqslant 1000\))。

Output

一个整数,表示短用时。

Sample Input

3 2

Sample Output

3

Solution

\(n\)块牛排共有\(2n\)个面,先烤每块牛排的第一面,如果有剩余就并到第二面中一起烤,这样烤的总次数最少,为\(\lceil \frac{2n}{k} \rceil\)。注意当\(n \leqslant k\)时必须烤两次。

Code

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10;

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    if (n <= k) printf("2\n");
    else printf("%d\n", (2 * n + k - 1) / k);
    return 0;
}

https://vjudge.net/problem/URAL-1820

posted @ 2017-08-08 20:04  达达Mr_X  阅读(151)  评论(0编辑  收藏  举报