CF1918A.Brick Wall
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A brick is a strip of size 1×k, placed horizontally or vertically, where k can be an arbitrary number that is at least 2 (k≥2).
A brick wall of size n×m is such a way to place several bricks inside a rectangle n×m, that all bricks lie either horizontally or vertically in the cells, do not cross the border of the rectangle, and that each cell of the n×m rectangle belongs to exactly one brick. Here n is the height of the rectangle n×m and m is the width. Note that there can be bricks with different values of k in the same brick wall.
The wall stability is the difference between the number of horizontal bricks and the number of vertical bricks. Note that if you used 0 horizontal bricks and 2 vertical ones, then the stability will be −2, not 2.
What is the maximal possible stability of a wall of size n×m?
It is guaranteed that under restrictions in the statement at least one n×m wall exists.
砖是一条尺寸为 1×k 的条状物,可水平或垂直放置,其中 k 是任意大于等于 2 的整数(即 k≥2)。
一个 n×m 规格的砖墙,是指将若干块砖放入一个 n×m 的矩形区域内的一种方式,要求:所有砖均严格水平或垂直地放置在单元格中、不超出矩形边界,且该 n×m 矩形中的每个单元格恰好属于一块砖。此处 n 表示矩形 n×m 的高度,m 表示其宽度。注意:同一面砖墙中可以包含不同 k 值的砖。
墙的稳定性定义为:水平放置的砖的数量与垂直放置的砖的数量之差。注意:例如若使用了 0 块水平砖和 2 块垂直砖,则稳定性为 −2,而非 2。
对于一个 n×m 规格的砖墙,其可能达到的最大稳定性是多少?
题目保证:在本题给定的约束条件下,至少存在一种合法的 n×m 砖墙。
输入格式
The first line of the input contains one integer t (1≤t≤10000), the number of test cases.
The only line of each test case contains two integers n and m (2≤n,m≤104).
输入的第一行包含一个整数 t(1≤t≤10000),表示测试用例的数量。
每个测试用例仅有一行,包含两个整数 n 和 m(2≤n,m≤104)。
输出格式
For each test case, print one integer, the maximum stability of a wall of size n×m.
对于每个测试用例,输出一个整数,表示尺寸为 n×m 的墙的最大稳定性。
输入输出样例
输入#1
5 2 2 7 8 16 9 3 5 10000 10000
输出#1
2 28 64 6 50000000
说明/提示
In the 1st test case, the maximum stability of 2 is obtained by placing two horizontal bricks 1×2 one on top of the other.
In the 2nd test case, one can get the maximum stability of 28 by placing 4 horizontal bricks 1×2 in each of the 7 rows.
在第 1 个测试用例中,通过将两块 1×2 的水平砖块上下叠放,可获得最大稳定性值 2。
在第 2 个测试用例中,通过在全部 7 行中每行放置 4 块 1×2 的水平砖块,可获得最大稳定性值 28。
输入解题思路,AI测评打分。不知道怎么写?