兰州烧饼
2017-06-24 16:08
176 查看
兰州烧饼
时间限制:1000 ms | 内存限制:65535 KB难度:1
描述烧饼有两面,要做好一个兰州烧饼,要两面都弄热。当然,一次只能弄一个的话,效率就太低了。有这么一个大平底锅,一次可以同时放入k个兰州烧饼,一分钟能做好一面。而现在有n个兰州烧饼,至少需要多少分钟才能全部做好呢?
输入依次输入n和k,中间以空格分隔,其中1 <= k,n <= 100000
输出输出全部做好至少需要的分钟数
样例输入
3 2
样例输出
3
提示如样例,三个兰州烧饼编号a,b,c,首先a和b,然后a和c,最后b和c,3分钟完成
上传者
勿念情
问题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=779
问题分析:
输入n个饼子,那就是一共有2*n个面
当n<=k时,一分钟只能热n个面,所以要2分钟。
当n>k时,一共2*n个面,所以需要2*n/k分钟,注意结果要向上取整,即最后一次热时放不满k个饼子。
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
/*freopen("file/input.txt","r",stdin);
freopen("file/output.txt","w",stdout);*/
int n,k;
while(scanf("%d%d",&n,&k)!=EOF) {
if(n<=k){
printf("2\n");
}else{
printf("%.0lf\n",ceil((double)(2*n)/k));
}
}
return 0;
}
代码分析:
ceil函数
函数名: ceil
用 法: double ceil(double x);
功 能: 返回大于或者等于指定表达式的最小整数
头文件:math.h
返回数据类型:double
对应的向下取整函数为floor:
函数名: floor
用 法: double floor(double x);
功 能: 返回小于或者等于指定表达式的最小整数
头文件:math.h
返回数据类型:double