Lanzhou Sesame seed time limit: +Ms | Memory Limit:65535KB Difficulty:1
-
-
Describe
- Sesame Cake has two sides, to do a good job of Lanzhou sesame cake, both sides are hot. Of course, you can only get one at a time, the efficiency is too low. There is such a big pan, can at the same time into the K-Lanzhou sesame cake, a minute can do a good side. And now there are n a Lanzhou sesame seed, at least how many minutes to do all the good?
-
-
Input
-
-
Enter N and K in turn, separated by spaces, where 1 <= k,n <= 100000
-
-
Output
-
-
output all do at least the required number of minutes
-
-
Sample input
-
-
3 2
-
-
Sample output
-
-
3
-
-
Tips
-
As a sample, three Lanzhou sesame seed number a,b,c, first A and B, then A and C, finally B and C, 3 minutes to complete
Problem Solving Ideas:
The problem compared to the pit dad is a number of test data, and the topic is not mentioned.
It is also important to note that when n>=k, it takes two minutes.
Other only need the formula (N*2)/k can
Use the three-mesh operator to
program code;
#include <stdio.h>int main () {int n,k;while (scanf ("%d%d", &n,&k)!=eof) {if (n<=k) printf ("2\n"); else{ if (((n*2)%k) ==0) printf ("%d\n", (n*2)/k); elseprintf ("%d\n", (n*2)/k+1);}} return 0;}
In addition, read the best code learned to use a statement: printf ("%d\n", ((n*2)/k==0)?
(n*2)/k:(n*2)/k+1);
To replace if (((n*2)%k) ==0)
printf ("%d\n", (n*2)/k);
Else
printf ("%d\n", (n*2)/k+1);
Lanzhou Sesame Cake