Codeforces 102263H-Steaks【数学】 难度:*

题意:

Motasem wants to cook n steaks (the steak consists of two faces) for his friends, and each face of the steak needs to be cooked for 5 minutes. Unfortunately, his pans can only fit 2 steaks at a time, and he only has k pans. If Motasem is cooking his steaks optimally, what is the minimum number of minutes he needs to cook all n steaks?

Input
A single line containing two space separated integers n,k (1≤n,k≤109) represent the number of steaks and pans respectively.

Output
A single integer represents the minimum time needed to cook all steaks

Example
inputCopy
3 1
outputCopy
15

题解:

一个平底锅可以放两张饼,一张饼需要烙两面,给n个饼和k个锅,烙熟需要5分钟,问最短多久可以烙完。
这道题我们可以把一张饼分离成两面,这样n个饼就变成了2n个面,因此每5分钟可以烙的数量为2k张面,接下来就很容易了。只是需要额外讨论一下当n/k<2时,10分钟即可搞定。

代码:

#include<stdio.h>
int main()
{
	long long a,b;
	scanf("%lld%lld",&a,&b);
	if(a/b<2)printf("10\n");
	else
	{
		if((a*2)%(b*2)!=0)printf("%lld\n",(a/b+1)*5);
		else printf("%lld\n",(a/b)*5);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42921101/article/details/104448144