日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Minimal Square CodeForces - 1360A(简单思维和图形判断)

發布時間:2023/12/4 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Minimal Square CodeForces - 1360A(简单思维和图形判断) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

給你兩個大小一樣的,邊長為a,b的矩形將其放入一個正方形里,問怎樣放可以使正方形面積最小(要求正方形邊和矩形邊平行)

題目:

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.

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

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:

分析:

確定正方形的邊長,可知當兩個矩形貼在一起,沒有多余空隙的時候面積最小,此時只要判斷下邊長情況。以較短的邊作為側邊y,那么較長的邊就為x;所求的正方形的邊則為a或者2*b,即為其中較大的那一個,就可以得到最小正方形面積。

AC代碼:

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int t,a,b,ans; int main() {scanf("%d",&t);while(t--){scanf("%d%d",&a,&b);int x=a*2;int y=b*2;if(x>y){if(a>y)printf("%d\n",a*a);else printf("%d\n",y*y);}else{if(b>x)printf("%d\n",b*b);else printf("%d\n",x*x);}}return 0; }

總結

以上是生活随笔為你收集整理的Minimal Square CodeForces - 1360A(简单思维和图形判断)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。