CodeForces-1A Theatre Square(向上取整)

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.

Examples
Input
6 6 4
Output
4

问题简述

  给n*m的矩形和边长为a的正方形,求最少需要多少块正方形可以铺满矩形。


AC的C++语言程序如下:

    /* CodeForces-1A Theatre Square */  
      
    #include <iostream>  
      
    using namespace std;  
      
    int main()  
    {  
        long long n, m, a;  
      
        while(cin >> n >> m >> a)  
            cout << ((n + a - 1) / a ) * ((m + a - 1) / a) << endl;  
      
        return 0;  
    }  

本题收获

1.A,B都是整数,A>1,B>1,求┌A/B┐(向上取整)。

(1)当A/B能整除时,向上取整返回值为A/B

(2)当A/B不能整除时,向上取整返回值是int(A/B)+1

2.(A+B-1)/B可达到向上取整的效果

3.原因:设A=nB+m(n为非负整数,m为0~B-1的数)

则A/B=n+m/B

(A+B-1)/B=n+1+(m-1)/B

当m=0时,

int(A/B)=n

int((A+B-1)/B)=n+int(1-1/B)=n


当m=1~B-1时,0<=m-1<=B-2

┌A/B┐=n+1

int((A+B-1)/B)=n+1+int((m-1)/B)=n+1

所以做题可直接用。


猜你喜欢

转载自blog.csdn.net/Highlight_Jin/article/details/79948156