极角排序
来源:互联网 发布:网络推广方案 编辑:程序博客网 时间:2024/05/21 13:58
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;struct point { long long x, y; int f;//代表在哪一个象限 friend point operator - (point a, point b) { return (point){a.x-b.x, a.y-b.y}; }};
//利用叉积的正负来作cmp.(即是按逆时针排序).long long cross(point a, point b, point c) {//AB X AC return (b.x-a.x) * (c.y-a.y) - (b.y-a.y) * (c.x-a.x);}bool cmp(const point &a, const point &b) {//逆时针排序 point origin; origin.x = origin.y = 0; return cross(origin, a, b) < 0;}
//利用complex的内建函数#include<complex>#define x real()#define y imag()#include<algorithm>using namespace std;bool cmp(const Point& p1, const Point& p2) { return arg(p1) < arg(p2);}
//利用arctan计算极角大小。(范围『-180,180』)bool cmp(const Point& p1, const Point& p2) { return atan2(p1.y, p1.x) < atan2(p2.y, p2.x);}
//利用象限加上极角,叉积bool cmp(const point &a, const point &b) { //先按象限排序,再按极角排序,再按远近排序 if (a.y == 0 && b.y == 0 && a.x*b.x <= 0)return a.x>b.x; if (a.y == 0 && a.x >= 0 && b.y != 0)return true; if (b.y == 0 && b.x >= 0 && a.y != 0)return false; if (b.y*a.y <= 0)return a.y>b.y; point one; one.y = one.x = 0; return cross(one,a,one,b) > 0 || (cross(one,a,one,b) == 0 && a.x < b.x);}//或者int cal(point a) {//计算象限 if(a.x > 0 && a.y >= 0) return 1; if(a.x <= 0 && a.y > 0) return 2; if(a.x < 0 && a.y <= 0) return 3; if(a.x >= 0 && a.y < 0) return 4;}bool cmp(const point a, const point b) { //先按象限排序,再按极角排序 if(a.f < b.f) return true; if(a.f > b.f) return false; long long tmp = cross(s, a, b); if(tmp > 0) return true; return false;}
//求cosA的符号bool ok(point a, point b, point c) { long long tmp = (b.x-a.x) * (c.x-a.x) + (b.y-a.y) * (c.y - a.y); if(tmp > 0) return true; return false;}
0 0
- 计算几何的排序--极角排序
- 极角排序
- 极角排序
- 极角排序
- 极角排序
- poj2007极角排序
- 极角排序
- 极角排序
- 极角排序
- 极角排序
- 极角排序 POJ1696
- 极角排序
- hdu5738(极角排序)
- 极角排序
- 极角排序
- 极角排序
- LightOJ1285->极角排序
- 极角排序
- 1883: 蛤玮当上主席(水)
- Django配置问题1:syncdb
- Reading Note : Gibbs Sampling for the Uninitiated
- 线程池的基本使用(中)
- 激励学习策略
- 极角排序
- 如何处理被中断的系统调用
- Android短信验证 自动输入到文本框
- 01背包问题
- 服务器控件单选,多选和表格样式冲突,多边框
- 图像处理 - 图像平移
- Cpp环境【Vijos1037】【CQYZos1391】搭建双塔
- Announcing Dolt, a drop-in Libtool replacement which cuts build times in
- 程序猿的一些幽默趣闻 个个经典