本文整理汇总了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;
}
示例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;
}
}
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
示例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]);
}
}
示例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;
}
示例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;
}
示例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;
}