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


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

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


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

示例3: printVector

void printVector(VPII segm){

		cout << " print vector : " << endl;

		for(int i=0;i<segm.size();i++){

			cout << segm[i].first << " " << segm[i].second << " " << endl;

		}
}
开发者ID:varenya,项目名称:algorithms,代码行数:10,代码来源:littlejhool.cpp

示例4: merge

void merge(VPII& ar){
    VPII ret;
    ret.pb(ar[0]);
    for(int i=1; i<ar.size(); i++){
        assert(ar[i].F);
        if(ar[i].S==ret.back().S)
            ret.back().F+=ar[i].F;
        else
            ret.pb(ar[i]);
    }
    ar=ret;
}
开发者ID:KamikazeCJJ,项目名称:Heuristics-CodeForces-GYM,代码行数:12,代码来源:je.cpp

示例5: back

void back(int mask){
    if(printed)return;
    VPII cpy=ar;
    int topleft, p=ar.size(), maxh=0, dist=0;
    for(int i=0; i<p; i++){
        if(ar[i].S>maxh)
            maxh=ar[i].S, topleft=i;
    }
    for(int i=0; i<topleft; i++)
        dist += ar[i].F;

    if(maxh==0){
        if(mask==(1<<N)-1)
            print();
        return ;
    }


    for(int i=0; i<N; i++)
        if(not (mask&(1<<i))){
            if(ar[topleft].F>=rect[i].F and ar[topleft].S>=rect[i].S){
                ans.pb(node(dist, ar[topleft].S-rect[i].S, dist + rect[i].F, ar[topleft].S));
                int oldwidth = ar[topleft].F;
                ar[topleft].F = rect[i].F;
                ar[topleft].S -= rect[i].S;
                if(oldwidth!=rect[i].F)
                    ar.insert(ar.begin() + topleft + 1, {oldwidth-rect[i].F, maxh});

                merge(ar);
                back(mask|(1<<i));
                ans.pop_back();
                ar = cpy;
            }
            swap(rect[i].F, rect[i].S);
            if(ar[topleft].F>=rect[i].F and ar[topleft].S>=rect[i].S){

                ans.pb(node(dist, ar[topleft].S-rect[i].S, dist + rect[i].F, ar[topleft].S));
                int oldwidth = ar[topleft].F;
                ar[topleft].F = rect[i].F;
                ar[topleft].S -= rect[i].S;
                if(oldwidth!=rect[i].F)
                    ar.insert(ar.begin() + topleft + 1, {oldwidth-rect[i].F, maxh});

                merge(ar);
                back(mask|(1<<i));
                ans.pop_back();
                ar = cpy;
            }
            swap(rect[i].F, rect[i].S);
        }
}
开发者ID:KamikazeCJJ,项目名称:Heuristics-CodeForces-GYM,代码行数:51,代码来源:je.cpp

示例6: gao

VPII gao(const VPII& v, const VPII& w, int u) {
    int i, j;
    VPII p, q, r;
    for (i = 1; i < (int)v.size() && p.empty(); ++i) {
    //  printf("i = %d\n", i);
        p = path(v[i - 1], v[i], w, u);
    }
    if (p.empty()) {
        return v;
    }
    for (j = (int)v.size() - 2; j >= 0 && q.empty(); --j) {
    //  printf("j = %d\n", j);
        q = path(v[j + 1], v[j], w, u);
    }
    --i;
    ++j;
    // printf("i = %d; j = %d\n", i, j);
    r.insert(r.end(), v.begin(), v.begin() + i);
    r.insert(r.end(), p.begin(), p.end());
    r.insert(r.end(), q.rbegin(), q.rend());
    r.insert(r.end(), v.begin() + j + 1, v.end());
    return trim(r);
}
开发者ID:Crmiv,项目名称:AlgoSolution,代码行数:23,代码来源:2696.cpp

示例7: 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

示例8: main

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,var,i,l,flag,d,j;
    vector <VI> v(100010);
    VPII vec;
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>var;
        v[var].PB(i);
    }
    for(i=1;i<=100000;i++)
    {
        l=v[i].size();
        if(l==0)
            continue;
        if(l==1)
        {
            vec.PB(MP(i,0));
            continue;
        }
        if(l==2)
        {
            vec.PB(MP(i,v[i][1]-v[i][0]));
            continue;
        }
        flag=1;
        d=v[i][1]-v[i][0];
        for(j=2;j<l;j++)
        {
            if(v[i][j]-v[i][j-1]!=d)
                flag=0;
        }
        if(flag==0)
            continue;
        else
            vec.PB(MP(i,d));
    }
    l=vec.size();
    cout <<l<<"\n";
    for(i=0;i<l;i++)
        cout <<vec[i].F<<" "<<vec[i].S<<"\n";
    return 0;
}
开发者ID:pranjal-rai,项目名称:codeforces,代码行数:46,代码来源:p2.cpp

示例9: main

int main(){
	VPII v;
	v.clear();
	LL n,i,j,x,y;
	cin >> n;
	pair <LL,LL> p[100005];
	for(i=0;i<n;i++){
		cin >> p[i].ff >> p[i].ss;
	}
	sort(p,p+n);
//	for(i=0;i<n;i++)
//		trace2(p[i].ff,p[i].ss);
	for(i=0;i<n;i++){
		x = p[i].ff;y=p[i].ss;
		if(i==n-1)
			v.pb(mp(x+y,x));
		else{
			if(p[i+1].ff>x+y)
				v.pb(mp(x+y,x));
		}
		if(i==0)
			v.pb(mp(x,x-y));
		else{
			if(p[i-1].ff<x-y)
				v.pb(mp(x,x-y));
		}
	}
	sort(v.begin(),v.end());
	LL ans=0,lf=-MOD;
	int sz = v.size();
	for(i=0;i<sz;i++){
		//trace2(v[i].first,v[i].second);
		//trace2(lf,v[i].second);
		if(v[i].second>lf){ans++;
			lf = v[i].first;
		//	trace2(v[i].second,v[i].first);
		}
	}
	cout << ans << endl;
	return 0;
}
开发者ID:anveshi,项目名称:Competitive-Programming,代码行数:41,代码来源:545-C-11161476.cpp

示例10: check

bool check(string word){
    int A = 0;
    int B = 0;
    int n = word.length();

    VPII arches ;
    int lastA = -1;
    int lastB = -1;
    REP(i, n){
        if(word[i] == 'A'){
            A++;
            if(lastA == -1){
                lastA = i;
            } else {
                arches.pb(mp(lastA, i));
                lastA = -1;
            }
        } else {
            B++;
            if(lastB == -1){
                lastB = i;
            } else {
                arches.pb(mp(lastB, i));
                lastB = -1;
            }
        }
    }
    if(A%2 || B%2){
        return false;
    }

    for(int i = 1; i< arches.size(); i++){
        if(overlap(arches[i-1], arches[i])){
            return false;
        }
    }

    return true;
}
开发者ID:bristy,项目名称:HackYourself,代码行数:39,代码来源:arches_new.cpp

示例11: 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

示例12: 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

示例13: 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

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