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.
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
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)