Technorati Tags: POJ,计算几何,凸包

初学计算几何,引入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 凸包的变形的更多相关文章

  1. poj 1696 Space Ant (极角排序)

    链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)

    Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...

  3. poj 1696:Space Ant(计算几何,凸包变种,极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2876   Accepted: 1839 Descrip ...

  4. 简单几何(凸包) POJ 1696 Space Ant

    题目传送门 题意:一个蚂蚁一直往左边走,问最多能走多少步,且输出路径 分析:就是凸包的变形题,凸包性质,所有点都能走.从左下角开始走,不停排序.有点纠结,自己的凸包不能AC.待理解透凸包再来写.. 好 ...

  5. POJ 1696 Space Ant 卷包裹法

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3316   Accepted: 2118 Descrip ...

  6. POJ 1696 Space Ant(极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2489   Accepted: 1567 Descrip ...

  7. poj 1696 Space Ant(模拟+叉积)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3840   Accepted: 2397 Descrip ...

  8. POJ 1696 Space Ant(点积的应用)

    Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...

  9. POJ 1696 Space Ant(凸包变形)

    Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scie ...

随机推荐

  1. 如何取Android设备日志

    安装Android SDK 运行 adb 命令 adb devices 查看链接的设备 adb logcat 日志相关

  2. Python 100道题深入理解

    # -*- coding: utf-8 -*-# 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?# 程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所 ...

  3. SQL ServerOVER 子句,over开窗函数,SQL SERVER 开窗函数

    https://technet.microsoft.com/zh-cn/library/ms189461(v=sql.105).aspx http://www.cnblogs.com/85538649 ...

  4. jquery选择器之属性选择器

    [attribute]   匹配指定属性名的所有元素 [attribute=value] 匹配给定的属性名是某个特定值的属性 [attribute!=value] 匹配给定的属性名不是某个特定值的属性 ...

  5. IntelliJ IDEA15导入jar包

    在IDEA中导入jar包和eclipse中是不一样的,那么现在我们就来看看在IDEA中如何导入jar包. 1.点击"File"-->"Project Structu ...

  6. c#上iOS apns p12文件制作记录 iOS推送证书制件

    前期一些准备工作可参考:http://jingyan.baidu.com/article/7082dc1c6bb86de40a89bd1a.html 1.在桌面上建一个"apns_p12&q ...

  7. Openstack Neutron L2 Population

    Why do we need it, whatever it is? VM unicast, multicast and broadcast traffic flow is detailed in m ...

  8. indexOf ie下的兼容问题

    今天突然发现ie下报错,不支持的属性,原来ie下不支持indexOf. 加入如下代码即可解决. if (!Array.prototype.indexOf){  Array.prototype.inde ...

  9. IOS开发中的几种设计模式介绍

    ios开发学习中,经常弄不清楚ios的开发模式,今天我们就来进行简单的总结和探讨~ (一)代理模式 应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现. 优势:解耦合 敏捷 ...

  10. MyEclipse中的重命名

    我们要重命名一个函数或变量时,如果手工改会很耗时而且可能会有些遗漏,造成编译错误.这个时候可以在变量或函数定义处,按下MyEclipse的Alter + SHIF + R 重命名,然后按下Enter键 ...