zoukankan      html  css  js  c++  java
  • uva 11136 multiset

    用multiset模拟一下就可以了,需要注意的是erase(val)会将值等于val的全部删掉,而erase(iterator)只会删去该iterator指向的一个值。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <set>
     5 using namespace std;
     6 
     7 multiset<int> s;
     8 multiset<int>::iterator it;
     9 
    10 int main ()
    11 {
    12     int n;
    13     while ( scanf("%d", &n), n )
    14     {
    15         long long sum = 0;
    16         s.clear();
    17         for ( int i = 0; i < n; i++ )
    18         {
    19             int m;
    20             scanf("%d", &m);
    21             while ( m-- )
    22             {
    23                 int tmp;
    24                 scanf("%d", &tmp);
    25                 s.insert(tmp);
    26             }
    27             it = s.begin();
    28             int lb = (*it);
    29             s.erase(it);
    30             it = s.end();
    31             it--;
    32             int ub = (*it);
    33             s.erase(it);
    34             sum += ub - lb;
    35         }
    36         printf("%lld
    ", sum);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    poj 2386 Lake Counting
    hdu 3998 Sequence
    hdu 1556 Color the ball
    synchronized和ReentrantLock的区别
    4种常用线程池
    java深浅拷贝
    ConcurrentHashMap总结
    List原理
    volatile关键字
    java关键字总结
  • 原文地址:https://www.cnblogs.com/huoxiayu/p/4768430.html
Copyright © 2011-2022 走看看