Theatre Square
题目 [CodeForces - 1A]
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.
Time limit | Memory limit | OS | Source |
---|---|---|---|
1000 ms | 262144 kB | Codeforces Beta Round #1 | Announcement Tutorial #1 Tutorial #2 |
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.
Example
Input | Output |
---|---|
6 6 4 | 4 |
问题链接: [CodeForces - 1A]
问题描述
先贴中文翻译吧:
首都伯兰的剧院广场呈矩形,大小为n×m米。 在城市周年纪念日之际,决定用方形花岗岩石板铺设广场。 每块石板的大小为a×a。
铺设广场所需的石板数量最少? 它允许覆盖比剧院广场更大的表面,但必须覆盖广场。 它不允许破坏石板。 石板的两侧应平行于广场的两侧。
问题分析
用广场的长和宽除砖的边长,如果刚好填满,那么数目就是长数量乘宽数量,如果哪一边不能整除那么就是再多加另一个边的数量,如果两个边都不能整除,那么还有角落的一个。
代码
AC代码
#include<iostream>
using namespace std;
int main()
{
long long kuan, chang, a;//分别保存广场的宽(kuan)长(chang)以及砖的边长a
long long sum_chang, sum_kuan;//每个边有多少个砖
long long temp_sum;
while (cin >> kuan >> chang >> a)
{
sum_kuan = kuan / a;//算出宽上的用砖
sum_chang = chang / a;//算出长上的用砖
temp_sum = sum_chang * sum_kuan;//暂时算出转的用量
if (sum_chang*a < chang)//如果是长上不够
{
temp_sum += sum_kuan;//就要再加上宽边的数目
}
if (sum_kuan*a < kuan)//如果是宽上不够
{
temp_sum += sum_chang;//就要再加上长边的数目
}
if ((sum_chang*a < chang) && (sum_kuan*a < kuan))//如果是两边都不够
{
temp_sum+=1;//加多一
}
cout << temp_sum << endl;
}
}