zoukankan      html  css  js  c++  java
  • POJ 2007 Scrambled Polygon (极角排序)

    题目:传送门

    题意:输入一个凸包的所有顶点,逆时针输出凸包的顶点

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <vector>
    #include <set>
    #include <string>
    #include <math.h>
    #define LL long long
    #define mem(i, j) memset(i, j, sizeof(i))
    #define rep(i, j, k) for(int i = j; i <= k; i++)
    #define dep(i, j, k) for(int i = k; i >= j; i--)
    #define pb push_back
    #define make make_pair
    #define INF INT_MAX
    #define inf LLONG_MAX
    #define PI acos(-1)
    using namespace std;
    
    const int N = 5e4 + 5;
    
    struct Point {
        int x, y;
        Point(int x = 0, int 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 - (Point A, Point B) { return Vector(A.x - B.x, A.y - B.y); }
    ///向量*数=向量
    Vector operator * (Vector A, int p) { return Vector(A.x * p, A.y * p); }
    ///向量/数=向量
    Vector operator / (Vector A, int p) { return Vector(A.x / p, A.y / p); }
    
    const int eps = 1e-10;
    int dcmp(int x) {
        if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
    }
    
    bool operator < (const Point& a, const Point& b) {
        return a.x == b.x ? a.y < b.y : a.x < b.x;
    }
    
    bool operator == (const Point& a, const Point &b) {
        return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
    }
    
    int Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; } /// 点积
    int Length(Vector A) { return sqrt(Dot(A, A)); } /// 计算向量长度
    int Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } /// 向量A、B夹角
    int Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; } /// 叉积
    
    
    Point P[N], Q[N];
    
    bool cmp(Point A, Point B) {
        int tmp = Cross(A - P[0], B - P[0]);
        if(dcmp(tmp) == 0) return Length(A - P[0]) < Length(B - P[0]);
        return dcmp(tmp) >= 0;
    }
    
    int main() {
    
        int n = 0;
    
        while(scanf("%d %d", &P[n].x, &P[n].y) == 2) n++;
    
        sort(P + 1, P + n, cmp);
    
        rep(i, 0, n - 1) printf("(%d,%d)
    ", P[i].x, P[i].y);
    
        return 0;
    }
    一步一步,永不停息
  • 相关阅读:
    [ios] 分辨率
    [bat] 图片裁剪工具ImageMagick
    [ASP.NET] 调用32位ORACLE错误
    [Linux] 开启ESX的SSH
    [Linux] 关机和重启命令
    [.net] 关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files… ‘Access is denied.’ 的解决办法
    [linux] XEN里面的虚拟机centos无法使用date s设置时间
    字符串替换,string的强大
    C语言学习笔记(1)
    C语言学习笔记(8)
  • 原文地址:https://www.cnblogs.com/Willems/p/12409249.html
Copyright © 2011-2022 走看看