5種極角排序的方法

2021-08-21 16:48:04 字數 2567 閱讀 6597

全部:

#include

using

namespace

std;

typedef

long

long ll;

const

int n = 10005;

const

int inf = 0x3f3f3f3f;

const

double eps = 1e-8;

const

int mod = 1e9 + 7;

bool dy(double x,double y) // x > y

bool xy(double x,double y) // x < y

bool dyd(double x,double y) // x >= y

bool xyd(double x,double y) // x <= y

bool dd(double x,double y) // x == y

int n;

struct lp

lp(double a,double b)

}cw[n];

lp operator +(lp a,lp b);}

lp operator -(lp a,lp b);}

lp operator *(lp a,double b);}

lp operator /(lp a,double b);}

double

operator *(lp a,lp b)

double

operator ^(lp a,lp b)

inline

double crossdot(lp a,lp b)

inline

double area2(lp a,lp b,lp c)

double leng(lp a,lp b)

double distoline(lp p,lp a,lp b)

//3 4 1 2

bool cmp1(lp a,lp b)

//象限排序,注意包含四個座標軸

int quadrant(lp a)

//1 2 3 4

bool c***(lp a,lp b)

return quadrant(a)//先按象限排序,再按極角排序,再按遠近排序

// 1 2 3 4

bool cmp4(const lp &a, const lp &b)

//象限排序,注意包含四個座標軸

int quadrant1(lp a)

//3 4 1 2

bool cmp5(lp &a,lp &b)

return qaint main()

sort(cw,cw+n,cmp1);

for(int i=0;iprintf("%d (%.0f,%.0f)\n",cw[i].id, cw[i].x,cw[i].y);}}

return

0;}

部分:

#include

using

namespace

std;

typedef

long

long ll;

const

int n = 10005;

const

int inf = 0x3f3f3f3f;

const

double eps = 1e-8;

const

int mod = 1e9 + 7;

int n;

struct lp

lp(double a,double b)

}cw[n];

lp operator +(lp a,lp b);}

lp operator -(lp a,lp b);}

lp operator *(lp a,double b);}

lp operator /(lp a,double b);}

double

operator *(lp a,lp b)

double

operator ^(lp a,lp b)

inline

double crossdot(lp a,lp b)

inline

double area2(lp a,lp b,lp c)

double leng(lp a,lp b)

double distoline(lp p,lp a,lp b)

//3 4 1 2

bool cmp1(lp a,lp b)

//象限排序,注意包含四個座標軸

int quadrant1(lp a)

//3 4 1 2

bool cmp5(lp &a,lp &b)

return qaint main()

sort(cw,cw+n,cmp1);

for(int i=0;iprintf("%d (%.0f,%.0f)\n",cw[i].id, cw[i].x,cw[i].y);}}

return

0;}

極角排序常用方法

寫在前面 儲存點的結構體和函式 1 struct point 儲存點2 5 6double cross double x1,double y1,double x2,double y2 計算叉積710 11double compare point a,point b,point c 計算極角 12 方...

極角排序詳解

極角排序詳解 名詞釋義 在平面內取乙個定點o,叫極點,引一條射線ox,叫做極軸,再選定乙個長度單位和角度的正方向 通常取逆時針方向 對於平面內任何一點m,用 表示線段om的長度 有時也用r表示 表示從ox到om的角度,叫做點m的極徑,叫做點m的極角,有序數對 就叫點m的極座標 四種極角排序 詳解 s...

極角排序理解

這裡我們說的極角排序,指的是對於二維座標中的點,當然也可以說是向量。極角排序的用途一般是預處理二維平面中的點,使之變得相對有序,接下來在有序的條件小用o n 或者o nlogn 處理,而不是無序條件下的o n n 的列舉。應用鏈結 關於叉積 叉積 0是指兩向量平行 重合 叉積 0,則向量a在向量b的...