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.
Sample test(s)
input
6 6 4
output
4
又是一道水题,但是有一点需要注意,就是题目上虽然没说大小,但是经过测试需要用long long,
任意长,任意宽,覆盖正方形,要对长和宽进行处理而不是面积,这是一种从复杂往简单转化的优秀思想。
这是自己写的代码,肿么提交了两次都是WA,后来发现sum+=b+c;写错了,脑子秀逗了
#include <iostream>
using namespace std;
int main()
{
long long n,m,a;
while(cin>>n>>m)
{
int b=0,c=0;
int sum=0;
cin>>a;
if(n%a==0)
b=n/a;
else
b=n/a+1;
if(m%a==0)
c=m/a;
else
c=m/a+1;
sum+=b+c;
cout<<sum<<endl;
}
return 0;
}
AC过的:
#include <iostream>
using namespace std;
int main()
{
long long n,m,a;
while(cin>>n>>m>>a)
{
long long b=0,c=0;
long long sum;
if(n%a==0)
b=n/a;
else
b=n/a+1;
if(m%a==0)
c=m/a;
else
c=m/a+1;
sum=b*c;
cout<<sum<<endl;
}
return 0;
}