poj1696 Space Ant

74 篇文章 0 订阅
33 篇文章 0 订阅

题目链接: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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值