题意:平面上有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 【极角排序】的更多相关文章

  1. poj 1696 Space Ant 极角排序

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  2. POJ 1696 Space Ant 极角排序(叉积的应用)

    题目大意:给出n个点的编号和坐标,按逆时针方向连接着n个点,按连接的先后顺序输出每个点的编号. 题目思路:Cross(a,b)表示a,b的叉积,若小于0:a在b的逆时针方向,若大于0a在b的顺时针方向 ...

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

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

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

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

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

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

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

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

  7. POJ 1696 Space Ant 卷包裹法

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

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

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

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

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

随机推荐

  1. JavaScript获取浏览器高度和宽度值

    IE中:  document.body.clientWidth ==> *DY对象宽度 document.body.clientHeight ==> *DY对象高度 document.do ...

  2. Android优秀学习资料(高手博客

    任玉刚, 博客 : http://blog.csdn.net/singwhatiwanna, github : https://github.com/singwhatiwanna Trinea, 博客 ...

  3. 优化MySchool数据库(四)

    关于“无法附件数据库”过程的遇到的问题: 1.数据文件本身,具有访问权限的限制 ---- 选中 数据库文件所在的文件夹---->右键菜单(属性)----> 安全 --->User用户 ...

  4. 在eclipse中把之前的Tomcat 6删掉,不能再建

    在eclipse中把之前的Tomcat 6删掉,重新配置一个,不料没有下一步. 解决的方法了,如下: 1.退出 eclipse 2.到[工程目录下]/.metadata/.plugins/org.ec ...

  5. iOS 学习资源

    这份学习资料是为 iOS 初学者所准备的, 旨在帮助 iOS 初学者们快速找到适合自己的学习资料, 节省他们搜索资料的时间, 使他们更好的规划好自己的 iOS 学习路线, 更快的入门, 更准确的定位的 ...

  6. redis配置文件参数说明及命令操作

    redis下载地址:https://github.com/MSOpenTech/redis/releases. Redis 的配置文件位于 Redis 安装目录下,文件名为redis.windows. ...

  7. thinkphp 创建子应用

    1 根目录建立 文件名 a 2 a 下建立index.php define('APP_NAME', 'a');define('APP_PATH', './a');define('RUNTIME_PAT ...

  8. Eclipse中jsp、js文件编辑时,卡死现象解决汇总

    使用Eclipse编辑jsp.js文件时,经常出现卡死现象,在网上百度了N次,经过N次优化调整后,卡死现象逐步好转,具体那个方法起到作用,不太好讲.将所有用过的方法罗列如下: 1.取消验证 windo ...

  9. 快速提升word文档编写质量

    1.调整样式顺序

  10. 14、SEO工程师要阅读的书籍 - IT软件人员书籍系列文章

    SEO工程师是Web项目中比较重要的一个角色.他主要负责网站的针对搜索引擎的优化方案的编写和实施.因为现在网站数量庞大,在全世界的这么多网站当中,想要让用户访问你的网站,就需要一些技巧性的内容.很多用 ...