题意:n个点选构3点面积最大的三角形
思路:
O(n)的假算法意思是三角形的边一定是凸包的边,而实际上不一定
能知的是3点必然在凸包上
旋转卡壳的思想是,当边在逆时针旋转的时候,对踵点也跟着逆时针旋转
到这也同样适用,当边在逆时针旋转的时候,对踵点也跟着逆时针旋转. 只是这个时候的边,并不在凸包上了
则有,O(n^2)枚举底边(i,j),根据上面的原则k=i+1为起点,不停地更新K
关于旋转卡壳的总结 , 传送门
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+6;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
int sign(int x){
return abs(x)<1e-7?0:x<0?-1:1;
}
struct Point{
ll x,y;
Point(ll x=0, ll y=0) : x(x), y(y) {}
Point operator - (const Point &rhs) const{
return Point(x-rhs.x,y-rhs.y);
}
bool operator == (const Point &rhs) const{
return sign(x-rhs.x)==0&&sign(y-rhs.y)==0;
}
bool operator < (const Point &rhs)const{
if(x==rhs.x) return y<rhs.y;
else return x<rhs.x;
}
}p[N];
typedef Point Vector;
ll cross(Vector A,Vector B){
return A.x*B.y-A.y*B.x;
}
int n;
typedef vector<Point> Polygon;
Polygon convex_hull(Polygon P){
sort(P.begin(),P.end());
P.erase(unique(P.begin(), P.end()), P.end());
int n=P.size(),k=0;
Polygon Q(n*2);
for(int i=0;i<n;++i){
while(k>1&&cross(Q[k-2]-Q[k-1],Q[k-2]-P[i])<=0) k--;
Q[k++]=P[i];
}
int t=k;
for(int i=n-2;i>=0;--i){
while(k>t && cross(Q[k-2]-Q[k-1],Q[k-2]-P[i])<=0) k--;
Q[k++]=P[i];
}
Q.resize(k-1);
return Q;
}
ll dis(Point a,Point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
ll query(Polygon t){
int sz=(int)t.size();
if(sz<=2) return 0;
ll res=0;
t.pb(t[0]);
++sz;
// int j=2;
for(int i=0;i<sz-1;++i){ /// 枚举所有边
int k=i+1;
for(int add=1;add<=sz-2;++add){
int j= (i+add)%(sz-1);
while(cross(t[j]-t[i],t[k]-t[i])<cross(t[j]-t[i],t[k+1]-t[i])) k++,k=k%(sz-1);
res=max(res,cross(t[j]-t[i],t[k]-t[i]));
// cout <<i <<" "<<j<<" "<<k<<endl;
}
}
return res;
}
int main(void){
int n;
while(scanf("%d",&n)==1){
if(n==-1) break;
Polygon t;
for(int i=1;i<=n;i++) scanf("%lld%lld",&p[i].x,&p[i].y);
for(int i=1;i<=n;i++) t.pb(p[i]);
t=convex_hull(t);
printf("%.2f\n",(double)query(t)/2.0);
}
}