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]); }
int main() { int D, nP; int cnt[2][3]; int tcase = 0; int x1, x2, y1, y2; chds.reserve(2000); chps.reserve(2000); u.reserve(2000); l.reserve(2000); while(1) { D = geti(); nP = geti(); if(D == 0 && nP == 0) break; for(int i = 0;i < D;i++) { x1 = geti(); y1 = geti(); x2 = geti(); y2 = geti(); ds[i*4] = (P){x1,y1}; ds[i*4+1] = (P){x1,y2}; ds[i*4+2] = (P){x2,y1}; ds[i*4+3] = (P){x2,y2}; } for(int i = 0;i < nP;i++) { x1 = geti(); y1 = geti(); x2 = geti(); y2 = geti(); ps[i*4] = (P){x1,y1}; ps[i*4+1] = (P){x1,y2}; ps[i*4+2] = (P){x2,y1}; ps[i*4+3] = (P){x2,y2}; } andrewScan(chds,ds,4*D); andrewScan(chps,ps,4*nP); bool ok = 0; for(int i = 0;i < chds.size();i++) { for(int j = 0;j < chps.size();j++) { memset(cnt,0,sizeof cnt); for(int k = 0;k < 4*D;k++) cnt[0][ccw(chds[i],chps[j],ds[k])]++; for(int k = 0;k < 4*nP;k++) cnt[1][ccw(chds[i],chps[j],ps[k])]++; if(((cnt[1][1]&&!cnt[1][2]&&cnt[0][2]&&!cnt[0][1]) || (!cnt[1][1]&&cnt[1][2]&&!cnt[0][2]&cnt[0][1]) ) && (cnt[1][0]==1&&cnt[0][0]==1)) { ok = 1; goto ANSWERING; } } } ANSWERING: printf("Case %d: ",++tcase); if(ok) puts("It is possible to separate the two groups of vendors."); else puts("It is not possible to separate the two groups of vendors."); puts(""); } return 0; }
double bruteforce(vp &p) { int i, j; double d = FLT_MAX; for (i = 0;i < (int)p.size(); i++) for (j = i + 1; j < (int)p.size(); j++) d = std::min(d, dist(p[i], p[j])); return d; }
int main(){ int N, n_ind, t, combs, n_morto; point input; double p_killed; cin >> t; while(t--){ cin >> n_ind; N = n_ind; combs = (N*(N-1)*(N-2))/6; positions.clear(); while(n_ind--){ cin >> input.x >> input.y; positions.push_back(input); } n_morto = 0; for(vp::iterator ii = positions.begin(); ii != positions.end(); ++ii){ for(vp::iterator jj = ii+1; jj != positions.end(); ++jj){ for(vp::iterator kk = jj+1; kk != positions.end(); ++kk){ n_morto += calc_morto(ii,jj,kk); } } } p_killed = ((double)n_morto)/(combs * ((positions.size()-3))); cout << setprecision(8) << p_killed << "\n"; } }
void printVP(vp p){ int size = p.size(); for (int i=0; i<size; i++) { cout << "(" << p[i].first << "," << p[i].second<< ")"; } cout << endl; }
vp convex_hull(vp P) { int n = P.size(), k = 0; vp H(2*n); sort(P.begin(), P.end()); for (int i = 0; i < n; i++) { while (k >= 2 && cross(H[k-2], H[k-1], P[i]) <= 0) k--; H[k++] = P[i]; } for (int i = n - 2, t = k + 1; i >= 0; i--) { while (k >= t && cross(H[k-2], H[k-1], P[i]) <= 0) k--; H[k++] = P[i]; } H.resize(k); return H; }
int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> N; for (int i = 1; i <= N; i++) { point temp; cin >> temp.x >> temp.y; P.push_back(temp); } point temp; temp.x = 0; temp.y = 0; P.push_back(temp); result = convex_hull(P); cout << result.size() - 1; return 0; }
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); }
void dfs(vp p){ if(p.size()==4){ int wid, len; wid = get_sum(p,0,3,0); len = get_max(p,0,3,1); ans.push_back( pii(wid, len) ); //2 wid = max(get_sum(p,0,2,0), p[3].first); len = get_max(p,0,2,1)+p[3].second; ans.push_back( pii(wid, len) ); //3 wid = get_sum(p,0,2,0); wid = max(wid, p[3].first+p[2].first); len = max(get_max(p,0,1,1)+p[3].second,p[2].second); ans.push_back( pii(wid, len) ); //4 wid = p[0].first+ max(p[1].first,p[2].first) +p[3].first; len = max(max(p[0].second, (p[1].second+p[2].second)), p[3].second); ans.push_back( pii(wid, len) ); //6... wid = p[0].first+p[1].first; len = max(p[0].second+p[2].second, p[1].second+p[3].second ); if( p[0].second<p[1].second){ wid = max(wid, p[2].first+p[1].first); } if( p[2].second+p[0].second > p[1].second){ wid = max(wid, p[3].first+p[2].first); } if( p[1].second < p[0].second){ wid = max(wid, p[0].first+p[3].first); } wid = max(p[2].first, max(p[3].first,wid) ); if(wid*len==480){ cout<<"now vector is "<<endl; for(int i=0; i<4; i++){ cout<<p[i].first<<" "<<p[i].second<<endl; } cout<<"and the wid, len is "<<wid<<" "<<len<<endl; } ans.push_back( pii(wid, len) ); return; } for(int i=0; i<4; i++){ if(!used[i]){ used[i] = true; vp np = p; np.push_back(rec[i]); dfs(np); used[i] = false; used[i] = true; int first = rec[i].second; int second = rec[i].first; np = p; np.push_back(pii(first, second) ); dfs( np ); used[i] = false; } } }
size_t size() const { return points_.size(); }
int solve(vp &v){ int r=0,i=0; for(;i<v.size()-1;i++)r+=min(v[i+1].first,v[i].second)-v[i].first; return r+v[i].second-v[i].first; }