码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 2108 Shape of HDU(判定是不是凸多边形)

时间:2018-06-09 15:31:18      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:struct   break   namespace   using   include   str   tor   #define   open   

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <string>
 6 #include <map>
 7 #include <cmath>
 8 #include <vector>
 9 
10 #define Faster ios::sync_with_stdio(false),cin.tie(0)
11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
12 #define Close fclose(stdin),fclose(stdout)
13 const int maxn = 1e5 + 5;
14 using namespace std;
15 const int MOD = 1e9+7;
16 typedef long long ll;
17 
18 const double eps = 1e-6;
19 #define _sign(x)((x)>eps?1:((x)<-eps?2:0))
20 
21 
22 struct point
23 {
24     double x,y;
25 }p[maxn];
26 
27 double xmult(point p1,point p2,point p0) { 
28     return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); 
29 }
30 
31 int is_convex(int n) { 
32     int i,s[3]={1,1,1}; 
33     for (i=0;i<n&&s[1]|s[2];i++) 
34         s[_sign(xmult(p[(i+1)%n],p[(i+2)%n],p[i]))] = 0; 
35     return s[1]|s[2]; 
36 }
37 
38 int main(){
39     Faster;
40     int n;
41     while(cin >> n){
42         if(n == 0)
43             break;
44         for(int i = 0;i < n;i++){
45             cin >> p[i].x >> p[i].y;
46         }
47         if(is_convex(n)){
48             cout << "convex" << endl;
49         }
50         else
51             cout << "concave" << endl;
52     }
53     return 0;
54 }

 

hdu 2108 Shape of HDU(判定是不是凸多边形)

标签:struct   break   namespace   using   include   str   tor   #define   open   

原文地址:https://www.cnblogs.com/jaydenouyang/p/9159402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!