Space Ant

The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y1999 and called it M11. It has only one eye on the left side of its head and just three feet all on the right side of its body and suffers from three walking limitations: 
  1. It can not turn right due to its special body structure.
  2. It leaves a red path while walking.
  3. It hates to pass over a previously red colored path, and never does that.

The pictures transmitted by the Discovery space ship depicts that plants in the Y1999 grow in special points on the planet. Analysis of several thousands of the pictures have resulted in discovering a magic coordinate system governing the grow points of the plants. In this coordinate system with x and y axes, no two plants share the same x or y
An M11 needs to eat exactly one plant in each day to stay alive. When it eats one plant, it remains there for the rest of the day with no move. Next day, it looks for another plant to go there and eat it. If it can not reach any other plant it dies by the end of the day. Notice that it can reach a plant in any distance. 
The problem is to find a path for an M11 to let it live longest. 
Input is a set of (x, y) coordinates of plants. Suppose A with the coordinates (xA, yA) is the plant with the least y-coordinate. M11 starts from point (0,yA) heading towards plant A. Notice that the solution path should not cross itself and all of the turns should be counter-clockwise. Also note that the solution may visit more than two plants located on a same straight line. 

Input

The first line of the input is M, the number of test cases to be solved (1 <= M <= 10). For each test case, the first line is N, the number of plants in that test case (1 <= N <= 50), followed by N lines for each plant data. Each plant data consists of three integers: the first number is the unique plant index (1..N), followed by two positive integers x and y representing the coordinates of the plant. Plants are sorted by the increasing order on their indices in the input file. Suppose that the values of coordinates are at most 100.

Output

Output should have one separate line for the solution of each test case. A solution is the number of plants on the solution path, followed by the indices of visiting plants in the path in the order of their visits.

Sample Input

2
10
1 4 5
2 9 8
3 5 9
4 1 7
5 3 2
6 6 3
7 10 10
8 8 1
9 2 4
10 7 6
14
1 6 11
2 11 9
3 8 7
4 12 8
5 9 20
6 3 2
7 1 6
8 2 13
9 15 1
10 14 17
11 13 19
12 5 18
13 7 3
14 10 16

Sample Output

10 8 7 3 4 9 5 6 2 1 10
14 9 10 11 5 12 8 7 6 13 4 14 1 3 2

题目大意就是,在二维平面是找出一条路径,满足:

1.只能向左弯折;

2.弯折的地方只能是给定的点集中的点;

3.路径不能与之前的有相交;

4.要求经过给定的点越多越好.

这一题用到的是凸包的思想,却不是凸包.先说结论:我们每次以前一次到达的点为最下方的点(同时为基准点),旋转这个图,下一个到达的点就是新图中最最右边,且距离x轴最近的点(先满足前一个要求).

那么这个其实就是运用到凸包的排序思想,对于上述的条件,其实只需要运用叉积做cmp来排序就好啦.由于n很小,所以这题就能稳稳地过了.

 #include<cstdio>
 #include<cstring>
 #include<cmath>
 #include<algorithm>
 #include<iostream>
 #include<stack>
 using namespace std;
 int n,nowpos;
 ];
 point operator - (point u,point v){point ret; ret.x=u.x-v.x,ret.y=u.y-v.y; return ret;}
 int dis(point u,point v){return (u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y);}
 int cross(point u,point v){return u.x*v.y-v.x*u.y;}
 inline int read(){
     ,f=; char ch=getchar();
     '){if (ch=='-') f=-f; ch=getchar();}
     +ch-',ch=getchar();
     return x*f;
 }
 bool cmp(const point &P,const point &Q){
     ||cross(P-a[nowpos],Q-a[nowpos])==&&dis(a[nowpos],P)<dis(a[nowpos],Q);
 }
 int main(){
     for (int T=read(); T; T--){
         n=read(),memset(a,,sizeof a);
         ; i<=n; i++) a[i].index=read(),a[i].x=read(),a[i].y=read();
         ; i<=n; i++) ].y||a[i].y==a[].y&&a[i].x<a[].x) swap(a[],a[i]);
         nowpos=;
         ; i<=n; i++){
             sort(a+i,a+n+,cmp); nowpos++;
         }
         printf("%d",n);
         ; i<=n; i++) printf(" %d",a[i].index);
         puts("");
     }
     ;
 }

Space Ant的更多相关文章

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

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

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

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

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

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

  4. POJ 1696 Space Ant 卷包裹法

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

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

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

  6. poj1696 Space Ant【计算几何】

    含极角序排序模板.   Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5334   Accepted:  ...

  7. Space Ant(极角排序)

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

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

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

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

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

随机推荐

  1. FI CO 常用表

    FI CO 常用表     最近写FICO的报表写得有点多,许多Table记不住,用F1查找又有点费事,不如把表单写下来,以后用到,直接在这上面找得了. 1,账目表主数据  SKA1  SKB1  S ...

  2. 聚类算法——KMEANS算法

    聚类概念 无监督问题:我们手里没有标签 聚类:相似的东西分到一组 难点:如何评估,如何调参 基本概念 要得到簇的个数,需要指定K值 质心:均值,即向量各维取平均即可 距离的度量:常用欧几里得距离和余弦 ...

  3. axios的学习与使用

    最近的项目都是使用的vue框架,所以请求都使用了vue官方推荐的axios. 官方中文介绍 此处记录一下常用的写法 执行 GET 请求 // 为给定 ID 的 user 创建请求 axios.get( ...

  4. 【UOJ#196】【BZOJ4574】[Zjoi2016]线段树

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4574 http://uoj.ac/problem/196 考虑数字随机并且值域够大,我们 ...

  5. eureka 和zookeeper 区别 优势【转】

    作为服务注册中心,Eureka比Zookeeper好在哪里 著名的CAP理论指出,一个分布式系统不可能同时满足C(一致性).A(可用性)和P(分区容错性).由于分区容错性在是分布式系统中必须要保证的, ...

  6. curl: (6) Could not resolve host: www.baidu.com;

    今天,在执行curl时,突然发现这个报错,问题是之前完全没有出现过这样的情况. [root@localhost ~]# curl www.baidu.comcurl: (6) Could not re ...

  7. Mysql 强行Kill 连接

    BEGIN ; ; ; DO KILL @Temp; ; END WHILE ; END

  8. Linux-Ubuntu16.0.4相关命令

    1.更新软件源 sudo apt-get update 2.shell命令 基本格式:命令  [-选项] [-命令参数] ls #查看当前文件夹下的文件 ls -l XXXX #查看XXXX文件夹下的 ...

  9. webService上传图片

    webService /// <summary> /// 上传图片webServer 的摘要说明 /// </summary> [WebService(Namespace = ...

  10. mongodb shell和Node.js driver使用基础

    开始: Mongo Shell 安装后,输入mongo进入控制台: //所有帮助 > help //数据库的方法 > db.help() > db.stats() //当前数据库的状 ...