hdu 2108 凸多边形判定

直接上模板

/*
* hdu2108/win.cpp
* Created on: 2011-10-19
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
const int MAX_POINT_NUM = 1100;

typedef int typec;
typedef struct {
typec x;
typec y;
} MyPoint;
const double eps = 1e-8;
#define _sign(x) ((x)>eps?1:((x)<-eps?2:0))
MyPoint points[MAX_POINT_NUM];

inline double xmult(MyPoint p1, MyPoint p2, MyPoint p0) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}

int is_convex(int n, MyPoint* p) {
int i, s[3] = { 1, 1, 1 };
for (i = 0; i < n && (s[1] | s[2]); i++) {
s[_sign(xmult(p[(i + 1) % n], p[(i + 2) % n], p[i]))] = 0;
}
return s[1] | s[2];
}

int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int N;
while (scanf("%d", &N) == 1 && N > 0) {
for (int i = 0; i < N; i++) {
scanf("%d%d", &points[i].x, &points[i].y);
}
if (is_convex(N, points)) {
puts("convex");
} else {
puts("concave");
}
}
return 0;
}



posted @ 2011-10-19 14:13  moonbay  阅读(161)  评论(0编辑  收藏  举报