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;
    }



  • 相关阅读:
    WebAPI中路由参数中包含字符-点“.”
    Web API 授权筛选器
    WebApi
    C#视频拍照、视频录制项目示例
    WPF 获取鼠标屏幕位置、窗口位置、控件位置
    C#中字符串转换为计算公式
    ffmpeg开发文档
    .net core控制台应用程序初识
    网络书籍
    ffmpeg命令参数详解
  • 原文地址:https://www.cnblogs.com/moonbay/p/2217586.html
Copyright © 2011-2022 走看看