H - Twin Buildings ( 精度损失 )

H - Twin Buildings ( 精度损失 )

题意: 有n个长方形的岛,给出长宽。现在想要在岛上建两个大小完全一样的长方形房子,房子的边必须和岛的边平行,问最大能建多么大的。

思路: 按照岛的最长边进行排序,前面的一定可以包括后面的,这样只需要考虑宽就好了。

注意: double存不下long long范围的值,会有精度损失。 处理方式看代码输出部分

Examples  Input

2
5 5
3 4

Output

12.5

Input

2
2 5
4 3

Output

8.0

Input

3
10 1
9 8
7 6

Output

42.0

Note

Explanation for the sample input/output #1

Two buildings of 2.5×5

can be built both on the first land.

Explanation for the sample input/output #2

Two buildings of 2×4

can be built each on the first and second lands.

Explanation for the sample input/output #3

Two buildings of 7×6

can be built each on the second and third lands.

代码:

#include 

using namespace std;

const int maxn = 1e5+10;
typedef long long ll;
struct node {
    ll xiao,da;
}a[maxn];

ll n,x,y;

bool rule( node a, node b )
{
    return a.da>b.da;
}

int main()
{
    cin >> n;
    for ( int i=0; i

 

你可能感兴趣的:(思维补题)