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


C++ VPII::push_back方法代码示例

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


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

示例1: LongestIncreasingSubsequence

VI LongestIncreasingSubsequence(VI v)
{
    VPII best;
    VI dad(v.size(), -1);

    for (int i = 0; i < v.size(); i++)
    {
#ifdef STRICTLY_INCREASNG
        PII item = make_pair(v[i], 0);
        VPII::iterator it = lower_bound(best.begin(), best.end(), item);
        item.second = i;
#else
        PII item = make_pair(v[i], i);
        VPII::iterator it = upper_bound(best.begin(), best.end(), item);
#endif
        if (it == best.end())
        {
            dad[i] = (best.size() == 0 ? -1 : best.back().second);
            best.push_back(item);
        }
        else
        {
            dad[i] = dad[it->second];
            *it = item;
        }
    }

    VI ret;
    for (int i = best.back().second; i >= 0; i = dad[i])
        ret.push_back(v[i]);
    reverse(ret.begin(), ret.end());
    return ret;
}
开发者ID:GENTLEMAN009,项目名称:Algorithm,代码行数:33,代码来源:LIS(stanford).cpp

示例2: path

VPII path(const PII& a, const PII& b, const VPII& w, int u) {
    int i, t, k = 1, p = -1;
    VPII ret;
    // printf("[path] w.size() = %d\n", (int)w.size());
    for (i = 1; i < (int)w.size(); ++i) {
        t = intersection(a, b, w[i - 1], w[i]);
        if (t != -1 && (p == -1 || p > t)) {
            p = t;
            k = i;
        }
    }
    if (p != -1) {
        ret.push_back(point(a, b, p - u));
        if ((w[k - 1].first == w[k].first && w[k].first == ret.back().first) ||
            (w[k - 1].second == w[k].second && w[k].second == ret.back().second)) {
            ++k;
        }
        // printf("k = %d\n", k);
        for (i = k ; i < (int)w.size(); ++i) {
            ret.push_back(ret.back());
            if (i + 1 < (int)w.size() && sameside(w[i - 1], w[i], ret.back(), w[i + 1])) {
                if (w[i - 1].first == w[i].first) {
                    ret.back().second = w[i].second - sign(w[i].second - w[i - 1].second) * u;
                } else {
                    ret.back().first = w[i].first - sign(w[i].first - w[i - 1].first) * u;
                }
            } else {
                if (w[i - 1].first == w[i].first) {
                    ret.back().second = w[i].second + sign(w[i].second - w[i - 1].second) * u;
                } else {
                    ret.back().first = w[i].first + sign(w[i].first - w[i - 1].first) * u;
                }
            }
        }
    }
    return ret;
}
开发者ID:Crmiv,项目名称:AlgoSolution,代码行数:37,代码来源:2696.cpp

示例3: trim

VPII trim(const VPII& v) {
    VPII ret;
    for (int i = 0; i < (int)v.size(); ++i) {
        if (ret.size() > 1) {
            if (ret.back().first == v[i].first && ret.back().first == (ret.end() - 2)->first) {
                ret.pop_back();
            } else if (ret.back().second == v[i].second && ret.back().second == (ret.end() - 2)->second) {
                ret.pop_back();
            }
        }
        if (ret.empty() || v[i] != ret.back()) {
            ret.push_back(v[i]);
        }
    }
    return ret;
}
开发者ID:Crmiv,项目名称:AlgoSolution,代码行数:16,代码来源:2696.cpp

示例4: main

int main() {
	LL tot = 1;
	LL n, m;

	cin >> n;
	for (int i=0; i<2*n; ++i) {
		int a;
		cin >> a;
		x.push_back(MP(a, i%n));
	}
	sort(x.begin(), x.end());
	cin >> m;
	init(2*n+10, m);
	for (int i=0,j=0,sz=(int)x.size(); i<sz; i=j) {
		int p2 = 0;
		for (j=i; j<sz&&x[j].first==x[i].first; ++j) p2 += (j + 1 < sz && x[j+1] == x[j]);
//		cout << x[i].first << ' ' << j - i << ' ' << p2 << ' ' << r[j-i] << ' ' << cc[j-i] << endl;
		tot = (tot * r[j-i] % m) * P(2, cc[j-i]-p2, m) % m;
	}
	cout << tot << endl;

	return 0;
}
开发者ID:delta4d,项目名称:AlgoSolution,代码行数:23,代码来源:D.cpp

示例5: main

int main()
{
    srand(time(NULL));
    FastIO(); 
    
    // Keeps track of all elements in kd-tree 
    VPII vec;
    kdtree *rootaddr = NULL;
    int n, p_x, p_y;
    n = 100;
    for(int i = 0 ; i < n ; i++) {
        p_x = rand() % 1000;
        p_y = rand() % 1000;
        vec.push_back(make_pair(p_x, p_y));
    }
    rootaddr = static_build(rootaddr, vec, 0, 0, n - 1);

    // Uncomment the below part to print the kd-tree (preorder traversal)
    /*
       cout << "tree traversal\n";
       print(rootaddr, 0, 'a');
    */
    return 0;
}
开发者ID:pranjal-rai,项目名称:kd-tree,代码行数:24,代码来源:kdtree_static.cpp

示例6: main

int main()
{
	int tc;
	scanf("%d",&tc);
	while (tc--)
	{
		int m, n;
		scanf("%d %d",&m, &n);
		VPII segm;
		for(int i=0;i<n;i++)
		{
			int st, en;
			scanf("%d %d",&st, &en);
			if(st<=en)
			{
				segm.push_back(make_pair(st,en));
				segm.push_back(make_pair(st+m,en+m));
			}
			else
				segm.push_back(make_pair(st,en+m));
		}

		printVector(segm);


		if(n>m)
		{
			puts("NO");
			continue;
		}
		sort(segm.begin(),segm.end());

		cout << "After Sorting " << endl;

		printVector(segm);

		int T=0;
		int i=0;
		set < PII > que;
		bool ok = true;
		while(true)
		{
			if(que.empty())
			{
				if(i==segm.size())
					break;
				else
					T = segm[i].first;
			}

			while(i<segm.size() && segm[i].first==T)
			{
				que.insert(make_pair(segm[i].second,i));
				i++;
			}

			int ind = que.begin()->second;
			que.erase(que.begin());

			if(!(T>=segm[ind].first && T<=segm[ind].second))
			{
				ok = false;
				break;
			}
			T++;
		}
		puts(ok?"YES":"NO");
	}
}
开发者ID:varenya,项目名称:algorithms,代码行数:69,代码来源:littlejhool.cpp

示例7: main

int main()
{
	FILE *fin = freopen("graph.in","r",stdin);
	FILE *fout = freopen("graph.out","w",stdout);
	memset(indegree, 0, sizeof(indegree));
	int m;
	cin>>n>>m>>k;
	for(int i=0; i<m; i++)
	{
		int u,v;
		cin>>u>>v;
		if(V[u].find(v)==V[u].end())
		{
			V[u].insert(v);
			indegree[v]++;
		}
	}
	for(int i=1; i<=n; i++)
	{
		if(indegree[i]==0)
			poss.insert(i);
	}
	priority_queue <int> deferred;
	bool first=false;
	int printed = 0;
	int cur = 0;
	while(printed<n)
	{
		if(!poss.empty())
		{
			int num_links = min(k,(int)poss.size()-1);
			if(num_links!=0)
			{
				k-=num_links;
				auto endpos = poss.begin();
				for(int j=0; j<num_links-1; j++) endpos++;
				for(auto it=endpos; ; it--)
				{
					deferred.push(*it);
					if(it==poss.begin())
						break;
				}
				poss.erase(poss.begin(), ++endpos);
			}
			if(k>0 && !deferred.empty() && deferred.top() > *poss.rbegin())
			{
				//trace(*poss.rbegin());
				deferred.push(*poss.rbegin());
				poss.erase(--poss.end());
				k--;
			}
		}
		if(poss.empty() && !deferred.empty())
		{
			int defcur = deferred.top();
			deferred.pop();
			V[cur].insert(defcur);
			ans.push_back(make_pair(cur, defcur));
			poss.insert(defcur);
		}

		if(first)
		{
			cout<<" ";
		}
		first=true;
		cur = *(poss.begin());
		poss.erase(poss.begin());
		cout<<cur;
		printed++;
		for(auto it = V[cur].begin(); it!=V[cur].end(); it++)
		{
			indegree[*it]--;
			if(indegree[*it]==0)
			{
				poss.insert(*it);
			}
		}
	}
	cout<<endl;
	cout<<ans.size()<<endl;
	for(int i=0; i<ans.size(); i++)
	{
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}
	return 0;	
}
开发者ID:KamikazeCJJ,项目名称:Heuristics-CodeForces-GYM,代码行数:87,代码来源:G.cpp

示例8: main

int main()
{
    freopen("Text/QCJ1.txt","r",stdin);

    int i = 0, h, w = 0, prevv=-2, tot=0, steps=0, len;
	VPII walk;
	while(gets(board[i])) i++;
	h = i-1;
	len = strlen(board[i-1]);
	while(w<len)
	{
		if(board[h][w]=='/')
		{
			if(prevv!=1)
			{
				walk.push_back(pair<char,int>(prevv,steps));
				steps = 0;
			}
			steps++;
			prevv = 1;
			w++;
			tot++;
		}
		else if(board[h][w]=='_')
		{
			if(prevv!=0)
			{
				walk.push_back(pair<char,int>(prevv,steps));
				steps = 0;
			}
			steps++;
			prevv = 0;
			w++;
			tot++;
		}
		else if(board[h][w]=='\\')
		{
			if(prevv!=-1)
			{
				walk.push_back(pair<char,int>(prevv,steps));
				steps = 0;
			}
			steps++;
			prevv = -1;
			w++;
			tot++;
		}
		else
		{
			if(prevv==-1)
			{
				if(h == i) break;
				else h++;
			}
			else if(prevv==0)
			{
				h++;
			}
			else if(prevv==1)
			{
				h--;
			}
		}
	}
	walk.push_back(pair<char,int>(prevv,steps));
	printf("Total Walk Distance = %d\n", tot);
	for(i=0; i<walk.size(); i++)
	{
		if(walk[i].first==-1) printf("Down %d steps\n", walk[i].second);
		else if(walk[i].first==0) printf("Walk %d steps\n", walk[i].second);
		else if(walk[i].first==1) printf("Up %d steps\n", walk[i].second);
	}

    return 0;
}
开发者ID:vijaynitrr,项目名称:Spoj,代码行数:75,代码来源:QCJ1.cpp


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