資源簡介
凸包melkman算法cpp實現,通過poj1113題測試
代碼片段和文件信息
/*?ac?poj?1113
由于1113輸入已經是個簡單多邊形,故可以直接用melkman求凸包o(n)復雜度
如果輸入只是個點集合,就要先排序?再用melkman?復雜度為nlgn
排序可先按照x排,再y排
*/
#include
#include
#include
#define?N?1002
#define?pi?3.141592653589793
struct?POINT{
int?xy;
};
int?nlD[N*2]topbot;
POINT?point[N];
inline?double?dis(POINT?aPOINT?b){
double?x=a.x-b.x;
double?y=a.y-b.y;
return?sqrt(x*x+y*y);
}
inline?int?cross(POINT?aPOINT?b){
return?a.x*b.y-b.x*a.y;
}
int?isleft(POINT?oPOINT?aPOINT?b){ //判斷ab是不是在oa的左邊
POINT?x;
POINT?y;
x.x=a.x-o.x;
x.y=a.y-o.y;
y.x=b.x-a.x;
y.y=b.y-a.y;
return?cross(xy);
}
void?melkman(){
int?it;
bot=n-1;?top=n;
D[top++]=0;?D[top++]=1;
for(i=2;i if(isleft(point[D[top-2]]point[D[top-1]]point[i])!=0)?break; //尋找第三個點?要保證3個點不共線!!
D[top-1]=i; //共線就更換頂點
}
D
- 上一篇:售前、售中、售后服務方案及保障措施方案
- 下一篇:基于51單片機電子時鐘的設計
評論
共有 條評論