Match two[A problem ]

Time limit: 1000 ms
Memory limit: 262144 kB
Source :Codeforces Beta Round #1
Tags: math *1300
Editorial: Announcement Tutorial #1 Tutorial #2

Problem Description:
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 ≤ 10^9).
Output
Write the needed number of flagstones.
Sample Input
6 6 4
Sample Output
4

问题链接https://vjudge.net/contest/275894#problem

问题简述:输入三个整数,其中前两个代表一个长方形的长和宽,第三个代表一个正方形的边长,计算该长方形应该由几个正方形构成

问题分析:应当注意的是,正方形不能拆分;并且,三个边长均有范围,且范围较大,即使用高精度整数型为正确
程序说明:该程序使用高精度整数型扩大整数范围,实现直接输入与输出;

AC通过的程序如下:

#include<iostream>
#include<math.h> 
using namespace std;
int main()
{
	long long int n,m,a;
	cin>>n>>m>>a;
	if(n<1 || n>pow(10.0, 9.0) || m<1 || m>pow(10.0, 9.0) || a<1 || a>pow(10.0, 9.0)) 
		return 0;
	else
	{
		if(n%a==0&&m%a==0)
			cout<<n/a*(m/a);
		else if(n%a==0&&m%a!=0)
			cout<<n/a*(m/a+1);
		else if(n%a!=0&&m%a==0)
			cout<<(n/a+1)*(m/a);
		else
			cout<<(n/a+1)*(m/a+1);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值