POJ 1696 Space Ant 【极角排序】
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点。
思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序。(n个点必定能走完,这是凸包的性质决定的)
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
const double eps=1e-;
int sgn(double x){
if(fabs(x)<eps) return ;
if(x>) return ;
return -;
}
struct point{
double x,y,id;
point(){}
point(double x_,double y_){
x=x_,y=y_;
}
point operator -(const point &b)const{
return point(x-b.x,y-b.y);
}
double operator *(const point &b)const{
return x*b.x+y*b.y;
}
double operator ^(const point &b)const{
return x*b.y-y*b.x;
}
}po[N];
double dis(point a,point b){
return sqrt((b-a)*(b-a));
}
int tmp;
int cmp(point a,point b){
int t=sgn((a-po[tmp])^(b-po[tmp]));
if(!t) return dis(po[tmp],a)<dis(po[tmp],b);
return t>;
}
int main(){
int t,n,i;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d%lf%lf",&po[i].id,&po[i].x,&po[i].y);
if(po[i].y<po[].y||po[i].y==po[].y&&po[i].x<po[].x)
swap(po[i],po[]);
}
tmp=;
for(i=;i<=n;i++){
sort(po+i,po+n+,cmp);
tmp=i;
}
printf("%d",n);
for(i=;i<=n;i++)
printf(" %d",po[i].id);
puts("");
}
return ;
}
POJ 1696 Space Ant 【极角排序】的更多相关文章
- poj 1696 Space Ant 极角排序
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...
- POJ 1696 Space Ant 极角排序(叉积的应用)
题目大意:给出n个点的编号和坐标,按逆时针方向连接着n个点,按连接的先后顺序输出每个点的编号. 题目思路:Cross(a,b)表示a,b的叉积,若小于0:a在b的逆时针方向,若大于0a在b的顺时针方向 ...
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- 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: 2876 Accepted: 1839 Descrip ...
- 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: 3316 Accepted: 2118 Descrip ...
- POJ 1696 Space Ant(点积的应用)
Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
随机推荐
- JavaScript学习笔记-用于模式匹配的String方法
用于模式匹配的String方法: String支持4种使用正则表达式的方法: seach()用于检索,参数是一个正则表达式,返回第一个与之匹配的子串的位置,找不到则返回-1,如 ...
- Mac下的Parallel Windows忘记密码怎么办?
Mac机上安装了Parallel Windows,日久年深不登录结果忘记了登录密码,百爪挠心,想破脑壳试了n个密码都不行,放了一个多月也没想起来. 今天没事网上溜溜,肯定也有和我同病相怜的弟兄,果然, ...
- javascript中,如何判断input中输入的为纯数字
用正则表达式判断.如果纯数字是指整数的话(不包含小数点),可以这样: function check(){ var value = document.getElementById("input ...
- 谈谈vertical-align的text-bottom和text-top - 韦奕
学习资料 : http://www.tuicool.com/articles/uuYvMv 友情链接 行高 替换元素,非替换元素,内联元素,块元素
- jar 命令 打包装class文件的文件夹
由于将spring源代码导入到eclipse后,缺少jar包, 所以从maven仓库中下载spring发布的spring-core jar包. 为了方便理解目录结构,使用tree命令: tr ...
- Windows Phone 8.0 SDK Update(10322) Released
昨天微软低调发布了WP 8 SDK的更新,甚至在Windows Phone Developer Blog上都没有提及. 从开发者的角度来看,此次更新的确没有太多需要关注的地方,因为没有添加新的API和 ...
- java开发中的23中设计模式详解--大话设计模式
设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- hadoop2.2.0伪分布式搭建1--准备Linux环境
1.0修改网关 点击VMware快捷方式,右键打开文件所在位置 -> 双击vmnetcfg.exe -> VMnet1 host-only ->修改subnet ip 设置网段:19 ...
- W3School-CSS测验
The only way to survive was to enjoy the good moments and not dwell too much on the bad. 生活,就应该享受美好的 ...
- Linux下使用NDK编译FFMPEG(libstagefright)
这个月要负责一个项目,使用FFMPEG渲染视频,主要是Android端的,由于性能要求,要使用硬解码,但网上大多数教程都是没有libstagefright的,所以个人觉得,生成的so库文件也是没有开启 ...