zoukankan      html  css  js  c++  java
  • codeforce 1A Theatre Square

    A. Theatre Square

    Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

    What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

    Input

    The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

    Output

    Write the needed number of flagstones.

    python入门之后来CF刷道水题练练手~

    和tag提示的一样直接用贪心就好了,将对面积的计算问题转化为对长宽的计算问题。每条边能整除就用整除的商,不能整除就用商再加一块。这个处理可以用(n-1)/a+1*((m-1)/a+1)完成也可以用(-n/a)*(-m/b)完成(当然用上if或者写个函数啥的也不是不可以……比较没那么pythonic  XD)
    输入方面即可以用map也可以用list配合for赋值。

    用python写题的一个好处就是不用担心精度问题……以下均为py27

    n, m, a = map(int, raw_input().split())
    print ((n-1)/a + 1)*((m-1)/a + 1)
    n, m, a = [int(x) for x in raw_input().split()]
    print (-n / a) * (-m / a)
  • 相关阅读:
    学生管理系统
    Selenium元素定位的30种方式
    python-- 多进程
    python 多线程的实现
    python 节省内存的for循环技巧
    python 生成器
    python 字符串编码检测
    opencv-python 图片的几何变换
    opencv-python --图像处理
    目标检测
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/3254623.html
Copyright © 2011-2022 走看看