poj 1696 Space Ant 极角排序

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

const double eps = 1e-8;
const double PI = acos(-1.0);
const double INF = 100000000.000000;

struct Point{
    int index;
    double x,y;
    Point(double x=0, double y=0) : x(x),y(y){ }    //构造函数
};
typedef Point Vector;

Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A , double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);}

bool operator < (const Point& a,const Point& b){
    return a.y < b.y ||( a.y == b.y && a.x < b.x);
}

int dcmp(double x){
    if(fabs(x) < eps) return 0;
    else              return x < 0 ? -1 : 1;
}
bool operator == (const Point& a, const Point& b){
    return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}

///向量(x,y)的极角用atan2(y,x);
double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
double Length(Vector A)    { return sqrt(Dot(A,A)); }
double Angle(Vector A, Vector B)  { return acos(Dot(A,B) / Length(A) / Length(B)); }

double Cross(Vector A, Vector B)  { return A.x*B.y - A.y * B.x; }

Vector Rotate(Vector A, double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); }

double Area(Point A,Point B,Point C) { return Cross(B-A,C-A); }


Point read_point(){
    Point A;
    scanf("%d %lf %lf",&A.index,&A.x,&A.y);
    return A;
}

/*************************************分 割 线*****************************************/

Point P[105];
int pos;
bool cmp(Point A,Point B){ 
    double num = Cross(A-P[pos],B-P[pos]);
    if(dcmp(num) == 0){
        return Length(A-P[pos]) < Length(B-P[pos]);
    }
    else if(dcmp(num) < 0)  return false;
    else                    return true;
}
int main()
{
    //freopen("E:\\acm\\input.txt","r",stdin);
    int T;
    cin>>T;
    int N;
    while(T--){
        cin>>N;
        for(int i=1;i<=N;i++){
            P[i] = read_point();
            if(P[i] < P[1]){
                swap(P[i],P[1]);
            }
        }
        pos = 1;
        for(int i=1;i<=N;i++){
            sort(P+i,P+N+1,cmp);
            pos++;
        }
        printf("%d",N);
        for(int i=1;i<=N;i++)
            printf(" %d",P[i].index);
        printf("\n");
    }
}
View Code

 

转载于:https://www.cnblogs.com/acmdeweilai/p/3314039.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值