hdu 2202 最大三角形_凸包模板

题意:略

思路:直接套用凸包模板

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50010
struct node{
	int x,y,d;
}p[N]; 
int dist(node a,node b){
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); 
}
int crossproduct(node a,node b,node c){
	return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
bool cmp1(node a,node b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}
bool cmp2(node a,node b){
	int cp=crossproduct(p[0],a,b);
	if(!cp)
		return a.d<b.d;
	return cp>0;
}
double Graham(int n){
	int i,j,k;
	sort(p,p+n,cmp1);
	for(i=1;i<n;i++)
		p[i].d=dist(p[0],p[i]);
	sort(p+1,p+n,cmp2);
	int top=1;
	for(i=2;i<n;i++){
		while(top>0&&crossproduct(p[i],p[top-1],p[top])<=0) 
			--top;
		p[++top]=p[i];
	}
	p[++top]=p[0];
	int R=1,D=0;
	/*
	for(int L=0;L<top;++L){
		while(crossproduct(p[L],p[L+1],p[R])<crossproduct(p[L],p[L+1],p[R+1]))
			R=(R+1)%top;
		D=max(D,max(dist(p[L],p[R]),dist(p[L+1],p[R+1])));
	}
	*/
	double sum=0;
	for(i=0;i<top;i++)
		for(j=i+1;j<top;j++)
			for(k=j+1;k<top;k++)
			if(sum<crossproduct(p[i],p[j],p[k]))
				sum=crossproduct(p[i],p[j],p[k]);
	return sum*0.5;
}
int main(int argc, char** argv) {
	int n;
	while(scanf("%d",&n)!=EOF){
		for(int i=0;i<n;i++)
			scanf("%d%d",&p[i].x,&p[i].y);
		printf("%.2lf\n",Graham(n));
	}
	return 0;
}


转载于:https://www.cnblogs.com/neng18/p/3676398.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值