"Hdoj" 1348 Wall

Source: Internet
Author: User

Calculate geometry-convex hull template title, Graham algorithm solution.

1 /*1348*/2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <cmath>7#include <algorithm>8 using namespacestd;9 Ten #defineMAXN 1005 One  Atypedefstructpoint_t { -     Doublex, y; - point_t () {} thepoint_t (DoubleXxDoubleyy) { -x = XX; y =yy; -     } - } point_t; +  - point_t STACK[MAXN]; + point_t POINTS[MAXN]; A Const DoublePI = ACOs (-1.0); at intN; -  - DoubleLength (point_t A, point_t b) { -     returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); - } -  in DoubleCross (point_t p0, point_t p1, point_t p2) { -     return(p1.x-p0.x) * (P2.Y-P0.Y)-(p2.x-p0.x) * (P1.Y-p0.y); to } +  - BOOLComp (point_t A, point_t b) { the     Doublek = Cross (points[0], A, b); *     return! (k<0|| (k==0&& Length (points[0], a) >length (points[0], b )); $ }Panax Notoginseng  - DoubleGraham () { the     DoubleRET =0; +     intI, J, K; A     inttop; the point_t P0; +      -P0 = points[0]; $K =0; $      for(i=1; i<n; ++i) { -         if(points[i].x<p0.x | | (points[i].x==p0.x && points[i].y<p0.y)) { -P0 =Points[i]; theK =i; -         }Wuyi     } the      -Points[k] = points[0]; Wupoints[0] =P0; -Sort (points+1, points+N, comp); About      $stack[0] = points[0]; -stack[1] = points[1]; -stack[2] = points[2]; -top =2; A      for(i=3; i<n; ++i) { +          while(Cross (stack[top-1], Stack[top], points[i]) <=0&& top>1) the--top; -Stack[++top] =Points[i]; $     } theStack[++top] =P0; the      for(i=1; i<=top; ++i) theRET + = Length (stack[i-1], stack[i]); the      -     returnret; in } the  the intMain () { About     intT; the     intI, J, K, TMP; the     Doublel, ans; the      + #ifndef Online_judge -Freopen ("data.in","R", stdin); the     #endifBayi      thescanf"%d", &t); the      while(t--) { -scanf"%d%lf", &n, &l); -          for(i=0; i<n; ++i) thescanf"%LF%LF", &points[i].x, &points[i].y); theAns =Graham (); theAns + = PI * (l +l); theprintf"%.0lf\n", ans); -         if(t) theprintf"\ n"); the     } the     94     return 0; the}

"Hdoj" 1348 Wall

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.