"Convex-clad Graham-method pole-angle Sort" POJ-scrambled Polygon

Source: Internet
Author: User

link:http://poj.org/problem?id=2007

Graham method for Convex Hull (O (nlog2n))

/* Extreme Corner Sort */
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace STD;

const int N = +;
Const double EPS = 1e-6;
struct point
{
    double x, y;
};
Point A[n];
Whether to turn left Strictly, collinear does not count (fork multiply)
double xmult (point a,point b,point C)   //(CA) x (CB)
{
    return (a.x-c.x) * (b.y-c.y )-(b.x-c.x) * (A.Y-C.Y);
}
Sort sort Function
bool CMP (const point &a, const point &b)//Counter-clockwise sort
{Point
    origin;
    Set the origin point
    origin.x = ORIGIN.Y = 0;
    Return Xmult (origin,b,a) <eps;
}

int main ()
{
    int n=0;
    while (scanf ("%lf%lf", &a[n].x,&a[n].y)!=eof)
        ++n;
    A polar sort, the first empty past
    sort (a+1,a+n,cmp);
    for (int i=0; i<n; ++i)
        printf ("(%.0LF,%.0LF) \ n", a[i].x,a[i].y);
    return 0;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.