题意:
给一个锅,这个锅一次可以煎k个饼(每个饼都是只煎一面),花费一个小时,现在需要煎n个饼(两面都煎),最少需要多少个小时??
输入描述:
The first line has two integers N,K
1≤N,K≤100
输出描述:
Output the answer.
输入
3 2
输出
3
思路:
两种做法:
(1)需要煎两面,那么n个饼总共要煎2 * n个一面,那么答案就是2 * n / k向上取整。
(2)先煎一面,那么可以煎n / k * k个饼的一面,需要n / k个小时,这个时候剩下了n - n / k * k个两面都没煎的和n / k * k个已经煎过一面的。
这个时候把两面都没煎的和已经煎过一面的一部分凑成一锅,花费1个小时
最后只剩下一面没煎的饼了,假设有m个,那么花费时间就是m / k向上取整嘛
但是哪个是更优的方案呢???
起码评测机告诉我们第二个更优。。
但是实际上呢,这样想吧,假设我们现在要煎4个饼,但是k = 9,第一种答案是1(明显是错误的),第二种答案是2。。。。。
代码实现:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int main(){
int n,k;
scanf("%d%d",&n,&k);
int m = n % k;
int ans = n / k;
ans++;
int tmp = n - k + m;
ans += tmp / k;
if(tmp % k)
ans++;
printf("%d\n",ans);
return 0;
}