二周:CodeForces - 1A——A. Theatre Square

A. Theatre Square
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Input
6 6 4
Output
4

问题链接:CodeForces - 1A

问题简述:用n块aa的板子完全覆盖mn大小的地方。

问题分析:可以通过长和宽来计算,只需要最终的长方体的长和宽均分别大于原本对应的长和宽即可。

程序说明:设最终铺成的长方体的长的长度为ia,宽的长度为ja,通过循环语句算出ia>=m&&ja>=n所满足的最小i,j即可。

AC通过代码:

#include<stdio.h>

int main()
{
	long long n,m,a,i=1,j=1;
	scanf("%lld %lld %lld",&n,&m,&a);
	while(i*a<n)
	{
		i++;
	}
	while(j*a<m)
	{
		j++;
	}
	printf("%lld\n",i*j);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43887417/article/details/85028550