题解
选的点一定是凸包上的点?
code
#include<bits/stdc++.h>
using namespace std;
struct poi
{
double x,y;
}node[50005];
int q[100005];
double cal(int a,int b,int c)
{
double x1=node[a].x-node[b].x,y1=node[a].y-node[b].y,x2=node[b].x-node[c].x,y2=node[b].y-node[c].y;
return x1*y2-x2*y1;
}
bool cmp(poi a,poi b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y>b.y;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=1;i<=n;i++) cin>>node[i].x>>node[i].y;
sort(node+1,node+1+n,cmp);//排序忘了,老是tle
int top=0;
for(int i=1;i<=n;i++)
{
while(top>1&&cal(i,q[top],q[top-1])<0) top--;
q[++top]=i;
}
int top1=top;
for(int i=n-1;i>=1;i--)
{
while(top>top1&&cal(i,q[top],q[top-1])<0) top--;
q[++top]=i;
}
double ans=0;
for(int i=1;i<top;i++)
for(int j=i+1;j<top;j++)
for(int k=j+1;k<top;k++)
ans=max(ans,abs(cal(q[i],q[j],q[k])));
printf("%.2lf\n",ans*0.5);
}
return 0;
}
标签:node,最大,int,double,top,cal,poi,三角形
From: https://www.cnblogs.com/pure4knowledge/p/18087988