POJ 2007 极角排序
来源:互联网 发布:淘宝挂机软件是真的吗 编辑:程序博客网 时间:2024/05/16 15:58
题目扯了那么多,又是算斜率, 又是不同象限的,最后就是一个极角排序
注意,这里的极角排序是一般grahm-scan算法的逆序即可
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>const int maxn=55;const double eps=1e-8;using namespace std;int sgn(double x){ if(fabs(x)<eps) return 0; if(x>0) return 1; if(x<0) return -1;}struct point{ double x,y; //double slope=0; point(){} point(double _x,double _y){ x=_x; y=_y; }};typedef point vector;vector operator - (vector a,vector b){ return point(a.x-b.x,a.y-b.y);}double operator * (vector a,vector b){ return a.x*b.x+a.y*b.y;}double operator ^ (vector a,vector b){ return a.x*b.y-a.y*b.x;}bool operator < (vector a,vector b){ if(a.x==b.x &&a.y<b.y ||a.x<b.x) return true; return false;}double dis(point a,point b){ return hypot(a.x-b.x,a.y-b.y);}struct convex{ int n; point p[maxn];};point p[maxn];bool cmp(point a,point b){ int d=sgn((a-p[0])^(b-p[0])); if(d<0 || d==0 && sgn(dis(a,p[0])-dis(b,p[0]))<0 )//d<0 逆序 return true; return false;}int main(){ //freopen("input.txt","r",stdin); int i=0; while(~scanf("%lf%lf",&p[i].x,&p[i].y)) i++; sort(p,p+i,cmp); printf("(%d,%d)\n",int(p[0].x),int(p[0].y)); for(int j=i-1;j>0;j--) printf("(%d,%d)\n",int(p[j].x),int(p[j].y));}
0 0
- poj 2007(极角排序)
- POJ 2007 极角排序
- poj 2007 极角排序
- poj 2007 极角排序
- POJ 2007 极角排序
- POJ 2007 极角排序
- poj 2007 Scrambled Polygon 极角排序
- POJ 2007 Scrambled Polygon(极角排序)
- POJ 2007 Scrambled Polygon 极角排序
- POJ 2007 (极角排序)
- POJ 2007 (极角排序)
- poj 2007 Scrambled Polygon [极角排序]
- POJ 2007 Scrambled Polygon 极角排序
- poj 2007 Scrambled Polygon 【极角排序】
- POJ 2007 Scrambled Polygon(极角排序)
- poj 2007 凸包 极角排序
- POJ 2007 Scrambled Polygon (极角排序)
- poj 1696 极角排序
- poj 1990 MooFest
- Java线程总结(十一):并发包------CyclicBarrier
- 介绍一下索引
- maven_pom解析
- Swift枚举详解
- POJ 2007 极角排序
- StackOverflow: 你没见过的七个最好的Java答案
- cs231n-(5)神经网络-1:建立架构
- 支付宝接口编码不规范问题
- 分享一个自己写的用python比对数据库表数据的脚本
- 树的结构总结
- scala中下划线的使用
- Myeclips出现An internal error occurred during: "Retrieving archetypes:". GC overhead limit exceeded
- LintCode:最接近的三数之和