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 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); }
int calc_morto(vp::iterator ia, vp::iterator ib, vp::iterator ic){ point a,b,c, p; a = *ia; b = *ib; c = *ic; // Ve se sao colineares int A = abs(( ( ( a.x*b.y ) + ( a.y*c.x ) + ( b.x*c.y ) ) - ( (b.y*c.x) + (c.y*a.x) + (b.x*a.y) ) )); if(A == 0) return 0; // Encontrando retas line ma, mb; ma.m = ((double)(b.x-a.x))/((a.y-b.y)); mb.m = ((double)(c.x-b.x))/((b.y-c.y)); ma.q = ((a.y+b.y)-ma.m*(a.x+b.x)); mb.q = ((b.y+c.y)-mb.m*(b.x+c.x)); double Cx, Cy; // Na verdade é dividido por 2, mas assim diminui uma operacao Cx = (ma.m*(a.x+b.x)-mb.m*(b.x+c.x)+c.y-a.y)/(ma.m-mb.m); Cy = ma.m*Cx+ma.q; if(a.x == b.x) Cy = (a.y+b.y); else if(b.x == c.x) Cy = (b.y+c.y); if(a.y == b.y) Cx = (a.x+b.x); else if(b.y == c.y) Cx = (b.x+c.x); double R = ((Cx - a.x)*(Cx - a.x))+((Cy - a.y)*(Cy - a.y)); int kills = 0; for(vp::iterator ii = positions.begin(); ii != positions.end(); ++ii){ if(ii != ia && ii != ib && ii != ic){ p = *ii; // if(((Cx - p.x)*(Cx - p.x))+((Cy - p.y)*(Cy - p.y)) <= R) kills++; // Original (tirei o 2 p compensar o 2 tirado dos Cx, Cy: if(((p.x*p.x)-(a.x*a.x)+(p.y*p.y)-(a.y*a.y)) <= 2*( (Cx*(p.x-a.x))+(Cy*(p.y-a.y)) )) kills++; if(( (Cx*(p.x-a.x))+(Cy*(p.y-a.y)) ) >= ((p.x*p.x)-(a.x*a.x)+(p.y*p.y)-(a.y*a.y))) kills++; // teste maluco de int com double } } return kills; }
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; }