POJ 2007 Scrambled Polygon 极角排序
2013-08-29 10:35
543 查看
题意:
给你一些点,这些点里面一定有(0,0)原点,并且没有第二象限中的点,这些点是一个凸包,让你按极角序输出这些点。
就排序,比较水,没凸包真扫兴
View Code
给你一些点,这些点里面一定有(0,0)原点,并且没有第二象限中的点,这些点是一个凸包,让你按极角序输出这些点。
就排序,比较水,没凸包真扫兴
View Code
#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; #define eps 1e-8 #define inf 1<<29 struct point { int x, y; }p[52]; int det(int x1, int y1, int x2, int y2) { return x1 * y2 - x2 * y1; } int cross(point o, point a, point b) { return det(a.x - o.x, a.y - o.y, b.x - o.x, b.y - o.y); } double f(int x) { return x * x * 1.0; } double dis(point a, point b) { return sqrt( f(a.x - b.x) + f(a.y - b.y) ); } bool cmp(point a, point b) { int tmp = cross(p[0], a, b); if(tmp > 0) return 1; if(tmp == 0 && dis(p[0], a) < dis(p[0], b) )return 1; return 0; } int main() { int i, j; int n = 0; //freopen("int.txt", "r", stdin); while( ~scanf("%d%d", &p .x, &p .y) ) { if(p .y < p[0].y) swap(p[0], p ); else if(p .y == p[0].y && p .x < p[0].x) swap(p[0], p ); n++; } sort(p + 1, p + n, cmp); for(i = 0; i < n; i++) if(p[i].x == 0.0 && p[i].y == 0.0){ j = i; break; } for(i = j; i < n; i++) printf("(%d,%d)\n", p[i].x, p[i].y); for(i = 0; i < j; i++) printf("(%d,%d)\n", p[i].x, p[i].y); }
相关文章推荐
- poj 2007 Scrambled Polygon [极角排序]
- POJ 2007 Scrambled Polygon 极角排序
- POJ 2007 Scrambled Polygon (极角排序)
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
- POJ 2007 Scrambled Polygon(点的极角排序)
- POJ 2007 Scrambled Polygon(极角排序)
- POJ 2007 Scrambled Polygon(计算几何 叉积排序啊)
- poj 2007 Scrambled Polygon 【极角排序】
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
- POJ 2007 Scrambled Polygon(极角排序)
- poj 2007 Scrambled Polygon (极角排序模板题)
- poj 2007 Scrambled Polygon(极角排序)
- POJ 2007 Scrambled Polygon (简单极角排序)
- POJ 2007 Scrambled Polygon 极角排序
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon 极角排序
- POJ 2007 Scrambled Polygon [凸包 极角排序]
- POJ 2007 Scrambled Polygon(极角排序)
- POJ 2007:Scrambled Polygon (极角排序)
- poj 2007 Scrambled Polygon(极角排序)