凸包求直徑(socalled。。)
採用graham+rotating_calipers,graham複雜度nlogn,rc演算法複雜度n,所以時間複雜度不會很高。
學習rc演算法,可到
另:另外,graham的過程即將整理。。
#include #include #include using namespace std;
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))0 ? 1 : -1) : (ret > 0 ? 1 : -1);
}void _graham(int n, point* p, int& s, point* ch)
int wipesame_cp(const void *a, const void *b)
int _wipesame(point * p, int n)
//構造凸包介面函式,傳入原始點集大小n,點集p(p原有順序被打亂!)
//返回凸包大小,凸包的點在convex中
//引數maxsize為1包含共線點,為0不包含共線點,預設為1
//引數clockwise為1順時針構造,為0逆時針構造,預設為1
//在輸入僅有若干共線點時演算法不穩定,可能有此類情況請另行處理!
int graham(int n, point* p, point* convex, int maxsize = 1, int dir = 1)
int rotating_calipers(point *ch, int n)
return ans;
}int main()
graham(n, p, convex,1,0);
cout << rotating_calipers(convex, n) << endl;
return 0;
}
poj 2187(旋轉卡殼)
傳送門 模板題,求凸包,用旋轉卡殼求出最遠點對。因為把int弄成double,wa了好幾次,差點對idy大神給的模板失去信心。不過事實證明idy的寫法沒問題,orz!include include include include include include using namespace std...
poj2187 凸包問題
pseudo code graham scan algorithm input a set of pointss select the rightmost lowest point p0 ins.sortsangularly about p0 as a center.for ties,discard...
poj2187 凸包直徑模板
include include include include using namespace std define inf 50005 struct node node point inf int n,s inf top double cross node a,node b,node c doub...