题解 P3217 [HNOI2011]数矩形

题面
首先,你可以$n^3$枚举 然后判合法 然后确定第4个点 再判断是否存在
考虑省掉判合法那一步
于是利用矩形的性质:对角线互相平分且相等
于是枚举中心,枚举对角线长度(可以$n^2$得到所有线段,然后把相同的扔到一起就好了)
然后每次再$x^2$枚举(有神仙证明了平面上$n$个点构成矩形个数是$O(n^{2.5})$的,所以没有冗余的枚举即可)
当然你也可以类似奇怪的算法做到纯正的$O(n^2logn)$(排序)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long ll;
struct point {
ll x, y;
friend inline int operator < (point a, point b) {
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
friend inline int operator == (point a, point b) {
return a.x == b.x && a.y == b.y;
}
friend inline ll operator * (point a, point b) {
return a.x * b.x + a.y * b.y;
}
friend inline ll operator ^ (point a, point b) {
return a.x * b.y - a.y * b.x;
}
friend inline point operator + (point a, point b) {
return point(a.x + b.x, a.y + b.y);
}
friend inline point operator - (point a, point b) {
return point(a.x - b.x, a.y - b.y);
}
inline ll get_len2() {
return x * x + y * y;
}
inline point() {}
inline point(ll a, ll b) : x(a), y(b) {}
} p[1510];
typedef struct point vec;
typedef pair<point, ll> data;
/*unordered_*/set<point> st;
int n, cnt;
pair<data, vec> x[2500010];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%lld%lld", &p[i].x, &p[i].y);
if(st.count(p[i])) {
n--;
i--;
continue;
}
else st.insert(p[i]);
}
for(int i = 1; i <= n; i++)
for(int j = 1; j < i; j++)
x[++cnt] = mp(mp(p[j] + p[i], (p[j] - p[i]).get_len2()), p[j] - p[i]);
sort(x + 1, x + 1 + cnt);
// for(int i = 1; i <= cnt; i++) printf("%lld %lld %lld %lld %lld\n", x[i].first.first.x, x[i].first.first.y, x[i].first.second, x[i].second.x, x[i].second.y);
ll ans = 0;
for(int l = 1, r = 1; l <= cnt; l = r = r + 1) {
for(; r < cnt && x[r + 1].first == x[l].first; r++);
// printf("%d %d\n", l, r);
for(int i = l; i <= r; i++)
for(int j = l; j < i; j++) ans = max(ans, abs(x[i].second ^ x[j].second));
}
return cout << ans / 2 << endl, 0;
}