本文整理汇总了C++中multiset::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::erase方法的具体用法?C++ multiset::erase怎么用?C++ multiset::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::erase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
file_r("laundro_matt.txt");
file_w("out.out");
int cas = 0;
cin >> T;
while (T--) {
cin >> l >> n >> m >> d;
s.clear();
rep (i, n) {
cin >> w[i];
s.insert(mp(w[i], w[i]));
}
q.clear();
m = min(l, m);
rep (i, m) q.insert(0);
ans = 0;
rep (i, l) {
iter = s.begin();
a[i] = iter->X;
s.erase(iter);
s.insert(mp(iter->X + iter->Y, iter->Y));
it = q.begin();
q.erase(it);
if (*it <= a[i]) {
ans = max(ans, a[i] + d);
q.insert(a[i] + d);
} else {
ans = max(ans, *it + d);
q.insert(*it + d);
}
}
示例2: main
int main()
{
#ifdef fn
freopen(fn".in", "r", stdin);
freopen(fn".out", "w", stdout);
#endif
scanf("%d", &n);
int nn = n * n;
for (int i = 1; i <= nn; i++)
{
scanf(I64, g + i);
s.insert(-g[i]);
}
for (int i = 1; i <= n; i++)
{
a[i] = -(*s.begin());
//printf("%d ", a[i]);
s.erase(s.begin());
for (int j = 1; j < i; j++)
{
s.erase(s.find(-__gcd(a[j], a[i])));
s.erase(s.find(-__gcd(a[j], a[i])));
}
}
for (int i = 1; i <= n; i++)
printf(I64 " ", a[i]);
}
示例3: 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;
}
示例4: insert
void insert(int num)
{
if(median == -1) median = num;
else
{
if(num < median)
small_number_set.insert(num);
else
big_number_set.insert(num);
if(small_number_set.size() + 1 < big_number_set.size())
{
small_number_set.insert(median);
auto median_iter = big_number_set.begin();
median = *median_iter;
big_number_set.erase(median_iter);
}
else if(small_number_set.size() > big_number_set.size())
{
big_number_set.insert(median);
auto median_iter = prev(small_number_set.end());
median = *median_iter;
small_number_set.erase(median_iter);
}
}
}
示例5: main
int main(){
ll n, res, k, val;
while(true){
scanf("%lld", &n);
if(n == 0)
break;
s.clear();
res = 0;
while(n--){
scanf("%lld", &k);
for(int j = 0; j < k; j++){
scanf("%lld", &val);
s.insert(val);
}
res += *s.begin() - *prev(s.end());
s.erase(s.begin());
s.erase(prev(s.end()));
}
printf("%lld\n", res);
}
return 0;
}
示例6: main
int main() {
#ifndef ONLINE_JUDGE
freopen("519b.in", "r", stdin);
freopen("519b.out", "w", stdout);
#endif
cin >> n;
for(int i = 1 ; i <= n ; ++ i) {
int x;
cin >> x;
s1.insert(x);
}
for(int i = 1 ; i < n ; ++ i) {
int x;
cin >> x;
s1.erase(s1.find(x));
s2.insert(x);
}
cout << *s1.begin() << '\n';
for(int i = 1 ; i < n - 1 ; ++ i) {
int x;
cin >> x;
s2.erase(s2.find(x));
}
cout << *s2.begin() << '\n';
}
示例7: update
void update(int a, int b) {
if (f[a] != -1) {
int temp = *SS[f[a]][c[a]].begin();
SS[f[a]][c[a]].erase(SS[f[a]][c[a]].find(d[a]));
if (SS[f[a]][c[a]].empty()) SS[f[a]].erase(c[a]);
if (c[f[a]] != c[a]) {
S.erase(S.find(temp));
if (SS[f[a]].find(c[a]) != SS[f[a]].end() && !SS[f[a]][c[a]].empty())
S.insert(*SS[f[a]][c[a]].begin());
}
if (c[f[a]] != b) {
if (!SS[f[a]][b].empty()) {
if (d[a] < *SS[f[a]][b].begin()) {
S.erase(S.find(*SS[f[a]][b].begin()));
S.insert(d[a]);
}
} else {
S.insert(d[a]);
}
}
SS[f[a]][b].insert(d[a]);
}
if (SS[a].find(c[a]) != SS[a].end()) S.insert(*SS[a][c[a]].begin());
if (SS[a].find(b) != SS[a].end()) S.erase(S.find(*SS[a][b].begin()));
c[a] = b;
}
示例8: scanf
main()
{
int n,m,Q ; scanf("%d%d%d",&m,&n,&Q) ;
s1.insert(0) ; s1.insert(n) ;
s2.insert(0) ; s2.insert(m) ;
d1.insert(n) ; d2.insert(m) ;
while(Q--)
{
char s[6] ; int x ;
scanf("%s%d",s,&x) ;
if(s[0]=='H')
{
auto it=s1.lower_bound(x) ;
int x2=*it ; it-- ; int x1=*it ;
d1.erase(d1.find(x2-x1)) ;
d1.insert(x2-x) ;
d1.insert(x-x1) ;
s1.insert(x) ;
}
else
{
auto it=s2.lower_bound(x) ;
int x2=*it ; it-- ; int x1=*it ;
d2.erase(d2.find(x2-x1)) ;
d2.insert(x2-x) ;
d2.insert(x-x1) ;
s2.insert(x) ;
}
printf("%I64d\n",(LL)(*d1.begin())*(*d2.begin())) ;
}
}
示例9: main
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
if (n==0) break;
LL ans = 0;
num.clear();
for (int i = 0; i < n; i++)
{
int k;
scanf("%d", &k);
for (int j = 0; j < k; j++)
{
int x;
scanf("%d", &x);
num.insert(x);
}
ans += *num.rbegin() - *num.begin();
num.erase(num.find(*num.begin()));
num.erase(num.find(*num.rbegin()));
}
printf("%I64d\n", ans);
}
return 0;
}
示例10: main
int main(){
ifstream fin("input.txt");
ofstream fout("output.txt");
int n, k;
long long tmp, t;
fin>>n>>k;
for(int i=0; i<n; ++i){
fin>>tmp;
if(q.size()==k){
t=*q.begin(); q.erase(q.begin());
q.insert(t+tmp);
} else q.insert(tmp);
}
while(q.size()>1) q.erase(q.begin());
fout<<*q.begin()<<endl;
fin.close();
fout.close();
return 0;
}
示例11: 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;
}
示例12: 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;
}
示例13: solve
void solve() {
int rez = 0;
multiset <int> :: iterator it;
for (int i = 1; i <= n; ++i) {
it = s.lower_bound(v[i].first);
if (it != s.end() && *it == v[i].first) {
s.erase(it);
s.insert(v[i].second);
++rez;
} else {
if (it == s.begin())
continue;
--it;
s.erase(it);
s.insert(v[i].second);
++rez;
}
}
printf("%d\n", rez);
}
示例14: remove
void remove(int num) {
if (num >= median)
right.erase(right.find(num));
else
left.erase(left.find(num));
balance();
median = cal();
}
示例15: 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;
}