#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, &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"