1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include<bits/stdc++.h> #define double long double #define eps 1e-18 using namespace std; const int maxn=5e4+10; struct geometric { double x, y; geometric(double X=0, double Y=0) :x(X), y(Y) {} friend geometric operator + (const geometric a, const geometric b) { return geometric(a.x+b.x, a.y+b.y); } friend geometric operator - (const geometric a, const geometric b) { return geometric(a.x-b.x, a.y-b.y); } friend geometric operator * (const geometric a, double p) { return geometric(a.x*p, a.y*p); } friend geometric operator / (const geometric a, double p) { return geometric(a.x/p, a.y/p); } }p[maxn], st[maxn]; int n, cnt, top;double S=1e20; double dis(geometric a, geometric b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double dot(geometric a1, geometric a2, geometric b1, geometric b2) { return (a2.x-a1.x)*(b2.x-b1.x)+(a2.y-a1.y)*(b2.y-b1.y); } double cross(geometric a1, geometric a2, geometric b1, geometric b2) { return (a2.x-a1.x)*(b2.y-b1.y)-(a2.y-a1.y)*(b2.x-b1.x); } bool cmp(geometric a, geometric b) { double tmp; tmp=cross(p[1], a, p[1], b); if(tmp>0)return true; if(tmp==0)return dis(p[1], a)<=dis(p[1], b); return false; } int main() { while(true) { memset(st,0,sizeof(st)); memset(p,0,sizeof(p)); scanf("%d", &n); if(n==0)break; top=0;cnt=0;S=1e20; for(int i=1;i<=n;i++) { double x, y; scanf("%Lf%Lf", &x, &y); p[++cnt]=geometric(x, y); if(i==1) continue; if(p[cnt].y<p[1].y) swap(p[cnt], p[1]); if(p[cnt].y==p[1].y&&p[cnt].x>p[1].x) swap(p[cnt], p[1]); } sort(p+2, p+cnt+1, cmp); st[++top]=p[1]; for(int i=2;i<=cnt;i++) { while(top>1&&cross(st[top-1], st[top], st[top], p[i])<=0) top--; st[++top]=p[i]; } st[++top]=p[1];
if(top<=3) { printf("0.0000\n"); continue; } st[0]=st[top-1]; for(int i=2, j=3,l,r;i<=top;i++) { r=(i==top)?1:i;l=i-1; while(cross(st[i-1], st[i], st[i], st[j])<cross(st[i-1], st[i], st[i], st[j+1])) j=(j==top-1)?1:j+1; while(dot(st[i-1], st[i], st[i], st[r])<dot(st[i-1], st[i], st[i], st[r+1])) r=(r==top-1)?1:r+1; while(dot(st[i], st[i-1], st[i-1], st[l])<dot(st[i], st[i-1], st[i-1], st[l-1])) l=(l==1)?top-1:l-1; double wide, high, len=dis(st[i-1], st[i]); wide=fabs(dot(st[i], st[i-1], st[i-1], st[l]))/len+fabs(dot(st[i-1], st[i], st[i], st[r]))/len+len; high=fabs(cross(st[i-1], st[i], st[i-1], st[j]))/len; S=min(S, high*wide); } printf("%.4Lf\n", S); } return 0; }
|