"Minimum rectangular area overlay: convex hull + rotational jam" uva 10173 smallest bounding rectangle topic link: UVa 10173 smallest bounding rectangle topic
Give you n points to be able to cover the smallest rectangular area of all point sets.
The author's 2nd convex hull problem, convex hull + rotating jam, realizes the minimum rectangular area coverage of point set
">=0" written "<=0" pit me for an afternoon! Qaq
Talk about the idea.
- ①graham ' s scan method for building convex hull, time complexity O (NLOGN)
- ② using the idea of rotating jam, the minimum rectangle has at least one side and the convex hull collinear. So directly enumerate the bottom edge, using the rotation jam to determine the remaining three points can be (Kuangbin the minimum rectangle overlay template, but the operation function I defined in the structure, save space!) )
Reference Code
/*====================================*|* Minimum rectangular area coverage *| | * Polygon A must be convex (default: Counterclockwise order) *|\*====================================*//*author:hacker_vision*/#include <bits/stdc++.h>#define EPS 1e-8using namespace STD;Const int_max =1e3+Ten;Const DoublePI =ACOs(-1);intNintSgnDoublex) {//three-state function if(fabs(x) <eps)return 0;Else returnx<0?-1:1;}structpoint{Doublex, y;} P[_max],res[_max];BOOLMult (Point sp,point ep,point op) {return(sp.x-op.x) * (EP.Y-OP.Y) >= (ep.x-op.x) * (SP.Y-OP.Y);}BOOL operator< (ConstPoint &l,ConstPoint &r) {returnL.y < R.Y | | (L.y = = R.y && l.x < r.x);}intGraham (Point pnt[),intN, point res[]) {//Construction Convex bag intI,len, k =0, top =1; Sort (pnt,pnt+n);if(n = =0)return 0; res[0] = pnt[0];if(n = =1)return 1; res[1] = pnt[1];if(n = =2)return 2; res[2] = pnt[2]; for(inti =2; I < n; + + i) { while(Top && mult (pnt[i],res[top],res[top-1])) top--; Res[++top] = Pnt[i]; } len = top; Res[++top] = pnt[n-2]; for(i = n-3; I >=0; --i) { while(Top!=len && mult (pnt[i],res[top],res[top-1])) top--; Res[++top] = Pnt[i]; }returnTop//Returns the number of midpoints in the convex hull}DoubleLen (Point A,point B) {//Returns the modulus of the vector ab squared return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y);}DoubleDot (point a,point b,point C) {//Point multiplication return(c.x-a.x) * (b.x-a.x) + (C.Y-A.Y) * (B.Y-A.Y);}DoubleCross (point A,point b,point C) {//Fork Multiply return(b.x-a.x) * (C.Y-A.Y)-(B.Y-A.Y) * (c.x-a.x);}DoubleMinretanglecover () {//Minimum rectangular area coverage (rotating jam) if(N <3)return 0.0; Res[n] = res [0];DoubleAns =-1;intR =1, p =1, q; for(inti =0; I < n; + + i) {//card out off Edge res[i]-res[i+1] farthest point while(SGN (res[i],res[i+1],res[r+1])-cross (res[i],res[i+1],RES[R]) >=0) R = (r+1)% n;//Card out res[i]-res[i+1] in the direction of the forward N farthest point while(SGN (Dot (res[i],res[i+1],res[p+1])-dot (res[i],res[i+1],RES[P]) >=0) p = (p+1)% n;if(i = =0) q = p;//card out res[i]-res[i+1] direction negative to the farthest point while(SGN (Dot (res[i],res[i+1],res[q+1])-dot (res[i],res[i+1],RES[Q]) <=0) Q = (q+1)% n;DoubleD = Len (res[i],res[i+1]);Doubletemp = Cross (res[i],res[i+1],RES[R]) * (Dot (res[i],res[i+1],RES[P])-dot (res[i],res[i+1],RES[Q])/D;if(Ans <0|| Ans > temp) ans = temp; }returnAns;}intMain () {#ifndef Online_judgeFreopen ("Input.txt","R", stdin);#endif //Online_judge while(scanf("%d", &n) = =1&& N) { for(inti =0; I < n; + + i) {scanf("%LF%LF", &P[I].X,&P[I].Y); } n = Graham (p,n,res);//Construction Convex bag printf("%.4f\n", Minretanglecover ()); }return 0;}
- Bold
Ctrl + B
- Italic Body
Ctrl + I
- Reference
Ctrl + Q
- Insert Link
Ctrl + L
- Inserting code
Ctrl + K
- Insert Picture
Ctrl + G
- Promote title
Ctrl + H
- Ordered list
Ctrl + O
- Unordered list
Ctrl + U
- Line
Ctrl + R
- Revoke
Ctrl + Z
- Redo
Ctrl + Y
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Minimum rectangular area coverage: convex hull + rotational jam" UVA 10173Smallest bounding Rectangle