"Minimum rectangular area coverage: convex hull + rotational jam" UVA 10173Smallest bounding Rectangle

Source: Internet
Author: User

"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", &AMP;P[I].X,&AMP;P[I].Y); } n = Graham (p,n,res);//Construction Convex bag    printf("%.4f\n", Minretanglecover ()); }return 0;}
    • Bold Ctrl + B
    • Italic Body Ctrl + I
    • ReferenceCtrl + Q
    • Insert LinkCtrl + L
    • Inserting codeCtrl + K
    • Insert PictureCtrl + G
    • Promote titleCtrl + H
    • Ordered listCtrl + O
    • Unordered listCtrl + U
    • LineCtrl + R
    • RevokeCtrl + Z
    • RedoCtrl + 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.