• 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("
    ");
        }
    }
    View Code
  • 相关阅读:
    类加载器ClassLoader
    JAVA分别获取日期中的年、月、日
    sql 安全问题
    马尔科夫链
    触发器、锁、事务和事务控制
    索引、视图、存储过程、函数、游标
    字符集
    数据类型选择
    存储引擎
    错误:too many indices for array
  • 原文地址:https://www.cnblogs.com/acmdeweilai/p/3314039.html
Copyright © 2020-2023  润新知