poj 2007(凸包)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 8005 | Accepted: 3798 |
Description
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
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
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(凸包)的更多相关文章
- poj 2007 凸包构造和极角排序输出(模板题)
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10841 Accepted: 508 ...
- POJ 2007 Scrambled Polygon 极角序 水
LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...
- poj 1873 凸包+枚举
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6198 Accepted: 1 ...
- poj 1113 凸包周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33888 Accepted: 11544 Descriptio ...
- Poj 2187 凸包模板求解
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...
- POJ - 2007 极角排序(Java 实现)
POJ 2007 将所有的点按逆时针输出 import java.io.*; import java.util.*; public class Main { static class Point im ...
- Scrambled Polygon - POJ 2007(求凸包)
给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列. 分析:最简单的极坐标排序了..................... 代码如下: ----------------- ...
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
随机推荐
- hadoop节点之间通信问题
前天遇到一个hadoop问题,由于之前都是伪分布的情况,没有真正的涉及到集群的环境,最近按照一些资料自己搭建了一个集群环境,三台虚拟机,一个master,两个slave,利用jps查看节点信息,启动了 ...
- java线程(3)——详解Callable、Future和FutureTask
回顾: 接上篇博客 java线程--三种创建线程的方式,这篇博客主要介绍第三种方式Callable和Future.比较继承Thread类和实现Runnable接口,接口更加灵活,使用更广泛.但这两种方 ...
- RxJS & Angular
RxJS & Angular https://www.learnrxjs.io/ https://rxjs-cn.github.io/learn-rxjs-operators/ https:/ ...
- JVM内存区域配置
堆内存:新域+旧域 设置堆内存初始化大小 java -Xms128m 设置堆内存初始化大小128MB 设置堆内存最大大小 java -Xmx256m 设置堆内存最大256MB 通常将堆内存的初始化大小 ...
- 安装和配置hadoop集群步骤
hadoop集群的安装步骤和配置 hadoop是由java语言编写的,首先我们肯定要在电脑中安装jdk,配置好jdk的环境,接下来就是安装hadoop集群的步骤了,在安装之前需要创建hadoop用户组 ...
- 【题解】SHOI2001化工厂装箱员
————传送:洛谷P2530 这道题目还是挺简单的,状态也容易想到. 数据范围非常的小,所以即便是很多维度,复杂度也完全可以接受.定义状态:dp[i][a][b][c]为手上的货物拿到第i个时三种物品 ...
- [洛谷P3521][POI2011]ROT-Tree Rotations
题目大意:给一棵$n(n\leqslant2\times10^5)$个叶子的二叉树,可以交换每个点的左右子树,要求前序遍历叶子的逆序对最少.输出最少的逆序对个数 题解:线段树合并,对于每个节点求出交换 ...
- clique 解题报告
clique 题目描述 数轴上有 \(n\) 个点,第 \(i\) 个点的坐标为 \(x_i\),权值为 \(w_i\).两个点 \(i\),\(j\) 之间存在一条边当且仅当 \(abs(x_i-x ...
- 洛谷 P3203 [HNOI2010]弹飞绵羊 解题报告
P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...
- 工具——SVN常用命令
SVN一般都是团队合作做一个项目所需用到的,为了是版本的统一 ;1. Check out——从服务器端取得代码 把服务器资料库里存放的某个项目代码取出来,放到本地主机中,这个动作叫做“check ...