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. ...
随机推荐
- CGI/FastCGI/mod_php工作原理
先了解一下普通cgi的工作流程:web server收到用户请求,并把请求提交给cgi程序,cgi程序根据请求提交的参数作相应处理,然后输出标准的html语句返回给web server,web ser ...
- libtorch 哪些函数比较常用?
libtorch 加载 pytorch 模块进行预测示例 void mat2tensor(const char * path, torch::Tensor &output) { //读取图片 ...
- OCR技术浅探 : 文字定位和文本切割(2)
文字定位 经过前面的特征提取,我们已经较好地提取了图像的文本特征,下面进行文字定位. 主要过程分两步: 1.邻近搜索,目的是圈出单行文字: 2.文本切割,目的是将单行文本切割为单字. 邻近搜索 我们可 ...
- JavaScript Big-Int
这个库是为JavaScript中的大整数操作,如加,减,乘,除,mod,比较等. 这个库的原理是模拟笔和纸的操作,你可以操作整数,大到你的RAM允许. 例 var bigInt = require(' ...
- python学习笔记(二十七)多线程与多进程
线程是程序里面的最小执行单元. 进程是资源的集合. 线程是包含在一个进程里面,一个进程可以有多个线程,一个进程里面默认有一个主线程.由主线程去启动子线程. 1.多线程 import threading ...
- JDB调试代码 20165324 何春江
Java书本程序调试: 课上程序调试
- adb push ,adb pull和adb install的区别
1.用命令行把手机上的文件拷贝到电脑上 1 adb pull sdcard/1222073679.png 拷贝文件夹命令,如把log文件夹拷贝到电脑当前目录 1 adb pull sdcard/log ...
- python字符串搜索
python字符串字串查找 find和index方法 更多0 python 字符串 python 字符串查找有4个方法,1 find,2 index方法,3 rfind方法,4 rindex方法. 1 ...
- centos7编译安装Python3.6(与2.7并存)
首先去官网下载python3.6 https://www.python.org/ 环境准备:#yum install openssl-devel bzip2-devel expat-devel gdb ...
- Zen cart 根据数量打折插件
Quantity Discounts 可以根据顾客购买多少来打折,很不错. 假如顾客买了3个以上的产品,就给他10%折扣,设置如下: Turn On Quantity Discount 1. In t ...