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. java中使用POI+excel 实现数据的批量导入和导出

    java web中使用POI实现excel文件的导入和导出 文件导出 //导入excle表 public String exportXls() throws IOException{ //1.查询所有 ...

  2. lintcode-63-搜索旋转排序数组 II

    63-搜索旋转排序数组 II 跟进"搜索旋转排序数组",假如有重复元素又将如何? 是否会影响运行时间复杂度? 如何影响? 为何会影响? 写出一个函数判断给定的目标值是否出现在数组中 ...

  3. Linux挂载Win共享文件夹 一

    1, Win下选中文件夹,属性设置为共享,红圈中的为共享路径,挂载时//ip/共享路径 2, 3,Linux需要安装这两个软件 rpm -qa | grep samba-client rpm -qa ...

  4. (转)Loadrunner监控Linux的17个指标

    1.Average load:Average number of processes simultaneously in Ready state during the last minute.   上 ...

  5. jquery/js iframe 元素操作

    1.判断id/ class 是否存在? <script> $(function(){ if(("#id_name").length()>0){ //如果id 存在 ...

  6. null?对象?异常?到底应该如何返回错误信息

    这篇文章记录我的一些思考.在工作了一段时间之后. 问题的核心很简单:到底如何返回错误信息. 学生时代,见到过当时的老师的代码: if (foo() == null) { } 当然,这位老师是一位比较擅 ...

  7. YUI Compressor是如何压缩JS代码的?

    YUI Compressor 压缩 JavaScript 的内容包括: 移除注释 移除额外的空格 细微优化 标识符替换(Identifier Replacement) YUI Compressor 包 ...

  8. 整理一些JavaScript时间处理扩展函数

    在JavaScript中,时间处理是经常需要用到的.最近想要慢慢建立自己的代码库,整理了几个之前用到的js处理时间的函数,发出来跟大家分享一下,以后的使用中会不断增加和修改代码库. 把字符串转换为日期 ...

  9. share-Nothing原理

    Share nothing理论在数据库设计和优化中的实践应用 首先介绍share nothing概念.最早接触它是在 DataBaseManagentSystem一书的并行数据库章节中. 并行数据库要 ...

  10. POJ3189:Steady Cow Assignment(二分+二分图多重匹配)

    Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7482   Accepted: ...