【题目】
题目描述
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 contains several cases, every case contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 1000).
输出
Write the needed number of flagstones.
样例输入
4 4 26 6 4
样例输出
44
提示
来源ZCMU1005(内网)
【思考】
英文就当是练习吧,得到三个参数【m,n,a】。
1.首先,发现程序没有具体数量要求,就需要:
while(~scanf("%d %d %d",&n,&m,&a))
等价为
while(scanf("%d %d %d",&n,&m,&a)!= EOF)
EOF为文件的结束符,不懂得可以看(本站的)
如果想结束,可以【Ctrl+z】
2.其次其中的数学逻辑很简单
x=n/a;y=m/a;
if(n%a!=0) x++;
if(m%a!=0) y++;
printf("%d\n",x*y);
x,y表示行和列可整铺的砖个数,然后就会有两种结果{1.整除或2.有余}
【整体代码】
#include<stdio.h>
int main()
{
int n,m,a;int x,y;
while(~scanf("%d %d %d",&n,&m,&a))
{
x=n/a;y=m/a;
if(n%a!=0) x++;
if(m%a!=0) y++;
printf("%d\n",x*y);
}
return 0;
}