Bzoj1069 [scoi2007] maximum land area

Labels: calculate geometry - rotate cartridge

subject

Title gate

Description

There are N points on a flat land. You can choose any four points to enclose the land. Of course, you want these four points to be
Has the largest polygon area.
Input

The first line is a positive integer n, next N lines, each line has two numbers x,y, representing the abscissa and ordinate of the point.
Output

The largest polygon area, the answer accurate to 3 decimal places.
Sample Input
5

0 0

1 0

1 1

0 1

0.5 0.5
Sample Output
1.000
HINT

Data range n < = 2000, |x|, |y| = 100000

Analysis

If we enumerate four points for calculation, the complexity can be imagined, and the constant of calculation geometry is relatively large

Making convex hull and rotating chuck (how to read this in the end)

Enumerate two points, connect a diagonal

Then, on the diagonal, two pieces of shells are rotated twice to calculate the largest triangle area

Then take the maximum value

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(register int i=a;i<=b;i++)
#define dep(i,a,b) for(register int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define eps 1e-6
using namespace std;
inline ll read()
{
    ll f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
const int maxn=2e3+6;
int n,top;
struct P{double x,y;}p[maxn],s[maxn];
inline P operator-(P a,P b){P t;t.x=a.x-b.x;t.y=a.y-b.y;return t;}
inline double operator*(P a,P b){return a.x*b.y-a.y*b.x;}
inline double dis(P a,P b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
inline bool operator<(P a,P b){
    double t=(a-p[1])*(b-p[1]);
    if(t==0)return dis(a,p[1])<dis(b,p[1]);else return t<0;
}
void graham(){
    int t=1;
    rep(i,2,n)
        if(p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x))t=i; 
    swap(p[1],p[t]);sort(p+2,p+n+1);
    s[++top]=p[1];s[++top]=p[2];
    rep(i,3,n){
        while(top>1&&((p[i]-s[top-1])*(s[top]-s[top-1]))<=0)top--;
        s[++top]=p[i];
    }
    s[top+1]=p[1];
}
inline double RC(){
    double ans=0;int a,b;
    rep(i,1,top){
        a=i%top+1,b=(i+2)%top+1;
        rep(j,i+2,top){
            while(a%top+1!=j&&(s[j]-s[i])*(s[a+1]-s[i])>(s[j]-s[i])*(s[a]-s[i]))a=a%top+1;
            while(b%top+1!=i&&(s[b+1]-s[i])*(s[j]-s[i])>(s[b]-s[i])*(s[j]-s[i]))b=b%top+1;
            ans=max((s[j]-s[i])*(s[a]-s[i])+(s[b]-s[i])*(s[j]-s[i]),ans);
        }
    }
    return ans;
}
int main()
{
    n=read();
    rep(i,1,n)scanf("%lf%lf",&p[i].x,&p[i].y);
    graham();
    printf("%.3lf\n",RC()/2);
    return 0;
}

Posted by jeephp on Mon, 06 Apr 2020 09:17:59 -0700