这题是明显的TU包变形。

使用卷包裹法可解,而且是必定可以经过所有点的。直观可知,当经过某点后,相当于把之前的点抹去,求剩下点的TU包,递归下去,也就能把点全部经过了。

于是,只需把经过的点标记一下就可以了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath> using namespace std;
const double inf=10000000;
const double eps=0.00000001;
struct point {
double x,y;
int num;
}p[60]; bool vis[60];
queue<int>que;
struct vect{
double x,y;
}; double dist(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double cross(point a,point b,point c,point d){
return (a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x);
} int n;
int main(){
int t;
scanf("%d",&t); double a,b;
while(t--){
scanf("%d",&n);
point start; start.x=inf; start.y=inf; int dep;
for(int i=0;i<n;i++){
scanf("%d%lf%lf",&p[i].num,&p[i].x,&p[i].y);
if(p[i].y<start.y){
start.x=p[i].x; start.y=p[i].y; start.num=p[i].num;
dep=i;
}
else if(p[i].y==start.y){
if(p[i].x<start.x){
start.x=p[i].x; start.num=p[i].num;
dep=i;
}
}
}
// cout<<start.x<<' '<<start.y<<endl;
point last; last.x=0; last.y=start.y;
que.push(start.num);
memset(vis,false,sizeof(vis));
vis[dep]=true; point tmp;
while(true){
bool flag=false;
for(int i=0;i<n;i++){
if(vis[i]==false){
if(cross(start,last,p[i],start)>=0){
tmp=p[i];
dep=i;
flag=true;
break;
}
}
}
// cout<<dep<<"YES"<<endl;
if(!flag) break;
for(int i=0;i<n;i++){
if(vis[i]==false){
if(cross(start,last,p[i],start)<0) continue;
double res=cross(tmp,start,p[i],start);
if(res<0){
tmp=p[i];
dep=i;
}
else if(res==0){
if(dist(p[i],start)+eps<dist(tmp,start)){
tmp=p[i];
dep=i;
}
}
}
}
que.push(tmp.num);
//cout<<dep<<endl;
vis[dep]=true;
last=start;
start=tmp;
}
printf("%d",n);
for(int i=0;i<n;i++){
printf(" %d",que.front());
que.pop();
}
printf("\n");
}
return 0;
}

  

POJ 1696的更多相关文章

  1. poj 1696 叉积理解

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

  2. poj 1696 (计算几何基础)

    poj 1696 Space Ant 链接:http://poj.org/problem?id=1696 题意:在坐标轴上,给定n个点的 id 以及点的坐标(xi, yi),让你以最底端点开始,从右依 ...

  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 凸包的变形

    Technorati Tags: POJ,计算几何,凸包 初学计算几何,引入polygon后的第一个挑战--凸包 此题可用凸包算法做,只要把压入凸包的点从原集合中排除即可,最终形成图形为螺旋线. 关于 ...

  5. POJ 1696 Space Ant --枚举,模拟,贪心,几何

    题意: 有很多点,从最右下角的点开始走起,初始方向水平向右,然后以后每步只能向左边走,问最多能走多少个点. 解法: 贪心的搞的话,肯定每次选左边的与它夹角最小的点,然后走过去. 然后就是相当于模拟地去 ...

  6. POJ 1696 Space Ant 【极角排序】

    题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...

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

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

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

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

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

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

  10. poj 1696 Space Ant 极角排序

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

随机推荐

  1. aspectC++常用命令

    常用命令:1.ag++ main.cc //在工程目录下产生编译后的exe2.ag++ main.cc --weave_only //产生.acc 纯c++文件3.ag++ main.cc --gen ...

  2. 部署webservice常见问题汇总

    问题一 转自http://blog.csdn.net/xingxing513234072/article/details/38615997 处理程序“WebServiceHandlerFactory- ...

  3. mybatis中if标签判断字符串相等问题

    mybatis 映射文件中,if标签判断字符串sfyx变量是否是字符串Y的时候,发现并不管用: <if test="sfyx=='Y' "> and 1=1 </ ...

  4. JPA实体关联关系,一对一以及转换器

    现有两张表 room (rid,name,address,floor) room_detail (rid,roomid,type) 需要创建房间实体,但是也要包含type属性 @Data //lamb ...

  5. pdf 转成 一张图片

    1.maven依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfb ...

  6. S - New Year Transportation

    Problem description New Year is coming in Line World! In this world, there are n cells numbered by i ...

  7. word文档去掉复制过来的背景颜色

    选择清除格式

  8. 6月10遇到的bug

    3.遇到的BUG        1.@Service(version = "1.0.0", interfaceClass = TransactionItemService.clas ...

  9. 理解list和vector的区别

    原文:http://genwoxuevc.blog.51cto.com/1852984/503337 vector和数组类似,它拥有一段连续的内存空间,并且起始地址不变,因此它能非常好的支持随机存取( ...

  10. 我和CSDN的那些事

    作者:朱金灿 来源:http://blog.csdn.net/clever101 前些日子收到这样一个邀请: CSDN的工作人员还来电给我确认是否能参加.开始我有点犹豫,毕竟是在工作日的晚上,毕竟离我 ...