第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)M-Cook Pancakes!

题目

In China, there is a very famous problem about pancakes: You have a pan and you can fry two pancakes at the same time each time. For a pancake, its front and back sides need to be cooked, and it takes one hour for each side to be cooked.

So how long does it take at least to cook 3 pancakes? The answer is three hours:

In the first hour, fry the front of No.1 pancake and the front of No.2 pancake.

In the second hour, fry the back of No.2 pancake and the front of No.3 pancake.

In the third hour, fry the back of No.1 pancake and the back of No.3 pancake.

Now you have a pan and you can fry KK pancakes at the same time each time. How many hours does it takes at least to cook NN pancakes?

It’s noticed that you have to fry some side of the pancake until fully cooked every time, it means that you can’t fry some side of the pancake half-cooked and taking it out. So the answers are always integers.
在这里插入图片描述
在这里插入图片描述

题意

一口锅可以同时煎制k个饼,每张饼两面都需要煎制,每一面需要煎1小时,问最快把n张饼全部煎好需要多少小时

思路

共有n张饼就意味着如果一张一张煎制的话总时间是2*n 但是现在可以同时煎制
如果 2 ∗ n % k = 0 2*n\%k=0 2n%k=0 就可以每次都放上去k张,这样答案就是 2 ∗ n / k 2*n/k 2n/k
如果 2 ∗ n % k ! = 0 2*n\%k!=0 2n%k!=0 就可以像题目那样交叉着煎制,到最后把小于k的剩余饼全都放上去煎制好就成了,答案是 2 ∗ n / k + 1 2*n/k+1 2n/k+1

代码

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n,k;
    cin>>n>>k;
    int now = 2 * n / k + (2 * n % k == 0?0:1);
    if(now < 2) now = 2;
    cout<<now;
}
 
/*
 
4 2 4
4 3 3
4 4 2
4 5 2
4 6 2
4 8 1
 
*/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值