• 简单几何(极角排序) POJ 2007 Scrambled Polygon


    题目传送门

    题意:裸的对原点的极角排序,凸包貌似不行。

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015/11/3 星期二 14:46:47
    * File Name     :POJ_2007.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    const double EPS = 1e-10;
    const double PI = acos (-1.0);
    int dcmp(double x)  {
        if (fabs (x) < EPS) return 0;
        else    return x < 0 ? -1 : 1;
    }
    struct Point   {
        double x, y;
        Point ()    {}
        Point (double x, double y) : x (x), y (y) {}
        Point operator - (const Point &r) const {       //向量减法
            return Point (x - r.x, y - r.y);
        }
        bool operator == (const Point &r) const {       //判断同一个点
            return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;
        }
        bool operator < (const Point &r) const  {
            return x < r.x || (dcmp (x - r.x) == 0 && y < r.y);
        }
    };
    typedef Point Vector;
    Point read_point(void)  {
        double x, y;
        scanf ("%lf%lf", &x, &y);
        return Point (x, y);
    }
    double polar_angle(Vector A)    {
        return atan2 (A.y, A.x);
    }
    double dot(Vector A, Vector B)  {
        return A.x * B.x + A.y * B.y;
    }
    double cross(Vector A, Vector B)    {
        return A.x * B.y - A.y * B.x;
    }
    
    bool cmp(Point a, Point b)  {
        return cross (a - Point (0, 0), b - Point (0, 0)) > 0;
    }
    
    int main(void)    {
        vector<Point> ps;
        double x, y;
        while (scanf ("%lf%lf", &x, &y) == 2)   {
            ps.push_back (Point (x, y));
        }
        sort (ps.begin ()+1, ps.end (), cmp);
        for (int i=0; i<ps.size (); ++i)    {
            printf ("(%.0f,%.0f)
    ", ps[i].x, ps[i].y);
        }
    
       //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.
    ";
    
        return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    百度搜索API v3版本与soap
    Yii整合ZF2及soap实例
    Getting started writing ZF2 modules
    js写出php中的函数系列
    一些有用的命令
    a标签至于flash之上的时候,IE浏览器无法点击连接的问题
    js问题集锦
    php常用函数集锦[备份用的]
    用过的一些js函数[备份用的]
    ELK
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4935443.html
Copyright © 2020-2023  润新知