跳到正文

题解

题解:P12105 [NWRRC2024] Another Brick in the Wall

Wendy_Hello_qwq约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年4月29日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
获赞
2
题目
P12105

版本

  1. v1当前

题目传送门。

题意

给定一堵宽 ll 高 hh 的墙面,用 1×31 \times 3 尺寸的砖块铺墙面,求出铺的最小数量的砖块。

分析

首先对于墙面宽 ll 进行分类讨论:

  • ll 为奇数的情况:由于砖块尺寸是 1×31 \times 3,那么不难想到,在墙面的左边或右边铺上 1×31 \times 3 的砖块,中间总会剩下若干个 1×21 \times 2 的砖块,那么不难想到最小数量就是 hh。

  • ll 为偶数的情况:只要在墙面的左右两边铺上 1×31 \times 3 的砖块,那么这样一共有 ⌊h2⌋\lfloor \frac{h} 2 \rfloor 行,所以答案就是 ⌊h2⌋×2\lfloor \frac{h} 2 \rfloor \times 2。

分类讨论结束后,根据条件判断并输出即可,代码十分简短。

Code

C++
// P12105 [NWRRC2024] Another Brick in the Wall
#include <cstdio>
using namespace std;
int l, h;
signed main() {
	scanf ("%d%d", &l, &h);
	// 分类讨论,l 为偶数 
	if (l % 2 == 1) printf ("%d", h);
	// l 为奇数 
	else printf ("%d", 2 * (h / 2));
	return 0;
}

AC 记录。

完结撒花。

原文