POJ 2007 Scrambled Polygon(点的极角排序)
来源:互联网 发布:办公软件app 编辑:程序博客网 时间:2024/06/01 09:18
POJ 2007 Scrambled Polygon(点的极角排序)
http://poj.org/problem?id=2007
题意: ZOJ 2352
给你一个凸多边形的n个点,其中第一个点是(0,0).其他点乱序给出,要你按逆时针顺序输出该凸多边形的所有点.同样第一个点也输出(0,0).
分析:
由于是凸多边形,所以如果以(0,0)点作为起点,其他所有点与(0,0)点构成了一个向量,我们只需要按照向量的叉积排序即可.
两个向量A,B(它们有相同的起点(0,0) ). 如果A与B的叉积>0,那么B的另一个端点一定在A的左边. 这样排序之后,最右边的点第二个输出,最左边的点最后一个输出. 所有点就是按逆时针顺序输出的了.
AC代码: 用于POJ
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;const int maxn=100+10;struct Point{ double x,y; Point(){} Point(double x,double y):x(x),y(y){}}P[maxn];typedef Point Vector;Vector operator-(Point A,Point B){ return Vector(A.x-B.x,A.y-B.y);}double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}bool cmp(Point A,Point B){ return Cross(A-P[0],B-P[0])>0;}int main(){ int n=0; while(scanf("%lf%lf",&P[n].x,&P[n].y)==2) { ++n; } sort(P+1,P+n,cmp); for(int i=0;i<n;++i) printf("(%.0lf,%.0lf)\n",P[i].x,P[i].y); return 0;}
AC代码: 用于ZOJ
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;const int maxn=100+10;struct Point{ double x,y; Point(){} Point(double x,double y):x(x),y(y){}}P[maxn];typedef Point Vector;Vector operator-(Point A,Point B){ return Vector(A.x-B.x,A.y-B.y);}double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}bool cmp(Point A,Point B){ return Cross(A-P[0],B-P[0])>0;}int main(){ int T; scanf("%d",&T); scanf("%lf%lf",&P[0].x,&P[0].y); for(int kase=1;kase<=T;kase++) { int n=1; while(scanf("%lf%lf",&P[n].x,&P[n].y)==2) { if(P[n].x==0 && P[n].y==0) break; ++n; } sort(P+1,P+n,cmp); for(int i=0;i<n;++i) printf("(%.0lf,%.0lf)\n",P[i].x,P[i].y); if(kase<T)printf("\n"); } return 0;}
0 0
- 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 Scrambled Polygon 2007 (凸包基础点排序)
- HDU-2007 Scrambled Polygon 极角排序
- PKU 2007 Scrambled Polygon 极角排序
- poj 2007 Scrambled Polygon--按极角排序
- 计算几何:极角排序(poj 2007 Scrambled Polygon)与简单凸包(poj 1113 Wall)
- 2.4 Git 基础 - 撤消操作
- 构建根文件系统
- java线程同步锁优化
- poj2135 Farm Tour(最小费用流)
- Java中byte转换int时与0xff进行与运算的原因
- POJ 2007 Scrambled Polygon(点的极角排序)
- Combination Sum II
- VS2008 自定义消息的问题
- 2014 ACM/ICPC Asia Regional Guangzhou Online
- 【华为SO挑战赛】电话号码检查
- LeetCode - 3Sum Closest
- 2.5 Git 基础 - 远程仓库的使用
- nyoj 448 寻找最大数(贪心)
- 找一个方向,让自己继续前行