1 /*UVA10078 2 按顺序输入多边形上的点,判断它是一个凸边形还是凹多边形 3 方法:求凸包,如果凸包的点数少于原来多边形的点数,就一定是凹的,不变则是凸的。 4 所以这里的数目特别重要 5 所以凸包上共线的点要算上,在求凸包的函数中方向向量的旋转,记得是<而不是<= 6 整理出模板 7 */ 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <string.h> 11 #include <math.h> 12 #include <ctype.h> 13 #include <string> 14 #include <iostream> 15 #include <sstream> 16 #include <vector> 17 #include <queue> 18 #include <stack> 19 #include <map> 20 #include <list> 21 #include <set> 22 #include <algorithm> 23 #define eps 1e-10 24 #define maxn 100+10 25 26 using namespace std; 27 28 struct Point 29 { 30 double x,y; 31 Point(){} 32 Point(double xx,double yy){x=xx,y=yy;} 33 bool operator < (const Point& p)const{ 34 return (x<p.x || (fabs(x-p.x)<eps && y<p.y)); 35 } 36 } P1[maxn],P2[maxn]; 37 38 39 typedef Point Vector; 40 Vector operator - (Vector A, Vector B) 41 { 42 return (Vector){A.x-B.x, A.y-B.y}; 43 } 44 double Cross(Vector A, Vector B) 45 { 46 return A.x*B.y - A.y*B.x; 47 } 48 int ConvexHull(Point *p, int n, Point* ch) //求凸包 49 { 50 sort(p, p + n);//先按照 x,再按照 y 51 int m = 0; 52 for(int i = 0; i < n; i++) 53 { 54 while(m > 1 && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) < 0) m--; 55 ch[m++] = p[i]; 56 } 57 int k = m; 58 for(int i = n-2; i >= 0; i--) 59 { 60 while(m > k && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) < 0) m--; 61 ch[m++] = p[i]; 62 } 63 if(n > 1) m--; 64 return m; 65 } 66 int n1,n2; 67 int main() 68 { 69 while(scanf("%d",&n1)!=EOF && n1>0) 70 { 71 for(int i=0; i<n1; i++) 72 { 73 int x,y; 74 cin>>x>>y; 75 P1[i].x=(double)x; 76 P1[i].y=(double)y; 77 } 78 n2=ConvexHull(P1,n1,P2); 79 if(n2==n1) cout<<"No"<<endl;else cout<<"Yes"<<endl; 80 81 } 82 return 0; 83 }