poj1912 求直線與凸包是否相交 logn

2021-09-11 01:46:59 字數 1720 閱讀 9939

我真的佛了,竟然還有0<=n<=1e5的情況,導致我一直re,因為處理斜率的時候要特殊處理w[n-1],所以n=0時,w[n-1]會陣列越界導致re。。。。計算幾何竟然還有給0個點的情況,真是有毒,dicuss裡只有人提醒n=1的情況。。。。

這裡需要改變一下凸包的點的先後順序,優先y座標小的在前,這樣就可以根據atan2的值二分了,由於是逆時針的凸包,第乙個點一定是y座標最小的中間x座標最小的,那麼1號點到2號點的atan2一定大於0,>0邊構成右凸包,<0的構成左凸包,由於atan2的取值範圍為(-pi,pi],從右凸包到左凸包的atan2值有乙個梯度下滑,所以只要加上乙個2*pi,就可以是逆時針遞增的順序了。

inline bool cmp(const point &a,const point &b)

然後對於s->e的線,二分找到第乙個比他大的atan2值,根據下標得出那個店,e->s同樣得出乙個點,如果有與凸包相交的話,這兩個點一定在這兩條線的兩邊。

#include#include#include#include#define maxl 100010

#define eps 1e-8

const double pi=acos(-1.0);

using namespace std;

inline int sgn(double x)

struct point

point operator + (const point &b)const

point operator - (const point &b)const

inline bool operator == (const point &b)const

friend point operator *(const double t,const point &p)

inline double norm() };

inline double dot(const point &a,const point &b)

inline double det(const point &a,const point &b)

struct polygon_convex

};inline bool cmp(const point &a,const point &b)

polygon_convex convex_hull(vectora)

int k=m;//l-1號點一定在其中,從l-2開始

for(int i=l-2;i>=0;i--)

res.p.resize(m);

if(a.size()>1)

res.p.resize(m-1);

return res;

}int n;

vectora;

polygon_convex hull;

double w[maxl];

inline void prework()

inline void mainwork()

int i=find(geta(e-s));

int j=find(geta(s-e));

if(sgn(det(e-s,hull.p[i]-s)*det(e-s,hull.p[j]-s))<0)

puts("bad");

else

puts("good"); }}

inline void print(){}

int main()

poj1113 求凸包 計算凸包周長

經典的求凸包題,模板題。要求用資源最少,那肯定這個多邊形是個凸多邊形,也就是凸包。所以先求出凸包,計算它的周長。還有就是這道題所說的,要離城牆l遠,其實就是在加上乙個圓的周長,圓的半徑就是l。都說到這了,這道題還差什麼?還差乙個經典的凸包模板!哈哈 如下 include include includ...

POJ 1113 Wall 凸包求周長

大意 給定些點,組成多邊形,問有沒有圓把多邊形圍起來並且圓距離多邊形最小的距離是m 求多邊形的邊長。思路 首先要知道怎麼求外邊圓的周長,l圓 l 半徑為m的圓 凸包外接圓半徑。至於為什麼要加上小圓半徑因為所有的小圓的一部分角度加和一定為360。include include include incl...

Poj2187 凸包求最大距離

凸包 暴力求解,注意n 0,和n 1的情況 include include include include include include include define maxn 50000 10 using namespace std typedef struct point point int ...