Convex hull template title.
1 /*3285*/2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <algorithm>7 using namespacestd;8 9 #defineMAXN 55Ten Onetypedefstruct { A intx, y; - } point_t; - the point_t POINTS[MAXN]; - point_t STACK[MAXN]; - inttop; - + voidOutputint); - + DoubleDist (point_t A, point_t b) { A returnsqrt1.0* (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); at } - - intDist2 (point_t A, point_t b) { - return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y); - } - in intCross (point_t A, point_t B, point_t c) { - return(b.x-a.x) * (C.Y-A.Y)-(c.x-a.x) * (b.y-a.y); to } + - BOOLComp (point_t A, point_t b) { the intm = Cross (points[0], A, b); * returnM>0|| (m==0&& Dist2 (points[0], a) <dist2 (points[0], b)); $ }Panax Notoginseng - voidGraham (intN) { the point_t p; + intI, J, K; A thep = points[0]; +K =0; - for(i=1; i<n; ++i) { $ if(points[i].x<p.x | | (points[i].x==p.x && points[i].y<p.y)) { $p =Points[i]; -K =i; - } the } -Points[k] = points[0];Wuyipoints[0] =p; the -Sort (points+1, points+N, comp); Wu -stack[0] = points[0]; Aboutstack[1] = points[1]; $top =1; - - for(i=2; i<n; ++i) { - while(Top && Cross (stack[top-1], Stack[top], points[i]) <=0) A--top; +Stack[++top] =Points[i]; the } - } $ the intMain () { the intT, Case_n; the intN; the intI, J, K; - point_t p; in the #ifndef Online_judge theFreopen ("data.in","R", stdin); About #endif the thescanf"%d", &t); the while(t--) { +scanf"%d%d", &case_n, &n); - for(i=0; i<n; ++i) thescanf"%d%d", &points[i].x, &points[i].y);Bayi Graham (n); theprintf"%d%d\n", Case_n, top+1); thep = stack[0]; -K =0; - for(i=1; i<=top; ++i) { the if(Stack[i].y>p.y | | (Stack[i].y==p.y && stack[i].x<p.x)) { thep =Stack[i]; theK =i; the } - } the for(I=k; i>=0; --i) theprintf"%d%d\n", stack[i].x, stack[i].y); the for(I=top; i>k;--i)94printf"%d%d\n", stack[i].x, stack[i].y); the } the the return 0;98}
"Hdoj" 3285 convex Hull of Lattice Points