poj2007(极角排序)

利用叉积按照逆时针方向进行极角排序,

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<fstream>
using namespace std;
struct Point{
	int x, y;
	Point(int a = 0, int b = 0) :x(a), y(b){}
};
Point operator-(Point a, Point b){
	return Point(a.x - b.x, a.y - b.y);
}
int Cross(Point p0,Point p1, Point p2){
	Point a = p1 - p0;
	Point b = p2 - p0;
	return a.x*b.y - b.x*a.y;
}
Point o;
bool cmp(Point a, Point b){
	return Cross(o, a, b)>0;
}
Point P[51];
int main(){
	int n = 0;
	while (~scanf("%d%d", &P[n].x, &P[n].y))n++;
	/*cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d%d", &P[i].x, &P[i].y);*/
	Point o = P[0];
	sort(P+1, P + n, cmp);
	for (int i = 0; i < n; i++)
		printf("(%d,%d)\n",P[i].x,P[i].y);
	return 0;
}

  

posted @ 2016-08-13 11:07  曹孟德  阅读(446)  评论(0编辑  收藏  举报