题目链接

题意:n天,每天往一个箱子里放m个数,放完之后取最大的Max和最小的min做差,并把这两个数去掉,求n天之后的和

multiset 和 set的原理是相似的,multiset可以存多个相同的数,而set都是唯一的,同时都是从小到大排列

set容器的总结

set还有lower_bound(x) {返回 第一个大于或者等于x的位置} 和 upper_bound(x) { 返回第一个大于x的位置 }

#include <iostream>
#include <set>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
multiset<int> s;
int main()
{
int n,m;
while(scanf("%d", &n) != EOF && n)
{
s.clear();
long long ans = ;
int minn,maxn;
for(int i = ; i <= n; i++)
{
scanf("%d", &m);
for(int j = ; j <= m; j++)
{
int thing;
scanf("%d", &thing);
s.insert(thing);
}
if(s.size() > )
{
multiset<int>::iterator it;
it = s.end();
it--;
maxn = *it;
s.erase(it); // 本来这里写成了s.erase(maxn),错误,应为会把所有的maxn都删除,这里只要删除一个
it = s.begin();
minn = *it; //如果最后只剩下一个数,既是最大又是最小
if(s.size() > )
{
it = s.begin();
s.erase(it);
}
ans += maxn - minn;
}
}
printf("%lld\n", ans);
}
return ;
}

UVA11136Hoax or what( multiset的应用)的更多相关文章

  1. C++ std::multiset

    std::multiset template < class T, // multiset::key_type/value_type class Compare = less<T>, ...

  2. Guava学习笔记:Guava新增集合类型-Multiset

    Guava引进了JDK里没有的,但是非常有用的一些新的集合类型.所有这些新集合类型都能和JDK里的集合平滑集成.Guava集合非常精准地实现了JDK定义的接口.Guava中定义的新集合有: Multi ...

  3. [Google Guava]学习--新集合类型Multiset

    Guava提供了一个新集合类型Multiset,它可以多次添加相等的元素,且和元素顺序无关.Multiset继承于JDK的Cllection接口,而不是Set接口. Multiset主要方法介绍: a ...

  4. 4.2 set和multiset

    使用必须包含头文件set 1)multiset *:定义 如果不给第二个参数,默认less<key>,即用<来进行. 例如: A是一个类的名字,则可以定义一个容器对象如下: mult ...

  5. STL(multiset) UVA 11020 Efficient Solutions

    题目传送门 题意:训练指南P228 分析:照着书上的做法,把点插入后把它后面不占优势的点删除,S.size ()就是优势的人数,时间复杂度O (nlogn) #include <bits/std ...

  6. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(可持久化Trie)

    D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  7. STL中的set/multiset小结

    (1)使用set/multiset之前必须包含头文件<set>:#include<set> (2)namespace std{ template <class T, cl ...

  8. STL--集和多集(set/multiset)

    与基本容器相比,关联容器更注重快速和高效地检索数据的能力.这些容器是根据键值(key)来检索数据的,键可以是值也可以是容器中的某一成员.这一类中的成员在初始化后都是按一定顺序排好序的. 本文地址:ht ...

  9. C++ Set & MultiSet

    转自http://www.cppblog.com/wanghaiguang/archive/2012/06/05/177627.html STL Set介绍集合(Set)是一种包含已排序对象的关联容器 ...

随机推荐

  1. Euler Level 2

    闲下来的时候就做点,慢慢的也终于到达Level 2了.

  2. AngularJS引入Echarts的Demo

    最近要用到图表展示,想了想,还是首选Echarts,HighCharts和D3.js备用吧, 而项目中也用到了AngularJS,所以需要把Echarts引入到AngularJs中一起使用, 试了试, ...

  3. html 文本超过显示省略号

    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;//显示行数 word-break: break-a ...

  4. js 漩涡

    What's the ball's orbit if they head for it's next ball. <html> <canvas id="ca"&g ...

  5. Beta项目冲刺–第四天

    考试太多,做项目的时间太少-- 队伍:F4 成员:031302301 毕容甲 031302302 蔡逸轩 031302430 肖阳 031302418 黄彦宁 会议内容: 1.站立式会议照片: 2.项 ...

  6. jQuery能做些什么

    来源于: Learning jQuery, 4th Edition What jQuery does: 1. Access elements in a document; $('div.content ...

  7. webService访问加密-Soapheader

    WebService head加密,可以对 WebService设置访问用户名和密码,增强 WebService的安全性 使 WebService只能被授权用户使用. 具体实现步骤: 1. 定义一个  ...

  8. fatal: Not a valid object name: 'master'.

    fatal: Not a valid object name: 'master'. the answer is : That is again correct behaviour. Until you ...

  9. ansible解密

    ansible是个什么东西呢?官方的title是“Ansible is Simple IT Automation”——简单的自动化IT工具.这个工具的目标有这么几项:让我们自动化部署APP:自动化管理 ...

  10. The resource identified by this request is only capable of generating responses with characteristics

    [转]今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only cap ...