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 = ; i < ; i++)
{
srand((int)time(NULL)+i); width = rand() % ;
height = rand() % ;
a = rand() % ; cout << width <<" " << height << " " << a << endl; //如果将width和height设为ll就用这种方法
// printf("%lf\n",(width/a + (width%a == 0 ? 0 : 1)) * (height/a + (height%a == 0 ? 0:1))); //或者采用向上取整的方法,涉及到cout用法
printf("%lf\n",ceil(width/a) * ceil(height/a)); cout<<fixed<<setprecision()<<ceil(width/a)*ceil(height/a)<<endl;
} return ;
}
codeforces 1A - math - ceil的更多相关文章
- Math.ceil(a/b)结果出错--原因是a和b不是double
脑袋短路.连续测试几次发现Math.ceil(188/20)==9; 忍无可忍,突然发现是int问题,顺着表达式走一遍,188/20==9,然后再向上取整.脑袋僵化了.看来一直做简单的不动脑筋的工作, ...
- Javascript Math.ceil()与Math.round()与Math.floor()区别
Math.ceil()向上舍入 1 2 3 alert(Math.ceil(20.1)) //输出 21 alert(Math.ceil(20.5)) //输出 21 alert(Math.ceil( ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...
- Javascript Math ceil()、floor()、round()三个函数的区别
Round是四舍五入的...Ceiling是向上取整..float是向下取整. ceil():将小数部分一律向整数部分进位. 如: Math.ceil(12.2)//返回13 Math.ceil(12 ...
- 数学对象Math ceil()、floor()、round()方法
Math.ceil() 功能:对一个数进行上取整. 语法:Math.ceil(x) 参数: x:一个数值. 返回值:返回大于或等于x,并且与之最接近的整数. 注:如果x是正数,则把小数“入”: ...
- javascript中Math ceil(),floor(),round()三个函数的对比
Math.ceil()执行的是向上舍入 Math.floor()执行向下舍入 Math.round()执行标准舍入 一下是一些补充: ceil():将小数部分一律向整数部分进位. 如: Math.ce ...
- Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结
一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...
- Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?
Math.round(x) 四舍五入 加上0.5向下取整 Math.round(1.5) 2 Math.round(-11.5) -11 Math.round(-11.2) -10 Math.ceil ...
- JS中的Math.ceil和Math.floor函数的用法
Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入 Math.floor(x)--返回小于等于数字参数的最大整数,对数字进行下舍入 例如: document. ...
随机推荐
- 提交任务到spark master -- 分布式计算系统spark学习(四)
部署暂时先用默认配置,我们来看看如何提交计算程序到spark上面. 拿官方的Python的测试程序搞一下. qpzhang@qpzhangdeMac-mini:~/project/spark-1.3. ...
- HBase 二次开发 java api和demo
1. 试用thrift python/java以及hbase client api.结论例如以下: 1.1 thrift的安装和公布繁琐.可能会遇到未知的错误,且hbase.thrift的版本 ...
- retry 使用
retry是用来实现重试的 from retry import retry @retry(tries=5, delay=2) def do_something(): xxx do_something( ...
- docker安装入门
docker安装入门 https://blog.csdn.net/earbao/article/details/49683175
- 002-shell变量定义、使用、字符串、数组、注释
一.变量定义 定义变量时,变量名不加美元符号($) name="lhx" 注意,变量名和等号之间不能有空格.同时,变量名的命名须遵循如下规则: 命名只能使用英文字母,数字和下划线, ...
- 001-shell基础,创建,运行
一.概述 Shell 是一个用 C 语言编写的程序.Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服 ...
- HBase存储架构
以下的介绍是基于Apache Hbase 0.94版本: 从HBase的架构图上可以看出,HBase中的存储包括HMaster.HRegionServer.HRegion.Store.MemStore ...
- PAT 1146 Topological Order[难]
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which o ...
- TensorFlow学习笔记(七)TesnorFlow实现计算加速
目录: 一.TensorFlow使用GPU 二.深度学习训练与并行模式 三.多GPU并行 四.分布式TensorFlow 4.1分布式TensorFlow的原理 4.2分布式TensorFlow模型训 ...
- TWebBrowser: Determine when a page with Frames is completed
TWebBrowser: Determine when a page with Frames is completed 6 comments. Current rating: (3 votes). L ...