我是靠谱客的博主 爱笑夕阳,这篇文章主要介绍codeforces 1A - math - ceil,现在分享给大家,希望可以做个参考。

2017-08-24 15:42:30

writer: pprp

感觉自己好菜啊,这个题都没有做的很好

题意很简单,用a * a 的地砖,将 n * m 的地板铺满,问最少需要多少个地砖?

一开始打算分情况讨论,恰好铺满某一行,某一列,分了很多种情况,(贪心的去选择)

但是其实根本没有必要那么做,用向上取整函数就可以搞定了,也很容易理解

但是这个题其实在数据比较大的时候会溢出,所以用long long

在数据比较长的时候用cout可能会出现1e n的形式不满足要求

所以还是要补充一下

1、floor & ceil的知识点

2、cout 的精度设置


1、floor & ceil

  都是在math.h的头文件下的函数

  函数形式: double floor( double x )向下取整 

          double ceil ( double x ) 向上取整

  注意返回类型是double

2、cout的其他函数及用法

  在iomanip头文件下的函数

  setprecition(n)对浮点数类型设置精度

  std :: fixed 将整数类型的以整数的形式输出

  std :: scientific 将整数以科学计数法形式输出(与fixed相对性)

代码如下:

/*
theme:铺地砖
writer:pprp
declare:虽然很简单,但是依然没有做的很好,
里面cout的有些知识点没有把握清楚,
还有ceil的用法也不是很清楚
date:2017/8/23
*/
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long ll;
int main()
{
ll width, height;
double a;
//
scanf("%lld%lld%lld",&width,&height,&a);

srand((int)time(NULL));
for(int i = 0 ; i < 10 ; i++)
{
srand((int)time(NULL)+i);
width = rand() % 100;
height = rand() % 100;
a = rand() % 100;
cout << width <<" " << height << " " << a << endl;
//如果将width和height设为ll就用这种方法
//
printf("%lfn",(width/a + (width%a == 0 ? 0 : 1)) * (height/a + (height%a == 0 ? 0:1)));
//或者采用向上取整的方法,涉及到cout用法
printf("%lfn",ceil(width/a) * ceil(height/a));
cout<<fixed<<setprecision(0)<<ceil(width/a)*ceil(height/a)<<endl;
}
return 0;
}

 

转载于:https://www.cnblogs.com/pprp/p/7423570.html

最后

以上就是爱笑夕阳最近收集整理的关于codeforces 1A - math - ceil的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(134)

评论列表共有 0 条评论

立即
投稿
返回
顶部