Minimal Square

简介: Minimal Square

文章目录

一、A. Minimal Square

总结


一、A. Minimal Square

本题链接:A. Minimal Square


题目:


A. Minimal Square


time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output


Find the minimum area of a square land on which you can place two identical rectangular a×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 a and b (1≤a,b≤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.

image.png


Input

The first line contains an integer t (1≤t≤10000) —the number of test cases in the input. Then t test cases follow.


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


Output

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


Example

input

8

3 2

4 2

1 1

3 1

4 7

1 3

7 4

100 100

output

16

16

4

9

64

9

64

40000

Note

Below are the answers for the first two test cases:

image.png

本博客给出本题截图

image.png

image.png

image.png

题意t组数据,每次数据给一个长方形的长和宽,现在把两个 相同 的长方形放入到一个正方形内部,可以旋转长方形但旋转必须满足长方形的边和正方形的边相平行,两个正方形不可以重叠,求正方形面积最小值

AC代码

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t -- )
    {
        int l, r;
        cin >> l >> r;
        if (l < r)
            swap(l, r);
        int len = max(r * 2, l);
        cout << len * len << endl;
    }
    return 0;
}

总结

水题,不解释

目录
打赏
0
0
0
0
62
分享
相关文章
成功解决matplotlib.units.ConversionError: Failed to convert value(s) to axis units: ‘LiR‘
成功解决matplotlib.units.ConversionError: Failed to convert value(s) to axis units: ‘LiR‘
UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
本文提供了解决PIL库中"Palette images with Transparency"警告的方法,通过将图片转换为'RGB'模式来消除透明通道的问题。
UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
UserWarning: Glyph 27668 (\N{CJK UNIFIED IDEOGRAPH-6C14}) missing from current font.
UserWarning: Glyph 27668 (\N{CJK UNIFIED IDEOGRAPH-6C14}) missing from current font.
538 2
|
11月前
|
C++
C++中的setprecision: fixed: scientific等函数
C++中的setprecision: fixed: scientific等函数
180 0
Locally Adaptive Color Correction for Underwater Image Dehazing and Matching
该文提出了一种新颖的水下图像处理方法,结合颜色转移和局部调整来校正颜色,以应对水下光照和散射造成的图像退化。传统颜色转移方法基于全局参数,不适应水下场景中颜色变化的局部性质。文章中,作者通过融合策略,利用光衰减水平估计来实现局部颜色校正。首先,通过暗通道先验恢复彩色补偿图像,然后估计光衰减图。接着,创建一个合成图像,该图像的统计特性代表高衰减区域,用于颜色转移。最后,通过加权融合初始图像和颜色转移图像,生成最终的颜色校正图像。这种方法旨在提高水下图像的对比度和颜色准确性,特别关注高衰减区域。
128 1
DFNet: Enhance Absolute Pose Regression withDirect Feature Matching
DFNet: Enhance Absolute Pose Regression withDirect Feature Matching
224 0
UserWarning: Glyph 28857 (\N{CJK UNIFIED IDEOGRAPH-70B9}) missing from current font. FigureCanvasA
UserWarning: Glyph 28857 (\N{CJK UNIFIED IDEOGRAPH-70B9}) missing from current font. FigureCanvasA
UserWarning: Glyph 28857 (\N{CJK UNIFIED IDEOGRAPH-70B9}) missing from current font. FigureCanvasA
LeetCode 310. Minimum Height Trees
对于一个具有树特征的无向图,我们可选择任何一个节点作为根。图因此可以成为树,在所有可能的树中,具有最小高度的树被称为最小高度树。给出这样的一个图,写出一个函数找到所有的最小高度树并返回他们的根节点。
109 0
LeetCode 310. Minimum Height Trees
undefined reference to `gdk_monitor_get_scale_factor/gtk_widget_get_scale_factor‘
undefined reference to `gdk_monitor_get_scale_factor/gtk_widget_get_scale_factor‘
116 0
解决办法:RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96
解决办法:RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96
908 0