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.
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
题解:旋转卡壳
同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);
}
}