Scrambled Polygon
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 8005   Accepted: 3798

Description

A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are 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
two points of the polygon lies in the polygon. Figure 1 shows a closed
polygon which is convex and one which is not convex. (Informally, a
closed polygon is convex if its border doesn't have any "dents".)



The subject of this problem is a closed convex polygon in the
coordinate plane, one of whose vertices is the origin (x = 0, y = 0).
Figure 2 shows an example. Such a polygon will have two properties
significant for this problem.

The first property is that the vertices of the polygon will be
confined to three or fewer of the four quadrants of the coordinate
plane. In the example shown in Figure 2, none of the vertices are 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 exactly once, and
arrive at (0, 0). As you visit each vertex (other than (0, 0)), draw
the diagonal that connects the current vertex with (0, 0), and calculate
the slope of this diagonal. Then, within each quadrant, the slopes of
these diagonals will form a decreasing or increasing sequence of
numbers, i.e., they will be sorted. Figure 3 illustrates this point.



Input

The
input lists the vertices of a closed convex polygon in the plane. The
number of lines in the input will be at least three but no more than 50.
Each line contains the x and y coordinates of one vertex. Each x and y
coordinate is an integer in the range -999..999. The vertex on the first
line of the input file will be the origin, i.e., x = 0 and y = 0.
Otherwise, the vertices may be in a scrambled order. Except for the
origin, no vertex will be on the x-axis or the y-axis. No three vertices
are 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 will determine a trip taken along the polygon's
border, in the counterclockwise direction. The output format for each
vertex is (x,y) as shown below.

Sample Input

0 0
70 -50
60 30
-30 -50
80 20
50 -60
90 -20
-30 -40
-10 -60
90 10

Sample Output

(0,0)
(-30,-40)
(-30,-50)
(-10,-60)
(50,-60)
(70,-50)
(90,-20)
(90,10)
(80,20)
(60,30)

题目要从(0,0)开始,所以找到(0,0)之后再进行输出其之后的和之前的就行...凸包水
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const double pi = atan(1.0)*;
const double eps = 1e-;
struct Point
{
int x,y;
} p[N];
Point Stack[N];
int n;
int mult(Point a,Point b,Point c)
{
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
int dis(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int cmp(Point a,Point b)
{
if(mult(a,b,p[])>) return ;
if(mult(a,b,p[])==&&dis(b,p[])-dis(a,p[])>eps) return ;
return ;
}
int Graham()
{
int top = ;
sort(p+,p+n,cmp);
Stack[] = p[];
Stack[] = p[];
Stack[] = p[];
for(int i=; i<n; i++)
{
while(top>=&&mult(p[i],Stack[top],Stack[top-])>=) top--;
Stack[++top]=p[i];
}
return top;
}
int main()
{
n = ;
while(scanf("%d%d",&p[n].x,&p[n].y)!=EOF)
{
n++;
//if(n==10) break;
}
//for(int i=0;i<n;i++) printf("%d %d\n",p[i].x,p[i].y);
int k=;
for(int i=; i<n; i++)
{
if(p[i].y<p[k].y||((p[i].y==p[k].y)&&(p[i].x<p[k].x))) k = i;
}
swap(p[],p[k]);
double sum=;
int top = Graham();
int temp = ;
for(int i=;i<=top;i++){
if(Stack[i].x==&&Stack[i].y==) temp = i;
}
for(int i=temp;i<=top;i++) printf("(%d,%d)\n",Stack[i].x,Stack[i].y);
for(int i=;i<temp;i++) printf("(%d,%d)\n",Stack[i].x,Stack[i].y);
}

poj 2007(凸包)的更多相关文章

  1. poj 2007 凸包构造和极角排序输出(模板题)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10841   Accepted: 508 ...

  2. POJ 2007 Scrambled Polygon 极角序 水

    LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...

  3. poj 1873 凸包+枚举

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1 ...

  4. poj 1113 凸包周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33888   Accepted: 11544 Descriptio ...

  5. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

  6. POJ - 2007 极角排序(Java 实现)

    POJ 2007 将所有的点按逆时针输出 import java.io.*; import java.util.*; public class Main { static class Point im ...

  7. Scrambled Polygon - POJ 2007(求凸包)

    给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列. 分析:最简单的极坐标排序了..................... 代码如下: ----------------- ...

  8. POJ 2007 Scrambled Polygon 凸包

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7214   Accepted: 3445 ...

  9. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

随机推荐

  1. DPDK Qos之报文处理流水线

    原创翻译,转载请注明出处. 下面是一个支持Qos的复杂报文处理流水线的图: 流水线是通过DPDP可重用的软件库构建出来的.在流水线里实现QoS主要是如下模块:policer,dropper,shced ...

  2. StanFord 编程方法

    教程下载地址:http://www.yyets.com/resource/26208 定制工具下载地址:http://www.stanford.edu/class/cs106a/cgi-bin/cla ...

  3. javaScript的流程控制语句学习笔记

    JavaScript提供了5种流程控制语句,if条件判断语句,switch语句,for循环语句,while循环语句,do-while循环语句. 1.条件判读语句 对变量或表达式进行判定,并根据判定结果 ...

  4. Github & DMCA Takedown Policy

    Github & DMCA Takedown Policy Digital Millennium Copyright Act 数字千年版权法案 https://help.github.com/ ...

  5. 【bzoj3626】[LNOI2014]LCA 树链剖分+线段树

    题目描述 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先.有q次询问,每次询 ...

  6. [51nod1791] 合法括号子段 DP

    ---题面--- 题解: 首先我们需要发现一个性质,在括号序列不变的情况下,括号匹配是不会变的,因此不论子串怎么取,括号匹配的关系是不会变化的.这是一个很容易发现的性质,然而我太弱,没发现. 于是可以 ...

  7. 【模拟赛·polyline】

    Input file: polyline.in Output file: polyline.out Time limit: 1s Memory limit: 128M 有若⼲个类似于下⾯的函数: 定义 ...

  8. 【TMD模拟赛】上低音号 链表

    这道题一看有两个出发现点,一枚举点去找边界,想了一会就Pass了...,二是枚举相框,我们最起码枚举两个边界,然后发现平行边界更好处理,然而仍然只有30分,这个时候就来到了链表的神奇应用,我们枚举上界 ...

  9. MySQL使用笔记(四)数据的操作

    By francis_hao    Dec 14,2016 数据的操作包括插入数据记录.更新数据记录和删除数据记录. 插入数据记录 插入单条数据记录 field表示的字段名和value表示数据要一一对 ...

  10. [POJ2777] Count Color

    \[Count Color\] Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 50865 Accepted: 15346 Des ...