void andrewScan(vp &polys,P *ps,int n) { u.clear(); l.clear(); polys.clear(); if(n < 3) return ; sort(ps,ps+n,cmpx); u.pb(ps[0]); u.pb(ps[1]); l.pb(ps[n-1]); l.pb(ps[n-2]); for(int i = 2;i < n;i++) { for(int j = u.size();j >= 2 && ccw(u[j-2],u[j-1],ps[i]) != 2;j--) u.pop_back(); u.pb(ps[i]); } for(int i = n-3;i >= 0;i--) { for(int j = l.size();j >= 2 && ccw(l[j-2],l[j-1],ps[i]) != 2;j--) l.pop_back(); l.pb(ps[i]); } polys = l; for(int i = 1;i < u.size()-1;i++) polys.pb(u[i]); }
void dpri1() { int n = 10; for(int i = 1;i<=n;++i) { int sign = (rand()%2)?1:-1; int num = rand()%10; int sign1 = (rand()%2)?1:-1; int num1 = rand()%10; test.pb(MP(sign*num,sign1*num1)); } sort(test.begin(),test.end()); int u = unique(test.begin(),test.end())-test.begin(); for(int i = 0;i<u;++i) { pLL now = test[i]; while(test1.size() > 1 && det(test1[test1.size()-2],now,test1[test1.size()-1])<0) test1.pop_back(); test1.pb(now); } ff(du,"list point(s):\n"); for(int i = 0;i<test.size();++i) ff(du,"(%I64d,%I64d)",test[i].X,test[i].Y); ff(du,"\nconvex hull point(s):\n"); for(int i = 0;i<test1.size();++i) ff(du,"(%I64d,%I64d)",test1[i].X,test1[i].Y); int _l = 0,_r = test1.size()-1; pLL now = MP(-4,1); while(_l<_r) { M; if(mid == 0 || mid == test1.size()-1) break; if((now*(test1[mid+1]-test1[mid])).X == 0 && (now*(test1[mid]-test1[mid-1])).X == 0) break; if((now*(test1[mid+1]-test1[mid])).X > 0 && (now*(test1[mid]-test1[mid-1])).X < 0) {_l = _r = mid;break;} if((now*(test1[mid+1]-test1[mid])).X < 0) _l = mid+1; else _r = mid-1; } ff(du,"\navailable point(s):\n"); for(int i = min(_l,_r);i<=max(_l,_r);++i) ff(du,"(%I64d,%I64d)",test1[i].X,test1[i].Y); }
forn(i,sz(v)) { while (sz(res)>1) { P last1=res[sz(res)-2]; P last2=res[sz(res)-1]; if ((last2-last1)*(v[i]-last1)<eps) res.pop_back(); else break; } res.pb(v[i]); }