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;
}

总结

水题,不解释

目录
相关文章
|
6月前
|
C++
C++中的setprecision: fixed: scientific等函数
C++中的setprecision: fixed: scientific等函数
83 0
|
机器学习/深度学习 PyTorch 算法框架/工具
【完美解决】RuntimeError: one of the variables needed for gradient computation has been modified by an inp
将loss.backward()函数内的参数retain_graph值设置为True, loss.backward(retain_graph=True),如果retain_graph设置为False,计算过程中的中间变量使用完即被释放掉。
1680 0
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‘
96 0
|
Python
“cosine_distance“ “KMeansClusterer“ is not defined
“cosine_distance“ “KMeansClusterer“ is not defined
122 0
|
数据可视化 Linux Python
成功解决RuntimeError: Selected KDE bandwidth is 0. Cannot estiamte density
成功解决RuntimeError: Selected KDE bandwidth is 0. Cannot estiamte density
成功解决coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to inc
成功解决coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to inc
|
iOS开发 开发者 C++
Effective Objective-C 2.0 Tips 总结 Chapter 5,6,7
Effective Objective-C 2.0 Tips 总结 Chapter 5,6,7 Chapter 5 内存管理 Tips 29 理解引用计数 引用计数是 Objective-C 内存管理的基础,包括 ARC 也是建立在引用计数的基础之...
1300 0
|
Android开发 安全
error: only position independent executables (PIE) are supported
由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题。在AndroidL上的运行情况发现,当运行该可执行文件时,报如下错误: error: only position independent executables (PIE) are supported. PIE这个安全机制从4.1引入,但是Android L之前的系统版本并不会去检验可执行文件是否基于PIE编译出的。
2092 0