Twin Buildings
时间限制: 1 Sec 内存限制: 256 MB
题目描述
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 N N N lands available for sale. The i i i-th land has a rectangular shape of size L i × W i L_i×W_i Li×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
×
B
A×B
A×B can be build on the ith land if and only if at least one of the following is satisfied:
·
A
≤
L
i
a
n
d
B
≤
W
i
,
A≤L_i \quad and \quad B≤W_i,
A≤LiandB≤Wi, or
·
A
≤
W
i
a
n
d
B
≤
L
i
A≤W_i \quad and\quad B≤L_i
A≤WiandB≤Li.
Alternatively, it is also possible to build two buildings of
A
×
B
A×B
A×B on the ith land with the same orientation. Formally, it is possible to build two buildings of
A
×
B
A×B
A×B on the ith land if and only if at least one of the following is satisfied:
·
A
×
2
≤
L
i
a
n
d
B
≤
W
i
A×2≤L_i\quad and\quad B≤W_i
A×2≤LiandB≤Wi, or
·
A
×
2
≤
W
i
a
n
d
B
≤
L
i
A×2≤W_i\quad and\quad B≤L_i
A×2≤WiandB≤Li, or
·
A
≤
L
i
a
n
d
B
×
2
≤
W
i
A≤L_i \quad and\quad B×2≤W_i
A≤LiandB×2≤Wi, or
·
A
≤
W
i
a
n
d
B
×
2
≤
L
i
A≤W_i \quad and\quad B×2≤L_i
A≤WiandB×2≤Li.
Your task in this problem is to help ICPC Jakarta to figure out the largest possible buildings they can build given
N
N
N available lands. Note that ICPC Jakarta has to build two buildings of
A
×
B
A×B
A×B; output the largest possible for
A
×
B
A×B
A×B.
输入
Input begins with a line containing an integer: N N N ( 1 ≤ N ≤ 100000 ) (1≤N≤100000) (1≤N≤100000)representing the number of available lands. The next N N N lines each contains two integers: L i W i L_i W_i LiWi ( 1 ≤ L i , W i ≤ 1 0 9 ) (1≤L_i,W_i≤10^9) (1≤Li,Wi≤109) representing the size of the land.
输出
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).
样例输入
【样例1】
2
5 5
3 4
【样例2】
2
2 5
4 3
【样例3】
3
10 1
9 8
7 6
样例输出
【样例1】
12.5
【样例2】
8.0
【样例3】
42.0
提示
Explanation for the sample input/output #1
Two buildings of 2.5 × 5 2.5×5 2.5×5 can be built both on the first land.
Explanation for the sample input/output #2
Two buildings of 2 × 4 2×4 2×4 can be built each on the first and second lands.
Explanation for the sample input/output #3
Two buildings of 7 × 6 7×6 7×6 can be built each on the second and third lands.
思路
按照岛的最长边进行排序,前面的一定可以包括后面的,这样只需要考虑宽就好了。
/*** Amber ***/
//#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define ls (rt<<1)
#define rs (rt<<1|1)
typedef long long ll;
typedef pair<int,int> pii;
template <typename T>
inline void read(T &x) {
x = 0;
static int p;
p = 1;
static char c;
c = getchar();
while (!isdigit(c)) {
if (c == '-')p = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c - 48);
c = getchar();
}
x *= p;
}
template <typename T>
inline void print(T x) {
if (x<0) {
x = -x;
putchar('-');
}
static int cnt;
static int a[50];
cnt = 0;
do {
a[++cnt] = x % 10;
x /= 10;
} while (x);
for (int i = cnt; i >= 1; i--)putchar(a[i] + '0');
puts("");
}
const double Pi=acos(-1);
const double eps=1e-6;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 100010;
struct node{
ll mi,mx;
}a[maxn];
bool cmp(const node &a,const node &b) {
return a.mx > b.mx;
}
int n;
inline void work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
ll x, y;
scanf("%lld%lld", &x, &y);
a[i].mi = min(x, y);
a[i].mx = max(x, y);
}
sort(a + 1, a + n + 1, cmp);
ll mx = a[1].mi, ans = a[1].mi * a[1].mx, now;
for (int i = 2; i <= n; i++) {
ans = max(ans, a[i].mi * a[i].mx);
now = min(mx, a[i].mi);
ans = max(ans, 2 * now * a[i].mx);
mx = max(mx, a[i].mi);
}
if (ans & 1) printf("%lld.5\n", ans / 2); else printf("%lld.0\n", ans / 2);
}
int main() {
//freopen("1.txt","r",stdin);
int T = 1;
//read(T);
while (T--) {
work();
}
return 0;
}