poj1696 Space Ant

题目链接:http://poj.org/problem?id=1696
题意:给你n个点的坐标,并给出每个点的序号,让你找一条,不向右拐的最长的路径
解析:每次都找到一个基准点做极角排序,下一次则选则相对于之前那一个点最小极角的点,再接着进行极角排序,这样生成的路径就是所求的

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
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 xreturn yint 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)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;iscanf("%d %lf %lf",&a[i].id,&a[i].x,&a[i].y);
        sort(a,a+n);
        cnt = 0;
        for(int i=1;iprintf("%d",n);
        for(int i=0;iprintf(" %d",a[i].id);
        puts("");
    }
    return 0;
}

你可能感兴趣的:(ACM,Onlineudge,poj,ACM,几何)