凸包内最大三角形
#define ld double
const ld eps = 1e-9;
const ld PI =acos(-1);
const int N = 2e5 + 50;
int sgn(double x) {
if(fabs(x) < eps)return 0;
return x<0?-1:1;
}
struct Point {
double x,y;
Point(double _x=0,double _y=0) {
x=_x,y=_y;
}
Point operator +(const Point &b)const {
return Point(x+b.x,y+b.y);
}
Point operator -(const Point &b)const {
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const {
return x*b.y-y*b.x;
}
double operator *(const Point &b)const {
return x*b.x+y*b.y;
}
bool operator == (Point b)const {
return sgn(x-b.x)==0&& sgn(y-b.y)==0;
}
bool operator <(Point b)const {
return sgn(x-b.x)==0?sgn(y-b.y)<0:x<b.x;
}
double distance(Point p) {
return hypot(x-p.x,y-p.y);
}
void input() {
scanf("%lf%lf",&x,&y);
}
};
int id1,id2,id3;
int n;
Point p[N],list[N];
struct polygon {
int n;
Point p[N];
void input(int _n) {
n = _n;
for(int i=0; i<n; i++) {
p[i].input();
}
}
};
polygon vv;
struct cmp {
Point p;
cmp(const Point &p0) {
p = p0;
}
bool operator()(const Point &aa,const Point &bb) {
Point a = aa,b = bb;
int d = sgn((a-p)^(b-p));
if(d == 0)return sgn(a.distance(p)-b.distance(p))<0;
return d > 0;
}
};
void norm() {
Point mi= p[0];
for(int i=1; i<n; i++)mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
void Graham(polygon &convex) {
norm();
int &top=convex.n;
top = 0;
if(n == 1) {
top=1;
convex.p[0] = p[0];
return ;
}
if(n == 2) {
top=2;
convex.p[0] = p[0];
convex.p[1] = p[1];
if(convex.p[0] == convex.p[1])top--;
return ;
}
convex.p[0] = p[0];
convex.p[1] = p[1];
top = 2;
for(int i=2; i<n; i++) {
while(top>1&& sgn((convex.p[top-1]-convex.p[top-2])^(p[i]-convex.p[top-2])) <=0)top--;
convex.p[top++] = p[i];
}
if(convex.n == 2 && (convex.p[0]==convex.p[1]))convex.n--;
}
Point p1,p2,p3;
/******凸包内最大三角形*****/
double rotating(Point p[],int n) {
double ans = 0;
Point v;
for(int i=0; i<n; i++) {
int j=(i+1)%n;
int k=(j+1)%n;
while(j!=i&&k!=i) {
double res = fabs((p[i]-p[j])^(p[k]-p[i]));
if(res > ans) {
ans = res;
// p1=p[i],p2=p[j],p3=p[k];
}
while(((p[i]-p[j])^(p[(k+1)%n]-p[k])) < 0) k=(k+1)%n;
j=(j+1)%n;
}
}
return ans/2.0;
}
void work() {
scanf("%d",&n);
vv.n = n;
for(int i=0; i<n; i++) {
p[i].input();
vv.p[i] = p[i];
}
Graham(vv);
double ans = rotating(vv.p,vv.n);
}