Title: Minimum Rectangle cover
First there is a conclusion: there must be an edge on the convex hull coincident with the edge of the rectangle.
Proof: If there is no edge coincident with one edge of the rectangle, then I will rotate the rectangle a little bit smaller than before.
So we enumerate one of the edges and jam the remaining three points
This spinning jam is really called a jam--fortunately, 1 a dropped--
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 50500#define EPS 1e-7using namespace std;struct point{double x, y; Point () {}point (double _,double __): X (_), Y (__) {}friend istream& operator >> (IStream &_,point &p) { scanf ("%lf%lf", &p.x,&p.y); return _;} BOOL operator < (const point &p) const{if (Fabs (x-p.x) <eps) return Y<p.y;return x<p.x;} Point operator + (const point &p) Const{return Point (X+P.X,Y+P.Y); Point operator-(const point &p) Const{return Point (X-P.X,Y-P.Y); Double operator * (const point &p) Const{return x*p.y-y*p.x;} Point operator * (const double &rate) Const{return point (x*rate,y*rate); Friend ostream& operator << (ostream& _,const point &p) {printf ("%.5lf%.5lf", p.x,p.y); return _;}} Points[m];struct Line{point p,v; Line () {}line (const point &_,const point &__):p (_), V (__) {}};int n,top;double ans=1e15; Point ans_points[4]; Point *stack[m<<1]; Point Get_intersection (const line &l1,const line &l2) {point u=l1.p-l2.p;double temp= (l2.v*u)/(L1.V*L2.V); return l1.p+l1.v*temp;} void Get_convex_hull () {static point *stack[m];int i,top=0;for (i=1;i<=n;i++) {while (top>=2 && (*stack[ TOP]-*STACK[TOP-1]) * (Points[i]-*stack[top]) >=-eps) stack[top--]=0x0;stack[++top]=&points[i];} For (i=1;i<=top;i++):: Stack[++::top]=stack[i];top=0;for (i=1;i<=n;i++) {while (top>=2 && (*stack[ TOP]-*STACK[TOP-1]) * (Points[i]-*stack[top]) <=eps) stack[top--]=0x0;stack[++top]=&points[i];} For (i=top-1;i>1;i--):: Stack[++::top]=stack[i];int limit=::top;for (i=1;i<=limit;i++):: stack[++::top]=:: STACK[I];::STACK[++::TOP]=::STACK[1];} void Rotating_calipers () {int limit=top>>1; Point **p1,**p2,**p3,**p4;p1=stack+1; Point v1= (* * (p1+1)-**P1); Point v2 (v1.y,-v1.x); Point v3 (v2.y,-v2.x); Point V4 (v3.y,-v3.x), for (P2=P1; (* * (p2+1)-**p2) *v2<0;p2++); for (P3=P2; (* * (p3+1)-**p3) *v3<0;p3++); for (p4=p3 ;(** (p4+1)-**P4) *v4<0;p4++), for (;p 1<=stack+limit;p1++) {v1= (* * (p1+1)-**P1); V2=point (v1.y,-v1.x); V3=point ( v2.y,-v2.x), V4=point (v3.y,-v3.x), for (;(* * (p2+1)-**P2) *v2<0;p2++), for (;(* * (p3+1)-**p3) *v3<0;p3++), for (;(* * (p4+1)-**P4) *v4<0;p4++); Point Temp_points[4]; Line L1 (**P1,V1); Line L2 (**P2,V2); Line L3 (**P3,V3); Line L4 (**P4,V4); temp_points[0]=get_intersection (L1,L4); temp_points[1]=get_intersection (L4,L3); temp_points[2]= Get_intersection (L3,L2); Temp_points[3]=get_intersection (L2,L1);d ouble area= (temp_points[1]-temp_points[0]) * ( Temp_points[3]-temp_points[0]); if (Area<ans) memcpy (ans_points,temp_points,sizeof ans_points), Ans=area;}} int main () {int i;cin>>n;for (i=1;i<=n;i++) cin>>points[i];sort (points+1,points+n+1); Get_convex_hull (); Rotating_calipers ();p rintf ("%.5lf\n", ans); int st=0;for (i=1;i<4;i++) if (Ans_points[i].y<ans_points[st].y | | Fabs (ANS_POINTS[I].Y-ANS_POINTS[ST].Y) <eps && ans_points[i].x<ans_points[st].x) st=i;for (i=0;i<4 ; i++) Cout<<anS_points[i+st&3]<<endl;return 0;}
Bzoj 1185 HNOI2007 minimum rectangular cover rotation jam