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:

It can not turn right due to its special body structure.

It leaves a red path while walking.

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

凸包,从第一个开始不停的进行排序就好了;

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
const int INF=0xfffffff;
struct Point{
int x,y,temp,num;
}p[50005],s[50005];
int top;
int direction(Point p1,Point p2,Point p3) { return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y); }//点2和3,按哪个和点一的角度更小排,相同的话按哪个更近排
double dis(Point p1,Point p2) { return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); }
bool cmp(Point p1,Point p2)//极角排序
{
int temp=direction(p[top],p1,p2);
if(temp<0)return true ;
if(temp==0&&dis(p[top],p1)<dis(p[top],p2))return true;
return false;
}
/*vector<int>v;
void Graham(int n)
{
int pos,minx,miny;
minx=miny=INF;
for(int i=0;i<n;i++)//找最下面的基点
if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
swap(p[0],p[pos]);
sort(p+1,p+n,cmp);
p[n]=p[0];
s[0]=p[0];s[1]=p[1];s[2]=p[2];
p[0].temp=1;p[1].temp=1;p[2].temp=1;
top=2;int i=3;
while(top<n)
{
while(p[i].temp)
{
i++;
if(i==n) i=0;
} while(direction(s[top-1],s[top],p[i])>=0&&top>=2)
{
p[s[top].num].temp=0;
top--;
}
s[++top]=p[i];
p[i].temp=1;
}
}*/
int main()
{
int re;
sf("%d",&re);
while(re--)
{
top=0;
int n;
cin>>n;
rep(i,0,n)
{
p[i].temp=0;sf("%d%d%d",&p[i].num,&p[i].x,&p[i].y);
}
int pos,minx,miny;
minx=miny=INF;
for(int i=0;i<n;i++)//找最下面的基点
if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
swap(p[0],p[pos]);
pf("%d",n);
rep(i,1,n)
{
sort(p+i,p+n,cmp);top++;
}
rep(i,0,n)
pf(" %d",p[i].num);
pf("\n");
}
return 0;
}

B - 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. Space Ant

    Space Ant The most exciting space discovery occurred at the end of the 20th century. In 1999, scient ...

  7. poj1696 Space Ant【计算几何】

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

  8. Space Ant(极角排序)

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

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

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

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

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

随机推荐

  1. C# SpinLock实现

    关于SpinLock自旋锁网上已经有很多说明,这里也copy了一部分,我这里主要关注微软的实现,学习人家的实现方式. 如果由于垃圾回收,基于对象的锁对象开销太高,可以使用SpinLock结构..NET ...

  2. crucible 的 破解

    crucible这个东西用了很久,但是从来都没有想过去破解它,毕竟在公司是不能使用破解 软件的.于是再家里面玩一下而已.下载地址 运行crucible_keygen 如图: 点击 patch 将选择安 ...

  3. springMVC返回json数据时date类型数据被转成long类型

    在项目的过程中肯定会遇到ajax请求,但是再用的过程中会发现,在数据库中好好的时间类型数据:2017-05-04 17:52:24 在转json的时候,得到的就不是时间格式了 而是145245121这 ...

  4. M1 卡技术规范

    射频卡简单来讲就是卡的一种工作方式,通过感应的方式来工作,也能够把全部的感应卡都统称为射频卡. IC卡的范围比較广.芯片外露的接触式IC卡.芯片内置的感应式IC卡和双界面IC卡都可统称为IC卡.IC卡 ...

  5. N1, T1刷机记录

    硬件配置 N1和T1使用的是晶晨Amlogic方案的芯片, 配置明细分别如下, 都是现在盒子的主流配置 N1CPU: Amlogic S905, ARM Cortex-A53 四核 up to 2.0 ...

  6. 利用 Express 托管静态文件

    通过 Express 内置的 express.static 可以方便地托管静态文件,例如图片.CSS.JavaScript 文件等. 将静态资源文件所在的目录作为参数传递给 express.stati ...

  7. 物联网架构成长之路(13)-SpringBoot入门

    1. 前言 下载最新版的JavaEE eclipse-jee-oxygen-2-win32-x86_64.zip 安装STS插件 Window->Eclipse Marketplace -> ...

  8. Cublas矩阵加速运算

    前言 编写 CUDA 程序真心不是个简单的事儿,调试也不方便,很费时.那么有没有一些现成的 CUDA 库来调用呢? 答案是有的,如 CUBLAS 就是 CUDA 专门用来解决线性代数运算的库. 本文将 ...

  9. linux命令(53):useradd,区别于adduser

    adduser和useradd的区别: useradd是一个linux命令,但是它提供了很多参数在用户使用的时候根据自己的需要进行设置: 而adduser是一个perl 脚本,在使用的时候会 出现类似 ...

  10. MXNET:深度学习计算-GPU

    mxnet的设备管理 MXNet 使用 context 来指定用来存储和计算的设备,例如可以是 CPU 或者 GPU.默认情况下,MXNet 会将数据创建在主内存,然后利用 CPU 来计算.在 MXN ...