2021.1.3 星期日 Theatre Square


《Theatre Square》


题目
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.

输入格式
The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

输出格式
Write the needed number of flagstones.

Sample Input
6 6 4

Sample Output
4

题意

算出广场需要用砖的数量。

思路
用广场的边长除以砖块的边长。

坑点
取余不等于0时,砖块的数量需要加1.
要用到long long int

代码

#include<stdio.h>
int main()/*
{
	long long int m=0,n=0,a=0,i1=0,i2=0;
	scanf("%lld%lld%lld",&m,&n,&a);
	i1=n%a;
	i2=m%a;
	if(i1==0 && i2==0)
	{
		printf("%d",(n/a)*(m/a));
	}
	if(i1==0 && i2!=0)
	{
		printf("%d",(n/a)*(m/a+1));
	}
	if(i1!=0 && i2==0)
	{
		printf("%d",(n/a+1)*(m/a));
	}
	if(i1!=0 && i2!=0)
	{
		printf("%d",(n/a+1)*(m/a+1));
	}
	return 0;
}*/
{
    
    
	long long int n,m,a;
	while(scanf("%lld%lld%lld",&n,&m,&a)!=EOF)
	{
    
    
		if((n)%(a)!=0)
		{
    
    
			n=(n)/(a)+1;
		}
		else
		{
    
    
			n=(n)/(a);
		}
		
		if((m)%(a)!=0)
		{
    
    
			m=(m)/(a)+1;
		}
		else
		{
    
    
			m=(m)/(a);
		}
		long long int ans=n*m;
		printf("%lld",ans);
	}	
	return 0;
	
}

猜你喜欢

转载自blog.csdn.net/Autumn_snow/article/details/112160986