ACM Exercise (eight) Lanzhou sesame seed time limit:MS | Memory limit:65535 KB 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
-
#include <iostream>
using namespace std;
int time (int n,int k)
{
if (n<=k && n!=0)
{
return 2;
}
else if (n==0)
{
return 0;
}
Else
{
if (2*n%k==0)
{
return 2*n/k;
}
Else
{
return 2*n/k+1;
}
}
}
int main ()
{
int n,k;
While (cin>>n>>k)
{
if (n<=100000 && k>=1)
{
cout<<time (n,k) <<endl;
}
}
return 0;
}
ACM Exercises (eight)