标签:输出 public panel while 数学 题目 知识 高中 pac
2017-07-15 22:29:06
4 0 0 1 0 1 1 0 1 0Sample Output
convex
代码如下;
#include <iostream> using namespace std; class point { public: int x; int y; point(int a,int b):x(a),y(b) {} point():x(0),y(0) {} void change(int a,int b) { x = a; y = b; } }; class vec { public: point a; point b; point pos; point nag; vec():a(point(0,0)), b(point(0,0)),pos(),nag() {} vec(point &aa,point&bb): a(aa),b(bb),pos(b.x-a.x,b.y-a.y),nag(a.x-b.x,a.y-b.y) {} void change(point & aa,point &bb) { a.x = aa.x; a.y = aa.y; b.x = bb.x; b.y = bb.y; pos.x = b.x-a.x; pos.y = b.y-a.y; nag.x = a.x-b.x; nag.y = a.y-b.y; } }; int chacheng(vec val1,vec val2) { if( (val1.nag.x * val2.pos.y-val1.nag.y*val2.pos.x)> 0) { return 1; } else return 0; } int main() { int num; int a,b; while(cin >> num && num!=0) { point *po = new point[num]; vec *ve = new vec[num]; for(int i = 0 ; i < num ; i++) { cin >> a >> b; po[i].change(a,b); } for(int i = 0 ; i < num ; i++) { if(i != num-1) ve[i].change(po[i],po[i+1]); else ve[i].change(po[i],po[0]); } int cnt = 0; for(int i = 0 ; i < num ; i++) { if(i == num-1) { if(chacheng(ve[i],ve[0])==1) { cnt++; } } else { if(chacheng(ve[i],ve[i+1])==1) { cnt++; } } } if(cnt == 0 || cnt == num) { cout << "convex" << endl; } else { cout << "concave"<<endl; } } return 0; }
标签:输出 public panel while 数学 题目 知识 高中 pac
原文地址:http://www.cnblogs.com/ilovelianghui/p/7187961.html