zoukankan      html  css  js  c++  java
  • poj2007极角排序

    裸的极角排序,但是要把0,0放在第一个(话说这题题目真是巨长,废话也多。。。)

    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cassert>
    #include<iomanip>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define pi acos(-1.0)
    #define ll long long
    #define mod 1000000007
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    
    const double g=10.0,eps=1e-9;
    const int N=100+10,maxn=500+100,inf=0x3f3f3f;
    
    struct point{
        double x,y;
    }p[N];
    double dis(point p1,point p2)
    {
        return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    }
    double dir(point p1,point p2,point p3)
    {
        return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
    }
    bool comp(point p1,point p2)
    {
        double te=dir(p[0],p1,p2);
        if(te<0)return 1;
        if(te==0&&dis(p[0],p1)<dis(p[0],p2))return 1;
        return 0;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int cnt=0;
        while(cin>>p[cnt].x>>p[cnt].y){
            //if(p[cnt].x==-1&&p[cnt].y==-1)break;
            cnt++;
        }
        int pos;
        for(int i=0;i<cnt;i++)
            if(p[i].x==0&&p[i].y==0)
                pos=i;
        swap(p[0],p[pos]);
        sort(p+1,p+cnt,comp);
        for(int i=0;i<cnt;i++)
            cout<<"("<<p[i].x<<","<<p[i].y<<")"<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    Node.js NPM 包(Package)
    Node.js NPM 作用
    Node.js NPM 介绍
    Node.js NPM 教程
    Node.js NPM 教程
    Node.js 发送Email
    Node.js 上传文件
    Node.js 事件
    Node.js NPM
    Node.js 文件系统模块
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/7191653.html
Copyright © 2011-2022 走看看