Building Boundaries

Building Boundaries

时间限制: 1 Sec  内存限制: 128 MB

题目描述

Maarja wants to buy a rectangular piece of land and then construct three buildings on that land.
The boundaries of the buildings on the ground must have rectangular sizes a1 × b1 , a2 × b2 ,and a3 × b3 . They can touch each other but they may not overlap. They can also be rotated as long as their sides are horizontal and vertical.
What is the minimum area of land Maarja has to buy?
Figure B.1: Illustration of the two test scenarios in Sample Input 1 and their solutions. In the second scenario the 5 × 1 building has been rotated by 90 degrees.

输入

The input consists of multiple test scenarios. The first line of input contains a single integer t(1 ≤ t ≤ 1000), the number of scenarios. Then follow the t scenarios. Each scenario consists of a single line, containing six integers a1 , b1 , a2 , b2 , a3 and b3 (1 ≤ a1 , b1 , a2 , b2 , a3 , b3 ≤ 109 ).

输出

For each test scenario, output the minimum area of land such that Maarja can construct the three buildings.

样例输入

2
2 3 2 2 1 1
2 4 5 1 2 3

样例输出

12
21

题解

枚举所有情况进行计算。
 1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 typedef long long LL;
 5 int n;
 6 struct Side
 7 {
 8     LL a[2];
 9     void read()
10     {
11         scanf("%lld%lld", &a[0], &a[1]);
12         return;
13     }
14 };
15 LL cal(Side a, Side b, Side c)
16 {
17     LL ans = 4e18;
18     for(int i = 0; i < 2; i++)
19         for(int j = 0; j < 2; j++)
20             for(int k = 0; k < 2; k++)
21             {
22                 ans = min(ans, (a.a[i]+b.a[j]+c.a[k])*max(a.a[i^1], max(b.a[j^1], c.a[k^1])));
23                 ans = min(ans, max(a.a[i]+b.a[j], c.a[k])*max(a.a[i^1]+c.a[k^1], b.a[j^1]+c.a[k^1]));
24                 ans = min(ans, max(a.a[i]+b.a[j], a.a[i]+c.a[k])*max(a.a[i^1], b.a[j^1]+c.a[k^1]));
25             }
26     return ans;
27 }
28 int main()
29 {
30     scanf("%d", &n);
31     for(int i = 1; i <= n; i++)
32     {
33         Side a, b, c;
34         a.read(); b.read(); c.read();
35         LL ans = min(cal(a, b, c), cal(a, c, b));
36         ans = min(ans, min(cal(b, a, c), cal(b, c, a)));
37         ans = min(ans, min(cal(c, a, b), cal(c, b, a)));
38         printf("%lld\n", ans);
39     }
40     return 0;
41 }
View Code

 

 
posted @ 2020-09-15 19:03  Johnny-English  阅读(281)  评论(0编辑  收藏  举报