当前位置: 首页>>代码示例>>C++>>正文


C++ vp类代码示例

本文整理汇总了C++中vp的典型用法代码示例。如果您正苦于以下问题:C++ vp类的具体用法?C++ vp怎么用?C++ vp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了vp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: bruteforce

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;
}
开发者ID:jcarreira,项目名称:Algorithms,代码行数:9,代码来源:test_closestpair.cpp

示例2: calc_morto

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;
}
开发者ID:caioaao,项目名称:cp-solutions,代码行数:48,代码来源:cirkill_crazy.cpp

示例3: printVP

void printVP(vp p){
    int size = p.size();
    for (int i=0; i<size; i++) {
        cout << "(" << p[i].first << ","  << p[i].second<< ")";
    }
    cout << endl;
}
开发者ID:jasoncho1021,项目名称:codejam,代码行数:7,代码来源:picnic.cpp

示例4: main

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";

	}
}
开发者ID:caioaao,项目名称:cp-solutions,代码行数:35,代码来源:cirkill_crazy.cpp

示例5: convex_hull

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;
}
开发者ID:hdi-superuser,项目名称:trainning,代码行数:18,代码来源:main.cpp

示例6: dfs

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;
        }
    } 
}
开发者ID:1code,项目名称:algorithm-oeddyo,代码行数:62,代码来源:packrec.cpp

示例7: andrewScan

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]);
}
开发者ID:Harshit44,项目名称:spoj,代码行数:27,代码来源:DOORSPEN.cpp

示例8: solve

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;
}
开发者ID:AbhiNki,项目名称:procon,代码行数:5,代码来源:tyama_imos0028.cpp

示例9:

	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]);
	}
开发者ID:teamurko,项目名称:Kharkov-summer-school,代码行数:11,代码来源:genRand.cpp

示例10: main

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;
}
开发者ID:hdi-superuser,项目名称:trainning,代码行数:20,代码来源:main.cpp

示例11: getInput

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));
    }
开发者ID:mgavin,项目名称:acm-code,代码行数:12,代码来源:10245_cp.cpp

示例12: main

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;
}
开发者ID:MarkGalloway,项目名称:uva_judge,代码行数:35,代码来源:UVa10065.C

示例13: main

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;
}
开发者ID:Harshit44,项目名称:spoj,代码行数:58,代码来源:DOORSPEN.cpp

示例14: size

 size_t size() const {
   return points_.size();
 }
开发者ID:c-a,项目名称:Impa,代码行数:3,代码来源:geometry.cpp

示例15: add_point

 void add_point(const Point& p) {
   points_.push_back(p);
 }
开发者ID:c-a,项目名称:Impa,代码行数:3,代码来源:geometry.cpp


注:本文中的vp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。