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的更多相关文章

  1. Math.ceil(a/b)结果出错--原因是a和b不是double

    脑袋短路.连续测试几次发现Math.ceil(188/20)==9; 忍无可忍,突然发现是int问题,顺着表达式走一遍,188/20==9,然后再向上取整.脑袋僵化了.看来一直做简单的不动脑筋的工作, ...

  2. 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( ...

  3. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

    Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...

  4. Javascript Math ceil()、floor()、round()三个函数的区别

    Round是四舍五入的...Ceiling是向上取整..float是向下取整. ceil():将小数部分一律向整数部分进位. 如: Math.ceil(12.2)//返回13 Math.ceil(12 ...

  5. 数学对象Math ceil()、floor()、round()方法

      Math.ceil()   功能:对一个数进行上取整. 语法:Math.ceil(x) 参数: x:一个数值. 返回值:返回大于或等于x,并且与之最接近的整数. 注:如果x是正数,则把小数“入”: ...

  6. javascript中Math ceil(),floor(),round()三个函数的对比

    Math.ceil()执行的是向上舍入 Math.floor()执行向下舍入 Math.round()执行标准舍入 一下是一些补充: ceil():将小数部分一律向整数部分进位. 如: Math.ce ...

  7. Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结

    一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...

  8. 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 ...

  9. JS中的Math.ceil和Math.floor函数的用法

    Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入 Math.floor(x)--返回小于等于数字参数的最大整数,对数字进行下舍入 例如: document. ...

随机推荐

  1. pymsql与ORM--python操作MySQL之利器

    pymsql 原生模块 pymsql是python中操作MySQL的模块,其使用方法和MySQLdb几乎相同. 下载安装 pip3 install pymysql 使用操作 1.执行SQL impor ...

  2. Mybatis框架学习总结-使用Mybatis对表执行CRUD操作

    使用MyBatis对表执行CRUD操作——基于XML的实现 1.创建(create)用户:在userMapper.xml文件中增加: <!-- 创建用户Create --> <ins ...

  3. python web框架 Django 登录页面

    在django 项目下 创建一个templates 放模板的文件夹 html文件都放在这里 在里面写一个login.html 登录页面 urls.py 加上 login 对应关系 from djang ...

  4. 如何理解PHP的单例模式

    单例模式就是让类的一个对象成为系统中的唯一实例,避免大量的 new 操作消耗的资源. PHP的单例模式实现要求: 1.一个private的__construct是必须的,单例类不能在其它类中实例化,只 ...

  5. PAT 1084 Broken Keyboard[比较]

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  6. 配置支持Basler的API函数的开发环境

    第一步:文件说明 使用默认路径安装Basler pylon x86 4.2.1.4845.exe 以后生产的文件如下: 文件说明: apps为用于配置ip和调试相机的软件 bin为驱动程序 CLPro ...

  7. (转)VC串口小程序(用SerialPort类)

    ××××××××××××××××××××××××××××××××××××××××××××××××××××× 在MFC里面实现串口通讯有很多方式: 方案一:使用微软公司提供的 串口类,SerialPor ...

  8. CentOS忘记用户名或者密码解决办法

    方法一:如果用户名和密码都忘记了,可以用以下这个方法找回:(和第二种大步骤差不多,需注意3,4步) 1. 在出现grub画面时,用上下键选中你平时启动linux的那一项,然后按e键 2. 再次用上下键 ...

  9. 获取一个表单字段中多条数据并转化为json格式

    如图需要获取下面两个li标签里面的数据,然后传给后台:而后台接收的数据格式是json的,所以需要把两个li里面的信息转化为以下格式的. {recieverName:小红,recieverPhone:1 ...

  10. 131. Palindrome Partitioning(回文子串划分 深度优先)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...