Пример #1
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;
}
Пример #2
0
	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]);
	}
Пример #3
0
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;
}
Пример #4
0
void printVP(vp p){
    int size = p.size();
    for (int i=0; i<size; i++) {
        cout << "(" << p[i].first << ","  << p[i].second<< ")";
    }
    cout << endl;
}
Пример #5
0
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";

	}
}
Пример #6
0
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;
}
Пример #7
0
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;
}
Пример #8
0
bool getInput()
{
    //get input
    int np;
    scanf("%d ", &np);
    if (fabs(0 - np) < EPS) return false;
    double x, y;
    REP(i, np)
    {
        scanf("%lf %lf ", &x, &y);
        points.push_back(point(x, y));
    }
Пример #9
0
int main() {
  int n, cases=0;
  while(1) {
    cin >> n;

    // End of cases
    if(n == 0) break;

    // Init
    points.clear();
    int x, y;

    // Read in points
    for (int i = 0; i < n; ++i) {
      cin >> x >> y;
      points.push_back(point(x,y));
    }

    double convex_hull_area = area(CH(points));

    // Complete the polygon, if necessary
    if(!(points.back() == points.front()))
      points.push_back(points.front());

    double total_area = area(points);

    double percent_diff = (convex_hull_area - total_area) / convex_hull_area * 100;

    cout << "Tile #" << ++cases << endl;
    cout << "Wasted Space = " << setprecision(2) << fixed << percent_diff << " " << '%' << endl << endl;

  }

  return 0;
}
Пример #10
0
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;
}
Пример #11
0
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;
        }
    } 
}
Пример #12
0
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]);
}
Пример #13
0
 size_t size() const {
   return points_.size();
 }
Пример #14
0
 void add_point(const Point& p) {
   points_.push_back(p);
 }
Пример #15
0
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;
}
Пример #16
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);
}