-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimal_Square.cpp
More file actions
76 lines (66 loc) · 1.85 KB
/
Copy pathMinimal_Square.cpp
File metadata and controls
76 lines (66 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//Minimal Square
/* 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.
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
inputCopy
8
3 2
4 2
1 1
3 1
4 7
1 3
7 4
100 100
outputCopy
16
16
4
9
64
9
64
40000
Note
Below are the answers for the first two test cases:
*/
#include<bits/stdc++.h>
using namespace std;
int solve(int l,int b){
if(2*b<l){
return(l*l);
}
else{
return((2*b)*(2*b));
}
}
int main(){
int n,l,b,ans=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>l>>b;
int z=0;
z=l;
if(l<b){
l=b;
b=z;
}
ans=solve(l,b);
cout<<ans<<endl;
}
return 0;
}