Codeforces 1A. Theatre Square

从今天起要开始自己的Codeforces之旅了,

虽然自己目前很菜,

希望通过刷题可以提高自己的能力。

【题目来源】:http://codeforces.com/problemset/problem/1/A

【题目描述】: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
Copy
6 6 4
Output
Copy
4

【题目分析】:广场面积为n*m平方米,现有边长为a米的砖块,问至少需要多少砖块可把广场填满。

分别把长度所需砖块个数与宽度所需砖块个数算出来,计算乘积即可。

注意:提交的时候要注意题目中给处的数据范围,一般数据量都很大,刚开始就因为设置成整型导致结果错误。

【AC代码】

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    long long n,m,a,x,y;
    cin>>n>>m>>a;
    if(n%a>0)
        x=n/a+1;
    else
        x=n/a;
    if(m%a>0)
        y=m/a+1;
    else
        y=m/a;
    cout<<x*y<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/mcp3128/article/details/80501555