Scrambled Polygon
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 7805 |
|
Accepted: 3712 |
Description
A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments is called the vertices of the polygon. When one starts at any vertex of a closed polygon and traverses each bounding line segment exactly once, one comes back to The starting vertex.
A closed polygon is called convex if the line segment joining any and points of the polygon lies in the polygon. Figure 1 shows a closed polygon which are convex and one which is not convex. (informally, a closed polygon is convex if its border doesn ' t has any "dents".)
The subject of this problem are a closed convex polygon in the coordinate plane, one of the whose vertices is the origin (x = 0 , y = 0). Figure 2 shows an example. Such a polygon would have both properties significant for this problem.
The first is the vertices of the polygon would be confined to three or fewer of the four quadrants of the COO Rdinate plane. In the example shown in Figure 2, none of the vertices is in the second quadrant (where x < 0, y > 0).
To describe the second property, suppose you ' take a trip ' around the Polygon:start at (0, 0), visit all other vertices E Xactly once, and arrive at (0, 0). As you visit each vertex (other than (0, 0)), draw the diagonal, which connects the current vertex with (0, 0), and Calculat E The slope of this diagonal. Then, within each quadrant, the slopes of these diagonals would form a decreasing or increasing sequence of numbers, i.e., They'll be sorted. Figure 3 illustrates.
Input
The input lists the vertices of a closed convex polygon in the plane. The number of lines in the input would be is at least three and no more than 50. Each line contains the x and y coordinates of one vertex. Each x and y coordinate are an integer in the range-999..999. The vertex on the first line of the input file would be the origin, i.e., x = 0 and y = 0. Otherwise, the vertices is in a scrambled order. Except for the origin, no vertex'll be on the x-axis or the y-axis. No three vertices is colinear.
Output
The output lists the vertices of the given polygon, one vertex per line. Each vertex from the input appears exactly once in the output. The origin (0,0) is the vertex on the first line of the output. The order of vertices in the output would determine a trip taken along the polygon's border, in the counterclockwise direct Ion. The output format for each vertex is (x, y) as shown below.
Sample Input
0 070-5060 30-30-5080 2050-6090-20-30-40-10-6090 10
Sample Output
(0,0) ( -30,-40) ( -30,-50) ( -10,-60) (50,-60) (70,-50) (90,-20) (90,10) (80,20) (60,30)
Test instructions: is to give you some points, the beginning has been told you are (0,0), let the output of this polygon, the slope from small to large representations;
The bottom line: The order is good, attention to the addition into the multiplication ...
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include < Algorithm> #include <queue>using namespace std;const int inf=0x3f3f3f3f; #define MEM (x, y) memset (x,y,sizeof ) #define SI (x) scanf ("%d", &x), struct node{int x,y;friend bool operator < (Node A,node b) {if (a.y*b.x<b.y*a.x) return true;else return false;}} Dt[100010];int Main () {int k=0;while (~scanf ("%d%d", &dt[k].x,&dt[k].y)) K++;sort (dt+1,dt+k); for (int i=0;i <k;i++) printf ("(%d,%d) \ n", dt[i].x,dt[i].y); return 0;}
Scrambled Polygon (convex polygon, slope)