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)
  • 相关阅读:
    array note
    前端开发规范
    java集合分类
    react native环境
    gulp
    关于如何在海量手机号中刷选出想要的手机号
    生成用户头像插件
    下拉加载
    阿里云人脸人体识别调试心得与备忘
    Sublime text3使用时有卡顿现象
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/3254623.html
Copyright © 2011-2022 走看看