HDU 2108 Shape of Hdu "Judging whether polygons are convex polygon templates"

Source: Internet
Author: User

#include <stdio.h> #include <math.h>const int maxn = 100000;struct point{double x, y;        Point () {}-point (double _x, double _y) {x = _x;    y = _y;    } Point operator-(const point &b) const {return point (x-b.x, Y-B.Y);    }}P[MAXN];d ouble eps = 1e-10;int dcmp (double x) {if (Fabs (x) < EPS) return 0; else return x < 0? -1:1;} Double Cross (Point A, point B) {return a.x*b.y-a.y*b.x;}     /** judge whether the polygon is a convex hull "with collinear" */bool Isconvex (point *p, int n) {p[n] = p[0];//Border processing p[n+1] = p[1];//Note You can also use%n processing, subscript starting from 0    int now = dcmp (Cross (p[1]-p[0], p[2]-p[1]));        for (int i = 1; i < n; i++) {int next = DCMP (P[i+1]-p[i], p[i+2]-p[i+1]);        if (Now*next < 0)//This can be collinear {return false; } now = Next; Note record the critical condition} return true;    int main () {int n;        while (scanf ("%d", &n)! = EOF) {if (n = = 0) break; for (int i = 0; i < n; i++) scanf ("%lf%lf", &p[i].x, &AMP;P[I].Y);        BOOL flag = Isconvex (p,n);        if (flag) printf ("convex\n");    else printf ("concave\n"); } return 0;}

HDU 2108 Shape of Hdu "Judging whether polygons are convex polygon templates"

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.