2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings

As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the same size. Now, their problem is to find land to build the buildings.

There are NN lands available for sale. The ithith land has a rectangular shape of size Li×WiLi×Wi. For a good feng shui, the building‘s side should be parallel to the land‘s sides.

One way is to build the two buildings on two different lands, one on each land (not necessarily with the same orientation). A building of size A×BA×B can be build on the ithith land if and only if at least one of the following is satisfied:

A≤LiA≤Li and B≤WiB≤Wi, or
A≤WiA≤Wi and B≤LiB≤Li.
Alternatively, it is also possible to build two buildings of A×BA×B on the ithith land with the same orientation. Formally, it is possible to build two buildings of A×BA×B on the ithith land if and only if at least one of the following is satisfied:

A×2≤LiA×2≤Li and B≤WiB≤Wi, or
A×2≤WiA×2≤Wi and B≤LiB≤Li, or
A≤LiA≤Li and B×2≤WiB×2≤Wi, or
A≤WiA≤Wi and B×2≤LiB×2≤Li.
Your task in this problem is to help ICPC Jakarta to figure out the largest possible buildings they can build given NN available lands. Note that ICPC Jakarta has to build two buildings of A×BA×B; output the largest possible for A×BA×B.

Input

Input begins with a line containing an integer: NN (1≤N≤1000001≤N≤100000) representing the number of available lands. The next NN lines each contains two integers: LiLi WiWi (1≤Li,Wi≤1091≤Li,Wi≤109) representing the size of the land.

Output

Output in a line a number representing the largest building that ICPC Jakarta can build with exactly one decimal point (see sample input/output for clarity).

Examples

input

Copy

2
5 5
3 4
output

Copy

12.5
input

Copy

2
2 5
4 3
output

Copy

8.0
input

Copy

3
10 1
9 8
7 6
output

Copy

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.

解题思路:建造两块场地,使得两块场地的面积尽可能地大,有两种情况,第一种:取一块最大的土地,一分为二。第二种:对土地的长(x)进行排序,从大到小,面积取当前x与min(之前y的最大值,当前y的值)乘积作为一块的面积,那在当前x之前的x都大于当前x,所以必定也能放得下这一块面积。有个细节问题是土地的长可以宽,宽也可以是长,所以当宽>长时,需要交换值。注意精度问题,用long long存。

AC代码:

#include <iostream>
#include <algorithm>
using namespace std;
struct Point{
    long long x,y;
}point[100005];
bool cmp(Point a,Point b)
{
    return a.x*a.y>b.x*b.y;
}
int main()
{
    int n;
    while(cin>>n)
    {
        long long area=0;
        for(int i=0;i<n;i++)
        {
            cin>>point[i].x;
            cin>>point[i].y;
            area=max(point[i].x*point[i].y,area);
            if(point[i].y>point[i].x)
                swap(point[i].y,point[i].x);
        }
        long long maxy=0;
        sort(point,point+n,cmp);
        for(int i=0;i<n;i++)
        {
            area=max(area,point[i].x*min(point[i].y,maxy)*2);
            maxy=max(point[i].y,maxy);
        }
        if(area%2)
            cout<<area/2<<".5"<<endl;
        else
            cout<<area/2<<".0"<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/lovelcy/p/11824421.html

时间: 2024-07-30 21:43:12

2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings的相关文章

2018 ICPC Asia Jakarta Regional Contest

题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . . . Ο . . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thinking:kk pai爷 Code:kk 不能直接反转,比如"010101",直接反转后就变成"101010",右移一位,然后加个0就可以了. 所以要先统计01的数量,如果0大于1,就全变成1,1大于0,就全变成0(从数量上的改变就大于s/2了),相等的话,就看首位是0

2019-2020 ICPC, Asia Jakarta Regional Contest C. Even Path

Pathfinding is a task of finding a route between two points. It often appears in many problems. For example, in a GPS navigation software where a driver can query for a suggested route, or in a robot motion planning where it should find a valid seque

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Krak&#243;w

ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik's RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C

2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine the area of the largest triangle that can be formed using \(3\) of those \(N\) points. If there is no triangle that can be formed, the answer is \(0\

The 43rd ACM International Collegiate Programming Contest Asia Shenyang Regional Contest

The 43rd ACM International Collegiate Programming Contest Asia Shenyang Regional Contest 原文地址:https://www.cnblogs.com/Accpted/p/11298233.html

比赛:ICPC Asia Taipei-Hsinchu Regional 2019 2020.4.1

C. Are They All Integers? 题意:是给定n个数字判断对任意的(a[j]-a[i])/a[k]一定要是整数. 题解: 一开始以为用枚举会超时不过还是试了下,没想到没超时,直接过了,题目很简单,简单枚举就好. #include<iostream> using namespace std; int main(){ int n,a[1001],sum; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } for(i

2019 ICPC Asia Yinchuan Regional

目录 Contest Info Solutions A. Girls Band Party B. So Easy D. Easy Problem E. XOR Tree F. Function! G. Pot!! H. Delivery Route I. Base62 K. Largest Common Submatrix N. Fibonacci Sequence Contest Info Practice Link Solved A B C D E F G H I J K L M N 9/1

The 2019 ICPC Asia Shanghai Regional Contest-B-Prefix Code

知识点:字典树. 题目链接: https://ac.nowcoder.com/acm/contest/4370/B 题意:t组数据,n个数字,问是否满足不存在任何一个数字是其他数字的前缀. 题解:套用字典树一个一个插入字符串.若在插入过程中遇到如下两种情况,则存在其中一个是另一个的前缀. 1.遍历完整个字符串都没有创造新的节点,说明该字符串是之前某个串的字串. 2.遍历过程中遇到了某个字符串的终点,说明存在一个字符串是该字符串的前缀. 若都不存在,则满足条件. AC代码: 1 #include