11136-Hoax or what
Each Mal-Wart supermarket has prepared a promotion scheme run by the following rules:
- A client who wants to participate in the promotion (aka a sucker) must write down their phone number on the bill of their purchase and put the bill into a special urn.
- Two bills are selected from the urn at the end of each day: first the highest bill is selected and then the lowest bill is selected. The client who paid the largest bill receives a monetary prize equal to the difference between his bill and the lowest bill of the day.
- Both selected bills are not returned to the urn while all the remaining ones are kept in the urn for the next day.
- Mal-Wart has many clients such that at the end of each day there are at least two bills in the urn.
- It is quite obvious why Mal-Wart is doing this: they sell crappy products which break quickly and irreparably. They give a short-term warranty on their products but in order to obtain a warranty replacement you need the bill of sale. So if you are gullible enough to participate in the promotion you will regret it.
Your task is to write a program which takes information about the bills put into the urn and computes Mal-Wart's cost of the promotion.
The input contains a number of cases. The first line in each case contains an integer n, 1<=n<=5000, the number of days of the promotion. Each of the subsequent n lines contains a sequence of non-negative integers separated by whitespace. The numbers in the (i+1)-st line of a case give the data for the i-th day. The first number in each of these lines, k, 0≤k≤105, is the number of bills and the subsequent k numbers are positive integers of the bill amounts. No bill is bigger than 106. The total number of all bills is no bigger than 106. The case when n = 0 terminates the input and should not be processed.
For each case of input print one number: the total amount paid to the clients by Mal-Wart as the result of the promotion.
Sample input
5
3 1 2 3
2 1 1
4 10 5 5 1
0
1 2
2
2 1 2
2 1 2
0
Output for sample input
19
2 动态数组最大值最小值差值的和。Multiset。
#include<cstdio>
#include<set>
using namespace std;
typedef long long LL;
int main()
{
LL n,x,maxn,mind,d,sum;
multiset<LL> s;
while(scanf("%I64d",&n)&&n!=)
{
sum=;
s.clear();
for(LL i=; i<n; i++)
{
scanf("%I64d",&x);
for(LL j=; j<x; j++)
{
scanf("%I64d",&d);
s.insert(d);
}
multiset<LL>::iterator it;
it=s.begin();
mind=*it;
s.erase(it);
it=s.end(),it--;
maxn=*it;
s.erase(it);
sum+=maxn-mind;
}
printf("%lld\n",sum);
}
return ;
}
11136-Hoax or what的更多相关文章
- UVA 11136 - Hoax or what (可以提交了,不会Submission error了)
看题传送门:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- set UVA 11136 Hoax or what
题目传送门 题意:训练指南P245 分析:set维护,查询删除最大最小值 #include <bits/stdc++.h> using namespace std; typedef lon ...
- uva 11136 - Hoax or what
用两个优先队列来实现,因为队列只能从一头出去: 所以维护一个数组,来标记这个队列的已经出列而另外一个队列没有出列的元素: 到时候再把他们删了就行: #include<cstdio> #in ...
- UVA 11136 Hoax or what (multiset)
题目大意: 超时进行促销.把账单放入一个箱子里 每次拿取数额最大的和最小的,给出 最大-最小 的钱. 问n天总共要给出多少钱. 思路分析: multiset 上直接进行模拟 注意要使用long lo ...
- UVa 11136 Hoax or what (STL)
题意:有 n 天,每天有m个数,开始的前一天没有数据,然后每天从这个里面拿出一个最大的和最小的,求 n 天的最大的和最小的差值相加. 析:一看就知道用set啊,多简单的STL,不过要注意,开long ...
- Hoax or what UVA - 11136(multiset的应用)
刚开始把题意理解错了,结果样例没过,后来发现每天只处理最大和最小的,其余的不管,也就是说昨天的元素会影响今天的最大值和最小值,如果模拟的话明显会超时,故用multiset,另外发现rbegin()的功 ...
- Hoax or what
Hoax or what 题意是询问一个动态序列的最小值和最大值. 可以用multiset来实现. #include <stdio.h> #include <set> usin ...
- 优化Hoax or what的思考
在抽取MinHeap的时候,涉及到重载,覆盖,虚函数等,有几点之前没注意到的问题在这里总结下: 1. 覆盖(override)只要是函数同名就会被覆盖,子类指针若调用父类的同名不同参数的函数的话,会在 ...
- SQL Server 2008 R2——VC++ ADO 操作 存储过程 向datetime类型参数传入空值
==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...
- 使用变量替换批量部署GoldenGate
GoldenGate运行时允许在参数文件中动态指定一个值,即在参数文件中使用一个变量,而不是一个静态的值,当启动OGG进程时,根据环境动态加载此变量的值,达到在不同环境中,通过变量定义,实现多个环境的 ...
随机推荐
- <s:if>标签与ActionContext.getContext().getSession()
今天在做<s:if>标签中的属性值从 ActionContext.getContext().getSession().put("WW_TRANS_I18N_LOCALE" ...
- 检测android机器是否有GPS模块
public boolean hasGPSDevice(Context context) { final LocationManager mgr = (LocationManager)context. ...
- php测试时不出现错误信息
来源:http://blog.sina.com.cn/s/blog_6c9d65a101013vdj.html 在练习程序时,有时候写错了,在浏览器会打印出出错信息. 可我的程序始终没有出现. 我的环 ...
- UEFI引导系统
UEFI引导系统 1 2 3 4 5 6 7 分步阅读 现在的电脑大多数使用了UEFI引导系统(原来都是使用BIOS),从而加快启动速度,但同时也给用惯BIOS的用户带来很多困惑!为啥电脑不能识别制作 ...
- 立体像对DEM提取
版权声明:本教程涉及到的数据仅练习使用,禁止用于商业用途. 目录 1.概述 2.详细操作步骤 第一步:输入立体像对 第二步:定义地面控制点 第三步:定义连接点 第四步:设定DEM提取参数 第五步:输出 ...
- VIM+qmake编译示例程序HelloQt出错问题的解决(文件名一定要使用.cpp,否则就会默认使用gcc编译,当然通不过)
之前看到很多初学Qt的Linux友们在使用qmake编译第一个HelloQt或者HelloWorld程序时报错,并且始终找不到原因. 前几天我也遇到了同样的问题,我用的是<精通Qt4编程> ...
- 在Centos 5.x或6.x上安装RHEL EPEL Repo
本文介绍了如何在CentOS 5.x或者CentOS 6.x的系统上使用Fedora Epel repos一个第三方repo:remi资源库.这些资源包并不是天然地支持CentOS,但是提供了很多流行 ...
- C语言入门(1)——C语言概述
1.程序与编程语言 我们使用计算机离不开程序,程序告诉计算机应该如何运行.程序(Program)是一个精确说明如何进行计算的指令序列.这里的计算可以是数学运算,比如通过一些数学公式求解,也可以是符号运 ...
- [Oracle] Listener的动态注册
在有Oracle Listener的动态注册之前,采用的是静态注册,所谓静态注册是指Oracle实例在启动时,读取listener.ora里的配置,然后注册到Listener,它主要有两个缺点: 1. ...
- android插件化-apkplugdemo源代码阅读指南-10
阅读本节内容前可先了解 apkplug基础教程 本教程是基于apkplug V1.6.8 版本号编写 最新开发方式以官网为准 可下载最新的apkplugdemo源代码http://git.oschi ...