zoukankan      html  css  js  c++  java
  • 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;
    }



  • 相关阅读:
    C# vb实现浮雕特效滤镜效果
    一张图看懂SharpImage
    C#控制操控操作多个UVC摄像头设备
    C#读写修改设置调整UVC摄像头画面-缩放
    继承多态绕点 Java篇
    继承多态绕点 C#篇
    lock关键字理解
    关于C#迭代器
    关于排列组合中组合结果
    C#与Java中相等关系
  • 原文地址:https://www.cnblogs.com/moonbay/p/2217586.html
Copyright © 2011-2022 走看看