本文整理汇总了C++中multiset类的典型用法代码示例。如果您正苦于以下问题:C++ multiset类的具体用法?C++ multiset怎么用?C++ multiset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了multiset类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: debug
void debug()
{
multiset<pair<int,int> > ::iterator it;
puts("- - - - - - - - - -debug begin-- - - - - - - - - - - - ");
for(it=apple.begin();it!=apple.end();++it)
{
cout<<(*it).first<<" "<<(*it).second<<endl;
}
puts("- - - - - - - - - -debug end-- - - - - - - - - - - - ");
}
开发者ID:ASIAH304,项目名称:ACM-ICPC,代码行数:13,代码来源:main.cpp
示例9: getMinimumNode
Node AStar::getMinimumNode( multiset<Node> l){
if(l.size()>=1){
multiset<Node>::iterator it = l.begin();
#if DEBUG
printf("Minimum f_score node is %lld \n", (*it).id);
#endif
return *it;
}
else{
printf("Set is empty, no nodes left to expand");
//exit(0);
}
}
开发者ID:nileshkulkarni,项目名称:AI_lab,代码行数:13,代码来源:Astar.cpp
示例10: is_BiASGS_goal
bool TSP::is_BiASGS_goal( const search_node& s, const multiset<search_node, less<search_node> >& frontier )
{
multiset<search_node>::iterator it;
for ( it = frontier.begin(); it != frontier.end(); it++ )
{
if ( s.get_state() == (*it).get_state() )
{
return true;
}
}
return false;
}
开发者ID:umairsajid,项目名称:my-random-cpp-libraries,代码行数:13,代码来源:TSP.cpp
示例11: Greedy01
double Greedy01(const multiset<Elemento> & objetos, const double pesoM){
double pesoact = 0, beneficio = 0;
multiset<Elemento>::const_reverse_iterator it;
for(it = objetos.rbegin(); it != objetos.rend() && pesoact < pesoM; ++it)
if((pesoact + (*it).peso) <= pesoM){
beneficio += (*it).beneficio;
pesoact += (*it).peso;
}
return beneficio;
}
开发者ID:mgmacias95,项目名称:Apuntes,代码行数:13,代码来源:mochila_branch_bound.cpp
示例12: two_array
int two_array(multiset<int> &a, multiset<int> &b, int k)
{
for(int i : a)
{
multiset<int>::iterator it = b.lower_bound(k-i);
if(it == b.end())
return 0;
b.erase(it);
}
return 1;
}
开发者ID:shrivashish,项目名称:HackerRank,代码行数:13,代码来源:TwoArrays.cpp
示例13: main
int main()
{
int num;
while(cin>>num&&num)
{
int key;
vec.clear();
for(int i=0;i<num;i++)
{
cin>>key;
vec.insert(key);
}
int sum=0;
int x,y,s;
while(vec.size()>=2)
{
multiset<int>::iterator it1=vec.begin();
x=*it1;
vec.erase(it1);
multiset<int>::iterator it2=vec.begin();
y=*it2;
vec.erase(it2);
sum=sum+x+y;
vec.insert(x+y);
}
cout<<sum<<endl;
}
return 0;
}
开发者ID:iFighting,项目名称:Algorithm-Contests,代码行数:29,代码来源:Add+All.cpp
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: 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
注:本文中的multiset类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论