UVA 11136(p245)----Hoax or what

#include<bits/stdc++.h>
#define debu
using namespace std;
int n;
multiset<int> s;
int main()
{
#ifdef debug
    freopen("in.in","r",stdin);
#endif // debug
    while(scanf("%d",&n)==1&&n)
    {
        s.clear();
        long long sum=0;
        for(int i=0; i<n; i++)
        {
            int k;
            scanf("%d",&k);
            for(int j=0; j<k; j++)
            {
                int x;
                scanf("%d",&x);
                s.insert(x);
            }
            multiset<int>::iterator maxx,minn;
            minn=s.begin();
            maxx=s.end();
            maxx--;
          //  cout<<*maxx<<" "<<*minn<<endl;
            sum+=*maxx-*minn;
            s.erase(minn);
            s.erase(maxx);
        }
        printf("%lld\n",sum);
    }
    return 0;
}

题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2077

题解:multiset中可有重复元素且数据有序,模拟即可。

你可能感兴趣的:(UVA 11136(p245)----Hoax or what)