Description
给出平面上 (n) 个点,选出四个点作为矩形顶点。求出矩形最大面积。
(1leq nleq 1500)
Solution
转载自 Z-Y-Y-S dark♂菜鸡
两条线段能作于矩形的对角线有 (2) 个条件:
- 中点相同
- 长度相同
于是 (O(n^2)) 处理出所有直线,排序,找到满足条件的区间,枚举得出答案。
复杂度有点玄学。
Code
//It is made by Awson on 2018.3.13
#include <bits/stdc++.h>
#define LL long long
#define dob complex<double>
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
#define writeln(x) (write(x), putchar('
'))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int N = 1500;
void read(int &x) {
char ch; bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
x *= 1-2*flag;
}
void print(LL x) {if (x > 9) print(x/10); putchar(x%10+48); }
void write(LL x) {if (x < 0) putchar('-'); print(Abs(x)); }
int n, tot, x[N+5], y[N+5]; LL ans;
struct tt {
int idx, idy; LL x, y, l;
tt(int _idx = 0, int _idy = 0, LL _x = 0, LL _y = 0, LL _l = 0) {
idx = _idx, idy = _idy, x = _x, y = _y, l = _l;
}
bool operator < (const tt &b) const {
if (x != b.x) return x < b.x;
if (y != b.y) return y < b.y;
return l < b.l;
}
}a[N*N];
LL dist(int a, int b) {return 1ll*(y[a]-y[b])*(y[a]-y[b])+1ll*(x[a]-x[b])*(x[a]-x[b]); }
LL square(int a, int b, int c) {return Abs(1ll*(y[b]-y[a])*(x[c]-x[a])-1ll*(y[c]-y[a])*(x[b]-x[a])); }
void work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]);
for (int i = 1; i <= n; i++)
for (int j = i+1; j <= n; j++)
a[++tot] = tt(i, j, x[i]+x[j], y[i]+y[j], dist(i, j));
sort(a+1, a+tot+1);
for (int i = 1, last; i < tot; i = last+1) {
last = i;
while (a[i].x == a[last+1].x && a[i].y == a[last+1].y && a[i].l == a[last+1].l && last < tot) ++last;
for (int j = i; j <= last; j++)
for (int k = j+1; k <= last; k++)
ans = max(ans, square(a[j].idx, a[j].idy, a[k].idx));
}
writeln(ans);
}
int main() {
work(); return 0;
}