题目链接:http://poj.org/problem?id=1696
题意:给你n个点的坐标,并给出每个点的序号,让你找一条,不向右拐的最长的路径
解析:每次都找到一个基准点做极角排序,下一次则选则相对于之前那一个点最小极角的点,再接着进行极角排序,这样生成的路径就是所求的
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;
const int maxn = 1000+100;
struct point
{
int id;
double x,y;
point() {}
point(double _x,double _y)
{
x = _x;
y = _y;
}
bool operator < (const point &b)const
{
if(y==b.y)
return x<b.x;
return y<b.y;
}
}a[maxn];
int cnt = 0;
double x_mul(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cmp(point p1,point p2)
{
if(x_mul(a[cnt],p1,p2)==0)
return dis(a[cnt],p1)<dis(a[cnt],p2);
return x_mul(a[cnt],p1,p2)>0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d %lf %lf",&a[i].id,&a[i].x,&a[i].y);
sort(a,a+n);
cnt = 0;
for(int i=1;i<n;i++)
{
sort(a+i,a+n,cmp);
cnt++;
}
printf("%d",n);
for(int i=0;i<n;i++)
printf(" %d",a[i].id);
puts("");
}
return 0;
}