rt,32pts代码
#include <bits/stdc++.h>
#define N 100010
#define LL long long
using namespace std;
int n, tot = 1;
double ans;
struct P{double x, y;}p[N], cop[N];
double squ(double x) {return x * x;}
double dis(P a, P b) {return squ(a.x - b.x) + squ(a.y - b.y);}
double check1(P a, P b, P c, P d) {return (b.x - c.x) * (d.y - c.y) - (d.x - c.x) * (b.y - a.y);}
double check2(P a, P b, P c, P d) {
double ans = check1(a, b, c, d);
if(ans == 0) return dis(a, b) - dis(c, d);
return ans;
}
bool cmp(P x, P y) {
double tmp = check1(p[1], x, p[2], y);
if(tmp > 0) return true;
if(tmp == 0 && dis(p[0], x) < dis(p[0], y)) return true;
return false;
}
double s(P a,P b, P c) {
double xi = min(a.x, min(b.x, c.x)), yi = min(a.y, min(b.y, c.y));
double xj = max(a.x, max(b.x, c.x)), yj = max(a.y, max(b.y, c.y));
double ans = (xj - xi) * (yj - yi);
ans -= (max(a.x, b.x) - min(a.x, b.x)) * (max(a.y, b.y) - min(a.y, b.y)) / 2;
ans -= (max(a.x, c.x) - min(a.x, c.x)) * (max(a.y, c.y) - min(a.y, c.y)) / 2;
ans -= (max(c.x, b.x) - min(c.x, b.x)) * (max(c.y, b.y) - min(c.y, b.y)) / 2;
return ans;
}
int main() {
scanf("%d", &n);
for(int i = 1;i <= n; ++i) {
scanf("%lf %lf", &p[i].x, &p[i].y);
if(i != 1)
if(p[i].y < p[1].y||(p[i].y == p[1].y)&&p[i].x < p[1].x)
swap(p[i], p[1]);
}
sort(p + 2, p + 1 + n, cmp);
cop[1] = p[1];
for(int i = 2;i <= n; ++i) {
while(tot != 1 && (check2(cop[tot - 1], cop[tot], cop[tot], p[i])) <= 0) --tot;
++tot;
cop[tot] = p[i];
}
cop[tot + 1] = p[1];
if(tot == 2) {
printf("%lld", (LL)dis(cop[1], cop[2]));
return 0;
}
for(int i = 1, num = 3;i <= tot; ++i) {
ans = max(ans, dis(cop[i], cop[i + 1]));
while(s(cop[i], cop[i + 1], cop[num]) < s(cop[i], cop[i + 1], cop[num + 1])) {
++num;
if(num == tot + 1)
num = 1;
}
ans = max(ans, max(dis(cop[i], cop[num]), dis(cop[i + 1], cop[num])));
}
printf("%lld", (LL)ans);
return 0;
}