标签:poj
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 50010
#define eps 1e-8
using namespace std;
int n;
struct Point
{
double x,y;
friend istream& operator >> (istream &_,Point &a)
{
scanf("%lf%lf",&a.x,&a.y);
return _;
}
Point(){}
Point(double a,double b):x(a),y(b){}
Point operator + (const Point &a)
{return Point(x+a.x,y+a.y);}
Point operator - (const Point &a)
{return Point(x-a.x,y-a.y);}
Point operator * (double rate)
{return Point(x*rate,y*rate);}
double operator * (const Point &a)
{return x*a.x+y*a.y;}
double operator ^ (const Point &a)
{return x*a.y-y*a.x;}
friend bool operator < (Point a,Point b)
{
if(a.x==b.x)return a.y>b.y;
return a.x<b.x;
}
}pt[N];
int sta[N];
int staa[N];
int top;
int topp;
double Rotating_Calipers()
{
double ret=0;
for(int i=0;i<topp;i++)
{
int p=1,q=1;
for(int j=i+2;j<topp;j++)
{
while(((pt[staa[p+1]]-pt[staa[i]])^(pt[staa[j]]-pt[staa[i]]))>
((pt[staa[p]]-pt[staa[i]])^(pt[staa[j]]-pt[staa[i]])))
p=(p+1)%topp;
while(((pt[staa[j]]-pt[staa[i]])^(pt[staa[q+1]]-pt[staa[i]]))>
((pt[staa[j]]-pt[staa[i]])^(pt[staa[q]]-pt[staa[i]])))
q=(q+1)%topp;
ret=max(ret,((pt[staa[p]]-pt[staa[i]])^(pt[staa[j]]-pt[staa[i]]))+
((pt[staa[j]]-pt[staa[i]])^(pt[staa[q]]-pt[staa[i]])));
}
}
return ret;
}
int main()
{
while(~scanf("%d",&n)&&n!=-1)
{
for(int i=1;i<=n;i++)cin>>pt[i];
sort(pt+1,pt+n+1);
top=0,topp=-1;
for(int i=1;i<=n;i++)
{
while(top>1&&((pt[i]-pt[sta[top]])^(pt[sta[top]]-pt[sta[top-1]]))>=0)top--;
sta[++top]=i;
}
for(int i=1;i<top;i++)
{
staa[++topp]=sta[i];
}
top=0;
for(int i=1;i<=n;i++)
{
while(top>1&&((pt[i]-pt[sta[top]])^(pt[sta[top]]-pt[sta[top-1]]))<=0)top--;
sta[++top]=i;
}
for(int i=top;i>=1;i--)
{
staa[++topp]=sta[i];
}
printf("%.3lf\n",Rotating_Calipers()/2.0);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
BZOJ 1069 [SCOI2007]最大土地面积 旋转卡壳
标签:poj
原文地址:http://blog.csdn.net/wzq_qwq/article/details/48314479