Problem:

Given a rectangular ground of dimension X by Y. And we have square tiles of size A by A. Find minimum number of tiles required to cover the ground.

Note: Tiles cannot be broken, it is OK if titles crosses rectangle boundary.

Note: Tiles cannot be broken, it is OK if titles crosses rectangle boundary.

**Input Format:**

X Y A

**Output Format:**

Number of tiles

**Constraints:**

None

Sample Input

8 10 4

Sample Output:

6

6

Explanations:

8 x 8 will be covered by 4 titles of 4 x 4. Remaining area 8 x 2 will be covered by another 2 tiles. So total 6 tiles.

8 x 8 will be covered by 4 titles of 4 x 4. Remaining area 8 x 2 will be covered by another 2 tiles. So total 6 tiles.

Solution:

($x,$y,$p)=split(" ",$line);

if($x%$p==0)

{

$tmp1=$x/$p;

}

else

{

$tmp1=int($x/$p)+1;

}

if($y%$p==0)

{

$tmp2=$y/$p;

}

else

{

$tmp2=int($y/$p)+1;

}

$ans=$tmp1*$tmp2;

print $ans;

Tips:

check x, y for divisibility by a and code accordingly

## No comments:

## Post a Comment