• 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;
    }
  • 相关阅读:
    bzoj1854 [Scoi2010]游戏
    bzoj2456 mode
    bzoj4810 [Ynoi2017]由乃的玉米田
    bzoj1076 [SCOI2008]奖励关
    bzoj3064 Tyvj 1518 CPU监控
    bzoj1798 [Ahoi2009]维护序列
    bzoj3575 [Hnoi2014]道路堵塞
    bzoj3992 [SDOI2015]序列统计
    uoj#34. 多项式乘法
    高等代数典型问题集
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4905457.html
Copyright © 2020-2023  润新知