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)
  • 相关阅读:
    Eureka与ZooKeeper 的比较(转)
    springcloud 与分布式系统(转载)
    jvm 分代回收算法通俗理解
    关于JVM调优
    Java常用的数据结构
    mysql数据库引擎(转载)
    java的堆栈通俗理解
    ArrayList 的实现原理
    hashMap 源码解读理解实现原理和hash冲突
    Sklearn库例子——决策树分类
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/3254623.html
Copyright © 2011-2022 走看看