(第二次周赛)Theatre Square 【CodeForces - 1A】

Theatre Square

题目 [CodeForces - 1A]

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.

Time limitMemory limitOSSource
1000 ms262144 kBCodeforces Beta Round #1Announcement
Tutorial #1
Tutorial #2

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.

Example

InputOutput
6 6 44

问题链接: [CodeForces - 1A]

问题描述

先贴中文翻译吧:
首都伯兰的剧院广场呈矩形,大小为n×m米。 在城市周年纪念日之际,决定用方形花岗岩石板铺设广场。 每块石板的大小为a×a。

铺设广场所需的石板数量最少? 它允许覆盖比剧院广场更大的表面,但必须覆盖广场。 它不允许破坏石板。 石板的两侧应平行于广场的两侧。

问题分析

用广场的长和宽除砖的边长,如果刚好填满,那么数目就是长数量乘宽数量,如果哪一边不能整除那么就是再多加另一个边的数量,如果两个边都不能整除,那么还有角落的一个。

代码

AC代码

#include<iostream>
using namespace std;
int main()
{
	long long kuan, chang, a;//分别保存广场的宽(kuan)长(chang)以及砖的边长a
	long long sum_chang, sum_kuan;//每个边有多少个砖
	long long temp_sum;
	while (cin >> kuan >> chang >> a)
	{
		sum_kuan = kuan / a;//算出宽上的用砖
		sum_chang = chang / a;//算出长上的用砖
		temp_sum = sum_chang * sum_kuan;//暂时算出转的用量
		if (sum_chang*a < chang)//如果是长上不够
		{
			temp_sum += sum_kuan;//就要再加上宽边的数目
		}
		if (sum_kuan*a < kuan)//如果是宽上不够
		{
			temp_sum += sum_chang;//就要再加上长边的数目
		}
		if ((sum_chang*a < chang) && (sum_kuan*a < kuan))//如果是两边都不够
		{
			temp_sum+=1;//加多一
		}
		cout << temp_sum << endl;
	}
}
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值