Problem statement
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
| |
Sample Output
| |
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
| |
Problem link: [NYOJ][799] Lanzhou Pancake