Title Link: http://poj.org/problem?id=2007
Test instructions: The vertex coordinates of a convex polygon are given in order to output each vertex in a counter-clockwise sequence. The first point given must be (0,0), there is no other point on the axis, there is no three-point collinear situation.
Can be used to sort the cross product, vector p1xp2 > 0 shows that p1 counter-clockwise rotation <180 degree can be p2;
/*in order to give the vertex coordinates of convex polygon, it is required to output each vertex in counter-clockwise sequence. The first point given must be (0,0), there is no other point on the axis, there is no three-point collinear situation. */#include<stdio.h>#include<algorithm>#include<iostream>using namespaceStd;typedefLong LongLL;Const intINF =0x3f3f3f3f;Const intN = the;structpoint{Doublex, y; Point () {}, point (DoubleX_Doubley_): X (x_), Y (y_) {} point friendoperator- (ConstPoint &p1,ConstPoint &p2)///vector p2p1; { returnPoint (p1.x-p2.x, p1.y-p2.y); } DoubleFriendoperator^ (ConstPoint &p1,ConstPoint &p2) { returnp1.x*p2.y-p1.y*p2.x; ///P1XP2: >0 description p1 counterclockwise rotation<180 degree can get P2; }};intCMP (Point P1, point p2) {if((P1-point (0,0) ^ (P2-point (0,0))) >0) return 1; return 0;} Point A[n];intN;intMain () {n=0; while(SCANF ("%LF%LF", &a[n].x, &a[n].y)!=eof) n++; Sort (a+1, A +N, CMP); for(intI=0; i<n; i++) cout<<"("<<a[i].x<<","<<a[i].y<<")"<<Endl; return 0;}
View Code
Scrambled Polygon---poj2007 (sorted by cross product)