Time Limit: 3000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 4972 Accepted
Submission(s): 2250
1 #include <iostream>
2 using namespace std;
3 struct Point {
4 int x,y;
5 };
6 int Cross(Point a,Point b,Point c) //叉积
7 {
8 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
9 }
10 bool isConvex(Point p[],int n) //判断多边形是否是凸多边形,必须是按顺序排列的
11 {
12 int i;
13 p[n+1] = p[1];
14 p[n+2] = p[2]; //注意!!每一条边都要遍历
15 for(i=1;i<=n;i++)
16 if(Cross(p[i],p[i+1],p[i+2])>0) //是否右拐
17 return false;
18 return true;
19 }
20 int main()
21 {
22 int n;
23 while(cin>>n){
24 if(n==0) break;
25 int i;
26 Point p[1010];
27 for(i=1;i<=n;i++)
28 cin>>p[i].x>>p[i].y;
29 if(n<3 || isConvex(p,n)) //判断
30 cout<<"convex"<<endl;
31 else
32 cout<<"concave"<<endl;
33 }
34 return 0;
35 }
Freecode : www.cnblogs.com/yym2013
hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题),布布扣,bubuko.com
hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题)
原文:http://www.cnblogs.com/yym2013/p/3675574.html