POJ 2007 Scrambled Polygon(极角排序)
2016-04-19 01:15
465 查看
题目链接:
POJ 2007 Scrambled Polygon
POJ 2007 Scrambled Polygon
//向量a叉乘向量b小于0,说明向量b在向量a的右侧。 //极角排序 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <climits> #include <cmath> using namespace std; const int MAX_N=100; int n=0; struct Point { int x,y; }point[MAX_N],origin; bool cmp(Point a,Point b) { int x1=a.x-origin.x,y1=a.y-origin.y; int x2=b.x-origin.x,y2=b.y-origin.y; return x2*y1-x1*y2 < 0; //计算b和原点的向量p1与a和原点的向量p2的叉积是否小于0,小于0说明p1在p2的右侧 } int main() { freopen("Bin.txt","r",stdin); scanf("%d%d",&origin.x,&origin.y); while(~scanf("%d%d",&point .x,&point .y)) { n++; } sort(point,point+n,cmp); printf("(%d,%d)\n",origin.x,origin.y); for(int i=0;i<n;i++){ printf("(%d,%d)\n",point[i].x,point[i].y); } return 0; }
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- 用单调栈解决最大连续矩形面积问题
- 2632 Crashing Robots的解决方法
- 1573 Robot Motion (简单题)
- POJ 1200 Crazy Search(简单哈希)
- 【高手回避】poj3268,一道很水的dijkstra算法题