POJ 1696 - Space Ant 凸包的变形
初学计算几何,引入polygon后的第一个挑战——凸包
此题可用凸包算法做,只要把压入凸包的点从原集合中排除即可,最终形成图形为螺旋线。
关于凸包,具体可见凸包五法:http://blog.csdn.net/bone_ace/article/details/46239187
此处简述我O(nH)的Jarvis法(H: 凸包上点数)

过程较易于理解。
//POJ1696
//凸包变形
//AC 2016.10.13 #include "cstdio"
#include "cstdlib"
#include "iostream"
#include "cmath"
#define MAXN (55) struct point{
int num, x, y;
bool been;
point(){}
point(int X, int Y): x(X), y(Y), been(){}
void input(){
scanf("%d%d%d", &num, &x, &y);
been = ;
}
friend point operator >> (const point &p1, const point &p2){
return point(p2.x - p1.x, p2.y - p1.y);
}
friend int operator ^ (const point &p1, const point &p2){
return p1.x * p2.y - p1.y * p2.x;
}
}pt[MAXN]; void swap(point &p1, point &p2){
point p = p1;
p1 = p2;
p2 = p;
} int main(){
int m, n;
freopen("fin.c", "r", stdin);
scanf("%d", &m);
while(m--){
scanf("%d", &n);
for(int i = ; i < n; i++){
pt[i].input();
for (int j = i; j && (pt[j].y < pt[j - ].y); j--){
swap(pt[j - ], pt[j]);
}
}
printf("%d %d", n, pt[].num);
pt[].been = ;
int cur = ;
while (){
int tmp = ;
for (int i = ; i < n; i++)
if (!pt[i].been){
if (!tmp)
tmp = i;
else if (((pt[cur] >> pt[i]) ^ (pt[cur] >> pt[tmp])) >= )
tmp = i;
}
if (!tmp) break;
printf(" %d", pt[tmp].num);
pt[tmp].been = ;
cur = tmp;
}
puts("");
}
}
POJ 1696 - Space Ant 凸包的变形的更多相关文章
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...
- poj 1696:Space Ant(计算几何,凸包变种,极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2876 Accepted: 1839 Descrip ...
- 简单几何(凸包) POJ 1696 Space Ant
题目传送门 题意:一个蚂蚁一直往左边走,问最多能走多少步,且输出路径 分析:就是凸包的变形题,凸包性质,所有点都能走.从左下角开始走,不停排序.有点纠结,自己的凸包不能AC.待理解透凸包再来写.. 好 ...
- POJ 1696 Space Ant 卷包裹法
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3316 Accepted: 2118 Descrip ...
- POJ 1696 Space Ant(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2489 Accepted: 1567 Descrip ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
- POJ 1696 Space Ant(点积的应用)
Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...
- POJ 1696 Space Ant(凸包变形)
Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scie ...
随机推荐
- How do you build a database?
在reddit上看到的一篇讲解数据库实现的文章,非常有意思,在这里记录一下. 回答者technical_guy: Its a great question, and deserves a long a ...
- 【python】传入函数
def add(x, y, f): return f(x) + f(y) 当我们调用add(-5, 6, abs)时,参数x,y和f分别接收-5,6和abs,根据函数定义,我们可以推导计算过程为: x ...
- SpringMVC学习系列(6) 之 数据验证
在系列(4).(5)中我们展示了如何绑定数据,绑定完数据之后如何确保我们得到的数据的正确性?这就是我们本篇要说的内容 —> 数据验证. 这里我们采用Hibernate-validator来进行验 ...
- redis集群的一些笔记
当节点数量少于6个时候会提示如下信息,初始化一个集群的时候需要6个节点,为什么?? *** ERROR: Invalid configuration for cluster creation. *** ...
- innodb insert buffer 插入缓冲区的理解
今天在做一个大业务的数据删除时,看到下面的性能曲线图 在删除动作开始之后,insert buffer 大小增加到140.对于这些状态参数的说明 InnoDB Insert Buffer 插入缓冲,并不 ...
- edittext_解释
============ 2 android判断EditText输入的数字.中文还是字母方法 String txt = edInput.getText().toString(); Patter ...
- fgets读取文件时的注意事项
1 文本文件 a.txt 内容如下 2 c代码 FILE *fil; if (!(fil = fopen("/home/rudy/projects/paser/a.txt", &q ...
- haproxy+keepalived实现高可用负载均衡
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. HA ...
- [POJ 1988] Cube Stacking (带值的并查集)
题目链接:http://poj.org/problem?id=1988 题目大意:给你N个方块,编号从1到N,有两种操作,第一种是M(x,y),意思是将x所在的堆放到y所在的堆上面. 第二种是C(x) ...
- jquery 监听radio选中,取值
$(document).ready(function(){ $("input[name=discount]").each(function(){ $(this).click(fun ...