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 ...
随机推荐
- [原创]cocos2d-x研习录-第二阶 概念类之场景类(CCScene)
场景类CCScene是Cocos2D-x在屏幕显示的内容,相当于游戏关卡或界面.CCDirector任何时候只能显示一个场景CCScene,游戏中可能存在若干场景,CCDirector通过场景切换达到 ...
- UIButton的使用
使用UIButton时需要注意的是: 1.UIButton的创建有专门的类方法(buttonWithType:,UILabel没有): 2.UIButton常用的属性包括:frame.titile.t ...
- LeetCode Potential Thought Pitfalls
Problem Reason Reference Moving ZeroesSort Colors Corner cases Shortest Word Distance Thought: 2 p ...
- git 新建分支/切换分支/合并分支 使用方法
我的源码在 阿里云的git上存储着呢 1. 在 code.aliyun.com 上 新建分支 fixbug 2. 通过在 phpstorm中 右键项目>>VSC>>Git&g ...
- 【Oozie】安装配置Oozie
安装和配置Oozie Oozie用于Hadoop的工作流配置: 参考链接: <Install and Configure Apache Oozie Workflow Scheduler for ...
- python学习-day18、文件处理、
4.文件操作 武sir:http://www.cnblogs.com/wupeiqi/articles/4943406.html 林海峰:http://www.cnblogs.com/linhaife ...
- [HTML5]原生事件绑定和jquery动态事件绑定的区别
原生事件绑定: <!-- 标签上绑定的事件是由window对象帮助调用,因此方法内的this其实是window对象 --> <label><input type=&quo ...
- Linux 服务器的网络配置 - 2. 查看 Linux 服务器的进程
2. 查看 Linux 服务器的进程 1)ps [主要选项] -a 显示系统中所有进程的信息 -e 显示所有进程的信息 -f 显示进行的所有信息 -l 以长格式显示进程信息 -r 只显示正 ...
- [IIS]在CMD中IIS的使用
一.打开IIS管理器1,win+r,打开"运行" 2,输入 InetMgr,就打开了IIS管理器 二.IIS其他相关命令iisreset /RESTART 停止后启动 iisres ...
- 九、DAG hierarchy
DAG 节点有两种,Transformation/shape. shape节点是transformation的子节点. transformation节点包括position, rotation, sc ...