标签:des style blog color io os java ar strong
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5188 Accepted Submission(s): 2364
第一条几何水题。判多边形凹凸 。
直接求叉积,用叉积正负(顺时针方向为正,逆时针方向为负)来判断,连续三个点的所成夹角的角度就OK了 。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; #define x first #define y second typedef long long LL; typedef pair<int,int> Point; const int N = 2550; vector<Point>e; int main() { int n ,xx, yy ; #ifdef LOCAL freopen("in.txt","r",stdin); #endif while(cin>>n) { if(!n)break; e.clear(); for(int i = 0 ; i< n ;++i ){ cin>>xx>>yy; e.push_back(Point(xx,yy)); } int flag = 1 ; for( int i =0 ; i < n ; ++i ){ if( ( e[ (i+1) % n ].x - e[i].x ) * ( e[(i+2) % n ] .y - e[(i+1) % n].y ) - ( e[ (i+1) % n ].y - e[i].y ) * ( e[(i+2) % n ] .x - e[(i+1) % n].x ) < 0 ){ flag = 0 ; break ; } } if(flag ) cout<<"convex"<<endl; else cout<<"concave"<<endl; } return 0; }
标签:des style blog color io os java ar strong
原文地址:http://www.cnblogs.com/YRETSIM/p/3979107.html