您的位置:首页 > 其它

bzoj1069: [SCOI2007]最大土地面积 计算几何 旋转卡壳

2015-02-26 11:03 357 查看
第一次遇到卡精度。。。。要1e-10才行。

先求出凸包,再在凸包上枚举两个切点,另外两个顶点在这两个点的连线的两端找极值点。#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define pi acos(-1.0)
#define maxn 410000
#define eps 1e-10
int n,cnt;
struct node
{
double x,y;
}p[maxn],dir[10];
double ans;
double sqr(double x)
{
return x*x;
}
double dis(node a,node b)
{
return (sqr(a.x-b.x)+sqr(a.y-b.y));
}
double operator * (node a,node b)
{
return a.x*b.y-a.y*b.x;
}
node operator - (node a,node b)
{
node t;
t.x=a.x-b.x; t.y=a.y-b.y;
return t;
}
node operator + (node a,node b)
{
node t;
t.x=a.x+b.x; t.y=a.y+b.y;
return t;
}
bool cmp(node a,node b)
{
if(fabs((a-p[1])*(b-p[1]))<eps)return dis(p[1],a)<dis(p[1],b);
return (a-p[1])*(b-p[1])>0;
}
bool operator<(node a,node b)
{
if(fabs(a.y-b.y)<eps) return a.x<b.x;
return a.y<b.y;
}
int s[maxn],top;
void solve()
{
for(int i=2;i<=cnt;i++) if(p[i]<p[1])swap(p[i],p[1]);
sort(p+2,p+cnt+1,cmp);
s[1]=1;s[2]=2;top=2;
for(int i=3;i<=cnt;i++)
{
for(;top>1 && (p[s[top]]-p[s[top-1]])*(p[i]-p[s[top-1]])<=0;top--);
top++;s[top]=i;
}
s[top+1]=1;
//for(int i=1;i<=top;i++) ans+=sqrt(dis(p[s[i]],p[s[i+1]]));
}
double get(int a,int b,int c)
{
double tmp=(p[a]-p[b])*(p[a]-p[c]);
return fabs(tmp);
}
void rc()
{
//printf("%d",top);
int a,b;
for(int x=1;x<=top;x++)
{
a=x%top+1;b=(x+2)%top+1;
for(int y=x+2;y<=top;y++)
{
for(;a%top+1!=y&&get(s[a],s[x],s[y])<get(s[a+1],s[x],s[y]);a=a%top+1);
for(;b%top+1!=x&&get(s[b],s[x],s[y])<get(s[b+1],s[x],s[y]);b=b%top+1);
ans=max(ans,get(s[a],s[x],s[y])+get(s[b],s[x],s[y]));
}
}
}
int main()
{
scanf("%d",&n);cnt=n;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
solve();
rc();
printf("%.3lf",ans/2);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: