码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 11136 Hoax or what (STL)

时间:2016-07-06 01:46:21      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

题意:有 n 天,每天有m个数,开始的前一天没有数据,然后每天从这个里面拿出一个最大的和最小的,求 n 天的最大的和最小的差值相加。

析:一看就知道用set啊,多简单的STL,不过要注意,开long long,和multiset,因为可能数是一样。

代码如下:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <cstdio>

using namespace std;
typedef long long LL;
multiset<int> sets;
multiset<int> :: iterator it1, it2;

int main(){
    int n, m, x;
    while(scanf("%d", &n) == 1 && n){
        sets.clear();
        LL ans = 0;
        while(n--){
            scanf("%d", &m);
            for(int i = 0; i < m; ++i){
                scanf("%d", &x);
                sets.insert(x);
            }
            it1 = sets.end();
            it2 = sets.begin();
            ans += (LL)*--it1;
            ans -= (LL)*it2;
            sets.erase(it1);
            sets.erase(it2);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

 

UVa 11136 Hoax or what (STL)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5645454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!