解题思路:
1、先求n个点的凸包,因为这三个点肯定在凸包上;
2、用旋转卡壳法求最大面积
代码如下:
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<time.h>
#include<math.h>
#define N 50005
#define eps 1e-9
#define P system("pause")
using namespace std;
struct node
{
double x,y;
}p[N],ch[N];
node operator - (node a,node b)
{
a.x -= b.x;
a.y -= b.y;
return a;
}
double cross(node a, node b)
{
return a.x*b.y - a.y*b.x;
}
bool cmp(node a,node b)
{
if(a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
double area(node a,node b,node c)
{
return fabs(cross(a-b,a-c)/2);
}
int convexhull(int n) //求凸包模板
{
sort(p,p+n,cmp);
int i,m = 0;
for(i=0; i<n; i++)
{
while(m>1 && cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0)
m--;
ch[m++] = p[i];
}
int k = m;
for(i = n-2; i >=0; i--)
{
while(m > k && cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) <= 0)
m--;
ch[m++] = p[i];
}
if(n > 1) m--;
return m;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);cc
int n;
while(scanf("%d",&n) && n)
{
int i;
for(i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int top = convexhull(n);
// for(i= 0; i < top; i++)
// cout<<ch[i].x<<" "<<ch[i].y<<endl;
double ans = 0;
int j,k;
for(i = 0; i < top; i++) //求每个点i对应的最大三角形
{
j = (i + 1)%top;
k = (j + 1)%top;
while(k != i && area(ch[i],ch[j],ch[k]) < area(ch[i], ch[j], ch[(k+1)%top]))
k = (k+1)%top;
if(k == i) continue;
int kk = (k+1)%top;
while(j != kk && k != i)
{
ans = max(ans,area(ch[i],ch[j],ch[k]));
while(k != i && area(ch[i],ch[j],ch[k]) < area(ch[i],ch[j],ch[(k+1)%top]))
k = (k+1)%top;
j = (j+1)%top;
}
}
printf("%0.2lf\n",ans);
}
// P;
return 0;
}