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

· · 题解

题目传送门。

题意

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

分析

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

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

Code

// 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 记录。

完结撒花。