码迷,mamicode.com
首页 > 编程语言 > 详细

poj2007(极角排序)

时间:2016-08-13 11:28:08      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

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

#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;
}

  

poj2007(极角排序)

标签:

原文地址:http://www.cnblogs.com/td15980891505/p/5767580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!