hdu 2202

OJ

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

#define N 50005
int n;
int ktoal;
struct p
{
	int x,y;
	void in()
	{
		scanf("%d%d",&x,&y);
	}
};
p ar[N];
p fundation;
int cmpy(p a,p b)
{
	if(a.y != b.y) return a.y<b.y;
	return a.x < b.x;
}
int squaredis(p a,p b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int mul(p a,p b,p c)
{
	return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
int cmp(const void * a,const void * b)
{
	struct p* aa = (p*) a;
	struct p * bb = (p*) b;
	int k = mul(*aa,*bb,fundation);
	if(k<0) return 1;
	else if(k==0&&squaredis(*aa,fundation)>= squaredis(*bb,fundation))
		return 1;
	 return -1;
	
}
double area(int a,int b,int c)
{
	return fabs(1.0*mul(ar[a],ar[b],ar[c]))/2.0;
}
void grah()
{
	 ktoal = 2;
	//ar[n] = fundation;
	for(int i = 3;i<n;i++)
	{
		while((mul(ar[ktoal],ar[i],ar[ktoal-1])<=0)&&ktoal>=2) 
			ktoal--;
		ar[++ktoal]= ar[i];
	}
}
double maxarea()
{
	//double max = 0;
	double max = 0;
	/*int p,q;
	for(int i=0;i<n;i++)
	{
		p = (i+1)%n;q = (i+2)%n;
		while(area(i,q,(q+1)%n)>area(i,p,q)) p = q,q = (q+1)%n;
		if(area(i,p,q)>max) max = area(i,p,q);
	}
	return max;*/

	for(int i=0;i<ktoal-1;i++)
		for(int j=i+1;j<ktoal;j++)
			for(int k=j+1;k<=ktoal;k++)
				if(area(i,j,k)>max) max = area(i,j,k);
	return max;
}
void init()
{
    while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		{
			ar[i].in();
		}
		if(n<=2) { printf("0.00\n");continue;}
		if(n==3)
		{
			printf("%.2lf\n",area(0,1,2));
			continue;
		}
		sort(ar,ar+n,cmpy);
		fundation = ar[0];
		qsort(ar+1,n-1,sizeof(ar[0]),cmp);
		grah();
		printf("%.2lf\n",maxarea());

	}
	return ;
}
int main()
{
	init();
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值