[NYOJ] [v1-799] Lanzhou Pancake

Problem statement

兰州烧饼
Time limit: 1000 msMemory limit: 64 MB

Description

A pancake has two sides. You have one large griddle that can hold k Lanzhou pancakes at a time, and one minute cooks one side. Given n pancakes, what is the minimum number of minutes needed to cook all of them?

Input

n and k, separated by a space, where 1 <= k, n <= 100000.

Output

The minimum number of minutes needed to cook every pancake.

Sample Input

1
3 2

Sample Output

1
3

Hint

For the sample: pancakes a, b and c — first a and b, then a and c, finally b and c. Done in 3 minutes.

Analysis

Let’s make this brain teaser the 200th node~ I did one on ZZULI before where the pan held exactly 2 this one has k as a variable

Still, the same idea applies: look for the pattern

—–k=1—–
whatever you do, it takes n*2
—–k=2—–
2 when n==1, otherwise n
2 when n<3
3 when n=4/5
4 when n=6
……
—–……—–

Then you notice the answer depends on
n*2/k

that is, the smallest value not below n*2/k

And when n<k
it always takes 2 minutes

So the code is

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include<stdio.h>
#include<math.h>
int main() {
	int n,k;
	while(scanf("%d %d",&n,&k)!=EOF) {
		if(n<=k)
			printf("2\n");
		else
			printf("%.lf\n",ceil(n*2.0/k));
	}
	return 0;
}

Problem link: [NYOJ][799] Lanzhou Pancake

Loading...