[SCOI2007]最大土地面积
2018-01-12 07:23
281 查看
Description
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大。
Input
第1行一个正整数N,接下来N行,每行2个数x,y,表示该点的横坐标和纵坐标。Output
最大的多边形面积,答案精确到小数点后3位。Sample Input
50 0
1 0
1 1
0 1
0.5 0.5
Sample Output
1.000HINT
数据范围 n<=2000, |x|,|y|<=100000[b]首先最大的4个点一定在凸包上[/b]
[b]先把凸包求出来[/b]
[b]然后选定对角线,然后发现另外两个顶点是单调的,用旋转卡壳的思想[/b]
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; struct point { double x,y; }p[5001],s[5001]; int n,top; double ans,eps=1e-5; int dcmp(double x) { if (x<-eps) return -1; if (x>eps) return 1; return 0; } double operator *(point a,point b) { return a.x*b.y-a.y*b.x; } point operator -(point a,point b) { return (point){a.x-b.x,a.y-b.y}; } double dist(point a,point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } bool cmp(point a,point b) { return (a.y<b.y)||(a.y==b.y&&a.x<b.x); } bool cmp2(point a,point b) { int t=dcmp((p[1]-a)*(p[1]-b)); if (t==0) return dist(p[1],a)<dist(p[1],b); return t>0; } void graham() {int i; sort(p+1,p+n+1,cmp); sort(p+2,p+n+1,cmp2); s[++top]=p[1];s[++top]=p[2]; for (i=3;i<=n;i++) { while (top>1&&dcmp((p[i]-s[top-1])*(s[top]-s[top-1]))>=0) top--; s[++top]=p[i]; } } void solve() {int i,j; s[top+1]=s[1]; for (i=1;i<=top-2;i++) { int a=i%top+1,b=(i+2)%top+1; for (j=i+2;j<=top;j++) { while (a%top+1!=j&&dcmp((s[a+1]-s[i])*(s[j]-s[i])-(s[a]-s[i])*(s[j]-s[i]))>0) a=a%top+1; while (b%top+1!=i&&dcmp((s[j]-s[i])*(s[b+1]-s[i])-(s[j]-s[i])*(s[b]-s[i]))>0) b=b%top+1; //cout<<i<<' '<<a<<' '<<j<<' '<<b<<endl; ans=max(ans,(s[a]-s[i])*(s[j]-s[i])+(s[j]-s[i])*(s[b]-s[i])); } } } int main() {int i; cin>>n; for (i=1;i<=n;i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } graham(); solve(); printf("%.3lf\n",ans/2.0); }
相关文章推荐
- BZOJ1069 [SCOI2007]最大土地面积 【凸包 + 旋转卡壳】
- bzoj 1069: [SCOI2007]最大土地面积 (旋转卡壳)
- BZOJ 1069: [SCOI2007]最大土地面积 [旋转卡壳]
- bzoj1069: [SCOI2007]最大土地面积
- bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳
- BZOJ-1069 [SCOI2007]最大土地面积
- [凸包] BZOJ1069: [SCOI2007]最大土地面积
- 【SCOI2007】bzoj1069 最大土地面积
- ●BZOJ 1069 [SCOI2007]最大土地面积
- 1069: [SCOI2007]最大土地面积
- BZOJ 1069 [SCOI2007] 最大土地面积
- 【bzoj1069】[SCOI2007]最大土地面积 凸包+旋转卡壳
- [BZOJ1069][SCOI2007]最大土地面积 凸包+旋转卡壳
- BZOJ 1069: [SCOI2007]最大土地面积
- [BZOJ1069]SCOI2007最大土地面积|凸包|旋转卡壳
- 1069: [SCOI2007]最大土地面积|旋转卡壳
- [BZOJ1069][SCOI2007]最大土地面积
- [BZOJ1069][SCOI2007]最大土地面积(水平扫描法求凸包+旋转卡壳)
- BZOJ 1069 SCOI 2007 最大土地面积 凸包+旋转卡壳
- 【BZOJ 1069】 [SCOI2007]最大土地面积