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


C++ multiset类代码示例

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


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

示例1: PerformInsert

/* Function: PerformInsert(int value,
 *                         multiset<int>& minSet,
 *                         multiset<int>& maxSet)
 * Usage: bool success = PerformInsert(value, minSet, maxSet);
 * -----------------------------------------------------------------------------
 * Inserts one instance of the specified value into the minset or the maxset, 
 * according to the following logic: if the value exceeds the current maximum 
 * value in the minset, then add the value to the maxset; otherwise, add the 
 * value to the minset. The function returns true if the insert operation was 
 * successful, and false otherwise.
 */
bool PerformInsert(int value, multiset<int>& minSet, multiset<int>& maxSet)
{
  if (minSet.empty() || value <= *FindMaxElement(minSet))
    minSet.insert(value);
  else
    maxSet.insert(value);
  
  /* Always return true. */
  return true;
}
开发者ID:cmslewis,项目名称:InterviewStreet-Puzzles,代码行数:21,代码来源:median.cpp

示例2: getNodeFromSet

Node AStar::getNodeFromSet( multiset<Node> l,Node n){

    multiset<Node> ::iterator it;
    for(it = l.begin();it!=l.end();it++){
        if(n.id == (*it).id){
            return *it;
        }

    }
}
开发者ID:nileshkulkarni,项目名称:AI_lab,代码行数:10,代码来源:Astar.cpp

示例3: cut

void inline cut(set<int> &s, multiset<int> &ss, int t) {
    s.insert(t);
    auto l = s.find(t), r = l;
    --l, ++r;
    int cur = *r - *l;
    //cout<<"cur: "<<cur<<endl;
    ss.erase(ss.find(cur));
    ss.insert(*r - t);
    ss.insert(t - *l);
}
开发者ID:TaoSama,项目名称:ICPC-Code-Library,代码行数:10,代码来源:C.cpp

示例4: main

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while(t--){
    S.clear();
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> x;
      it = S.upper_bound(x);
      if(it==S.end()){
        S.insert(x);
      }
      else{
        S.erase(it);
        S.insert(x);
        //(*it) = x;
      }
    }
    cout << S.size() << " ";
    for(multiset<int>::iterator it=S.begin();it!=S.end();it++){
      cout << (*it)  << " ";
    }
    cout << endl;
  }
  return 0;
}
开发者ID:anveshi,项目名称:Competitive-Programming,代码行数:27,代码来源:STACKS-8215643.cpp

示例5: FindNode

multiset<Node,NodeCompare>::iterator FindNode(const multiset<Node, NodeCompare>& nodes, int i, int j)
{
   for (set<Node, NodeCompare>::iterator it = nodes.begin(); it != nodes.end(); ++it)
   {
      if (it->x == i && it->y == j) 
      { 
         return it;
      }
   }
   return nodes.end(); 
}
开发者ID:nkersting,项目名称:Code,代码行数:11,代码来源:dijkstra-set.cpp

示例6: findInSet

bool AStar::findInSet( multiset<Node> l,Node n){

    multiset<Node> ::iterator it;
    for(it = l.begin();it!=l.end();it++){
        if(n.id == (*it).id){
            return true;
        }

    }

    return false;
}
开发者ID:nileshkulkarni,项目名称:AI_lab,代码行数:12,代码来源:Astar.cpp

示例7: main

int main() {
	multiset<int>::iterator it;
	while (scanf("%d", &n) != EOF) {
		while (!S.empty())
			S.pop();
		lef.clear();
		righ.clear();
		for (int i = 0; i < n; ++i) {
			scanf("%s", buf);
			if (strcmp(buf, "Pop") == 0) {
				if (S.empty()) {
					printf("Invalid\n");
					continue;
				}
				int u = S.top();
				S.pop();
				if (u <= med) {
					it = lef.find(u);
					lef.erase(it);

				}
				else {
					it = righ.find(u);
					righ.erase(it);
				}
				adjust();
				printf("%d\n", u);
			}
			else if (strcmp(buf, "PeekMedian") == 0) {
				if (S.empty()) {
					printf("Invalid\n");
					continue;
				}
				printf("%d\n", med);
			}
			else if (strcmp(buf, "Push") == 0) {
				int u;
				scanf("%d", &u);
				if (S.empty()) {
					med = u;
					lef.insert(u);
					
				}
				else if (u > med) {
					righ.insert(u);
				}
				else {
					lef.insert(u);
				}
				S.push(u);
				adjust();
			}
			else
				printf("Invalid\n");
		}
	}
	return 0;
}
开发者ID:CQUT,项目名称:Algorithm-Collection,代码行数:58,代码来源:pat1057.cpp

示例8: main

int main()
{
    //freopen("I.in","r",stdin);
    //freopen("I.out","w",stdout);
    int T;
    scanf("%d", &T);
    for(int cas=1;cas<=T;cas++)
    {
        mst.clear();
        int n, m, k, cnt = 0;
        long long  num;
        scanf("%d%d%d", &n, &m, &k);
        for(int i = 0; i < n; ++i)
        {
            scanf("%lld", &num);
            if(num <= k)
            {
                mst.insert(num);
            }
        }
        while(true)
        {
            int sz = mst.size();
            if(sz < 2)
                break;
            it1 = mst.end();
            it1--;
            long long  fst = *it1;
            mst.erase(it1);
            it2 = mst.lower_bound(min(fst, k - fst));
            if(it2 == mst.end())
                it2--;
            if(it2 == mst.begin() && *it2 > (k - fst))
                continue;
            if(*it2 <= k - fst)
            {
                ans[cnt++] = fst * ( *it2);
                mst.erase(it2);
            }
            else
            {
                it2 --;
                ans[cnt++] = fst * (*it2);
                mst.erase(it2);
            }
        }
        sort(ans, ans + cnt, cmp);
        long long  res = 0;
        for(int i = 0; i < min(m, cnt); ++i)
        {
            res += ans[i];
        }
        printf("CASE #%d: %lld\n",cas,res);
    }
    return 0;
}
开发者ID:JS00000,项目名称:acmCode,代码行数:56,代码来源:I1.cpp

示例9: main

int main(){
  int n;rit(n);
  for(int l,r;n;--n){
    rit(l,r);
    auto it=st.upper_bound(r);
    if(it!=st.end())st.erase(it);
    st.insert(l);
  }
  printf("%d\n",st.size());
}
开发者ID:edisonhello,项目名称:cpp,代码行数:10,代码来源:1941.cpp

示例10: update

	int update(int x){
		int u=V.back();
		int p=fa[u];
		if (p) D[p].erase(D[p].find(faW[u]+tree[0].mxR));
		ans.erase(ans.find(tree[0].mx));
		update_tree(0,n-1,at[x],0);
		ans.insert(tree[0].mx);
		if (p) D[p].insert(faW[u]+tree[0].mxR);
		return p;
	}
开发者ID:CoderINusE,项目名称:bcw_codebook,代码行数:10,代码来源:QTREE4.cpp

示例11: pushup

		void pushup() {
			if (this == EMPTY)	return ;
			mxv = val;
			if (s.size())
				mxv = max(mxv, *s.rbegin());
			if (ch[0] != EMPTY)
				mxv = max(mxv, ch[0]->mxv);
			if (ch[1] != EMPTY)
				mxv = max(mxv, ch[1]->mxv);
		}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:10,代码来源:SPOJ+-+QTREE7+-+Query+on+a+tree+VII.cpp

示例12: scan

void scan(int i, int n, int k, ll sum){
    if(i>k){
        mys.erase(mys.find(sum));
        return;
    }
    for(int j=pos[i-1]; j<=n; ++j){
        pos[i]=j;
        scan(i+1,n,k,sum+a[j]);
    }
}
开发者ID:hdi-superuser,项目名称:Codes,代码行数:10,代码来源:repeat-k-sums.cpp

示例13: main

int main()
{
    int n,d,r;
    while(scanf("%d%d%d",&n,&d,&r)!=EOF&&n||d||r)
    {
        int k;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&k);
            s1.insert(k);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&k);
            s2.insert(k);
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            int num=*s1.begin();
            int index=d-num;
            __typeof(s2.begin()) it=s2.lower_bound(index);
            if(it==s2.end())it--;
            ans+=r*max(0,num+*it-d);
            s1.erase(s1.begin());
            s2.erase(it);
        }
        printf("%d\n",ans);
    }
    return 0;
}
开发者ID:EternalZEROm,项目名称:ZEROm,代码行数:31,代码来源:11389.cpp

示例14: main

int main()
{
    int n, m, a;

    while ( scanf("%d", &n), n )
    {
        long long ans = 0LL;
        urn.clear();
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &m);
            for (int j = 0; j < m; j++)
            {
                scanf("%d", &a);
                urn.insert( a );
            }
            ans += *urn.rbegin() - *urn.begin();
            urn.erase( urn.begin() );
            urn.erase( urn.find(*urn.rbegin()) );
        }
        printf("%lld\n", ans);
    }

    return 0;
}
开发者ID:AOQNRMGYXLMV,项目名称:pcuva-problems,代码行数:25,代码来源:sol.cpp

示例15: main

int main()
{
    srand(time(NULL));
    for(int i=6; i<21; ++i) {
        char fin[55],out[55];
        sprintf(fin,"teste/grader_test%d.in",i);
        sprintf(out,"teste/grader_test%d.ok",i);
        ofstream in(fin);
        ofstream g(out);
        n=rand()%DN+1;k=rand()%n+1;
        in<<n<<' '<<k<<'\n';
        for(int i=1; i<=n; ++i) {
            p[i]=rand()%DK+1; c[i]=rand()%DK+1;
            in<<p[i]<<' '<<c[i]<<'\n';
        }
        pt=0; rst.clear(); sol.clear(); ssol=0; rez=0;
        for(int i=1; i<=k; ++i) {
            pt+=p[i];
            rst.insert(p[i]+c[i]);
        }
        rez=max(rez,pt);
        for(int i=k+1; i<=n; ++i) {
            pt+=p[i];
            rst.insert(p[i]+c[i]);
            ssol+=*rst.begin();
            sol.insert(*rst.begin());
            rst.erase(rst.begin());
            bst[i]=pt-ssol;
            rez=max(rez,bst[i]);
        }
        g<<rez;
    }
    return 0;
}
开发者ID:S7012MY,项目名称:Surse,代码行数:34,代码来源:creator_teste.cpp


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