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 }
原文地址:https://www.cnblogs.com/jaydenouyang/p/9159402.html
时间: 2024-10-13 06:43:53