zoukankan      html  css  js  c++  java
  • Scrambled Polygon

    给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列。

    分析:最简单的极坐标排序了.....................

    代码如下:

    --------------------------------------------------------------------------------------------------------------------------

    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<string.h>
    #include<queue>
    #include<string>
    #include<vector>
    #include<math.h>
    using namespace std;
    
    const double EPS = 1e-10;
    const double PI = acos(-1);
    const int MAXN = 1e3+7;
    int sta[MAXN], top;
    int Sign(double t)
    {
        if(t > EPS)return 1;
        if(fabs(t) < EPS)return 0;
        return -1;
    }
    struct point
    {
        double x, y;
        point(double x=0, double y=0):x(x), y(y){}
        point operator - (const point &t)const{
            return point(x-t.x, y-t.y);
        }
        double operator ^(const point &t)const{
            return x*t.y - y*t.x;
        }
        double operator *(const point &t)const{
            return x*t.x + y*t.y;
        }
    }p[MAXN];
    double Dist(point a, point b)
    {
        return sqrt((a-b)*(a-b));
    }
    bool cmp(point a, point b)
    {
        int t = Sign((a-p[0])^(b-p[0]));
    
        if(t == 0)
            return Dist(a, p[0]) < Dist(b, p[0]);
        return t > 0;
    }
    
    int main()
    {
        int i=0, N;
    
        while(scanf("%lf%lf", &p[i].x, &p[i].y) != EOF)
            i++;
        
        N = i;
        sort(p+1, p+N, cmp);
    
        for(i=0; i<N; i++)
            printf("(%.0f,%.0f)
    ", p[i].x, p[i].y);
    
        return 0;
    }
  • 相关阅读:
    VS2010 添加项目依赖
    人工鱼群算法 AFSA
    粒子群算法 PSO
    CUDA速度测试
    AGSO 萤火虫算法
    用于WTL工具栏的辅助类CToolBarHelper
    关于结构体内存对齐
    遗传算法 GA
    A*算法
    人工蜂群算法 ABC
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4905457.html
Copyright © 2011-2022 走看看