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 <bits/stdc++.h>

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<n; i++ ) {
        scanf("%lld %lld",&x,&y);
        a[i].da = max(x,y);
        a[i].xiao = min(x,y);
    }
    sort(a,a+n,rule);
    ll maxx=a[0].xiao, ans=a[0].xiao*a[0].da,now;
    for ( int i=1; i<n; i++ ) {
        ans = max( ans,a[i].xiao*a[i].da );
        now = min(maxx,a[i].xiao);
        ans = max( ans, 2*now*a[i].da );
        maxx = max(maxx,a[i].xiao);
    }
    //printf("%.1f\n",(double)(ans/2.0));
    if ( ans%2==1 ) {
        printf("%lld.5\n",ans/2);
    }
    else {
        printf("%lld.0\n",ans/2);
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值