hdu 3934 Summer holiday (旋转卡壳)

Summer holiday

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1885    Accepted Submission(s): 675


Problem Description
Summer holiday was coming! Xiaomao went back to his hometown where he yearn day and night, his hometown has picturesque scenery. There is a big forest beside his village. There are n trees in the forest.
Now they want to across the forest with a rope (the rope won't cross). Try to find 3 trees in this tree on the rope which can make the area of the surrounded largest. Work out the area of it.
 

Input
The input will consist of several test cases. The first line contains a positive integer N(3<=N<=10^6), the number of trees, followed N lines, each gives the (xi, yi ) coordinates.
 

Output
Print the largest area, one number a line with two decimal places.
 

Sample Input
  
  
4 0 0 1 1 0 1 1 0
 

Sample Output
  
  
0.50
 

Source
 

Recommend
We have carefully selected several similar problems for you:   3932  3933  3931  3935  3936 
 

Statistic |  Submit |  Discuss | Note

题解:旋转卡壳

同hdu 2202

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 50003
#define eps 1e-10
using namespace std;
struct vector {
	double x,y;
	vector (double X=0,double Y=0) {
		x=X,y=Y;
	}
}a[N],ch[N];
typedef vector point;
vector operator -(vector a,vector b){
	return vector (a.x-b.x,a.y-b.y);
}
vector operator +(vector a,vector b){
	return vector (a.x+b.x,a.y+b.y);
}
vector operator *(vector a,double t){
	return vector (a.x*t,a.y*t);
}
bool operator <(vector a,vector b)
{
	return a.x<b.x||a.x==b.x&&a.y<b.y;
}
int n,m;
int dcmp(double x)
{
	if (fabs(x)<eps) return 0;
	return x<0?-1:1;
}
double dot(vector a,vector b)
{
	return a.x*b.x+a.y*b.y;
}
double cross(vector a,vector b)
{
	return a.x*b.y-a.y*b.x;
}
double len(vector a)
{
	return sqrt(a.x*a.x+a.y*a.y);
}
double distl(point a,point b,point c)
{
	vector v=a-b; vector u=c-b;
	return fabs(cross(u,v))/len(u);
}
void convexhull()
{
    sort(a+1,a+n+1);
    m=0;
    if (n==1) {
    	ch[++m]=a[1];
    	return;
	}
	for (int i=1;i<=n;i++){
		while (m>1&&cross(ch[m-1]-ch[m-2],a[i]-ch[m-2])<=0) m--;
		ch[m++]=a[i];
	}
	int k=m;
	for (int i=n-1;i>=1;i--){
		while (m>k&&cross(ch[m-1]-ch[m-2],a[i]-ch[m-2])<=0) m--;
		ch[m++]=a[i]; 
	}
	m--;
}
double rotating()
{
	if (m<=2) return 0; 
	if (m==3) return fabs(cross(ch[1]-ch[0],ch[2]-ch[0]))/2;
	double ans=0;
	int i,j,k;
	for (int i=0;i<m;i++){
		j=(i+1)%m;
		k=(j+1)%m;
		//cout<<i<<" "<<j<<" "<<k<<endl;
		while (fabs(cross(ch[i]-ch[j],ch[i]-ch[k]))<fabs(cross(ch[i]-ch[j],ch[i]-ch[(k+1)%m]))) k=(k+1)%m;
		while (i!=j&&k!=i) {
			ans=max(ans,fabs(cross(ch[i]-ch[j],ch[i]-ch[k])));
			while (fabs(cross(ch[i]-ch[j],ch[i]-ch[k]))<fabs(cross(ch[i]-ch[j],ch[i]-ch[(k+1)%m]))) k=(k+1)%m;
			j=(j+1)%m;
		}
	}
	return ans/2.0;
}
int main()
{
	freopen("a.in","r",stdin);
	//freopen("my.out","w",stdout);
	while (scanf("%d",&n)!=EOF ) {
		for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
		convexhull();
		double ans=rotating();
		printf("%.2lf\n",ans);
	}
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值