CF1360A.Minimal Square

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Find the minimum area of a square land on which you can place two identical rectangular a×ba \times b houses. The sides of the houses should be parallel to the sides of the desired square land.

Formally,

  • You are given two identical rectangles with side lengths aa and bb (1≤a,b≤1001 \le a, b \le 100) — positive integers (you are given just the sizes, but not their positions).
  • Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square.

Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.

The picture shows a square that contains red and green rectangles.

求能放置两个相同的 a×ba \times b 矩形房屋的正方形土地的最小面积。房屋的边必须与目标正方形土地的边平行。

形式化地:

  • 给定两个完全相同的矩形,其边长分别为 aa 和 bb(1≤a,b≤1001 \le a, b \le 100),均为正整数(仅给出尺寸,不指定位置);
  • 求能同时包含这两个给定矩形的、面积最小的正方形。矩形可以旋转(两个都旋转,或仅旋转其中一个)、平移,但其边必须始终与目标正方形的边平行。

两个矩形可以相互接触(边接触或角接触),但不能相交;矩形也可以接触正方形的边界,但必须完全位于正方形内部。允许对矩形进行旋转。请参看示例以加深理解。

图中展示了一个包含红色和绿色矩形的正方形。

输入格式

The first line contains an integer tt (1≤t≤10 0001 \le t \le 10\,000) —the number of test cases in the input. Then tt test cases follow.

Each test case is a line containing two integers aa, bb (1≤a,b≤1001 \le a, b \le 100) — side lengths of the rectangles.

第一行包含一个整数 tt(1≤t≤10 0001 \le t \le 10\,000)——输入中测试用例的数量。随后是 tt 个测试用例。

每个测试用例是一行,包含两个整数 aa、bb(1≤a,b≤1001 \le a, b \le 100)——矩形的边长。

输出格式

Print tt answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions a×ba \times b.

输出 tt 个测试用例的答案。每个答案必须是一个整数——能够包含两个尺寸为 a×ba \times b 的矩形的正方形土地的最小面积。

输入输出样例

  • 输入#1

    8
    3 2
    4 2
    1 1
    3 1
    4 7
    1 3
    7 4
    100 100

    输出#1

    16
    16
    4
    9
    64
    9
    64
    40000

说明/提示

Below are the answers for the first two test cases:

以下是前两个测试用例的答案:

输入解题思路,AI测评打分。不知道怎么写?

首页