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
inputCopy
6 6 4
outputCopy
4
这个就是数学问题,利用边长求解。注意数据类型,int会爆,亲测。
代码:
import java.util.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n=in.nextInt();
long m=in.nextInt();
long a =in.nextInt();
long c=0,sum2=0, sum1=0;
if(m%a==0) {
sum1=(m/a);
}
else {
sum1=(m/a)+1;
}
if(n%a==0) {
sum2=(n/a);
}
else {
sum2=(n/a)+1;
}
c=sum1*sum2;
System.out.println(c);
}
}
为庆祝城市周年,Berland首都的TheatreSquare计划使用a×a尺寸的花岗岩方砖铺设广场。本篇介绍如何计算所需最少数量的方砖,确保广场完全覆盖,且砖块不得破坏,砖边须平行于广场边界。
319

被折叠的 条评论
为什么被折叠?



