UVa - 11136 Hoax or what (水题 最大最小堆 set)
2014-09-25 10:38
465 查看
UVA - 11136 Hoax or what
Back] [Status] Description Problem H: Hoax or whatEach 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 input5 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 input19 2 T. Walen, adapted by P. Rudnicki Warning: Time limit is too tight to get accepted using STL. The input file size is around 16 MBSourceRoot :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Data Structures and Libraries :: Non Linear Data Structures with Built-in Libraries :: C++ STL map/set (Java TreeMap/TreeSet) Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Data Structures and Libraries :: Non Linear Data Structures with Built-in Libraries :: C++ STL set (Java TreeSet) Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 2. Data Structures and Libraries :: Data Structures With Built-in Libraries :: STL map/set Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 3. Data Structures :: Fundamental Data Structures :: Exercises: Beginner [Submit] [Go Back] [Status] |
n天,每天有ki张单据,每张单据上面有金额。第一天早上箱子是空的,每天晚上都把当天的单据放进箱子里,然后取出两张最大,最小的单据max,min,然后为最大单据所有者提供max - min的奖品。问n天一共要提供多少价值奖品。
直接multiset/优先队列就行了
#include <cstdio> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <string> #include <map> #include <cmath> #include <queue> #include <set> using namespace std; //#define WIN #ifdef WIN typedef __int64 LL; #define iform "%I64d" #define oform "%I64d\n" #define oform1 "%I64d" #else typedef long long LL; #define iform "%lld" #define oform "%lld\n" #define oform1 "%lld" #endif #define S64I(a) scanf(iform, &(a)) #define P64I(a) printf(oform, (a)) #define P64I1(a) printf(oform1, (a)) #define REP(i, n) for(int (i)=0; (i)<n; (i)++) #define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++) const int INF = 0x3f3f3f3f; const double eps = 1e-9; const double PI = (4.0*atan(1.0)); multiset<int> S; int main() { int n; while(scanf("%d", &n) != EOF && n) { LL ans = 0; S.clear(); for(int i=0; i<n; i++) { int k; scanf("%d", &k); for(int j=0; j<k; j++) { int t; scanf("%d", &t); S.insert(t); } set<int>::iterator eit = S.end(); set<int>::iterator sit = S.begin(); --eit; ans += *eit - *sit; S.erase(eit); S.erase(sit); } P64I(ans); } return 0; }
相关文章推荐
- UVA 11136 Hoax or what set
- set UVA 11136 Hoax or what
- UVa 11136 - Hoax or what
- UVA 11136——Hoax or what
- uva 11136 - Hoax or what(STL)
- UVA 11136(p245)----Hoax or what
- UVA - 11136 Hoax or what
- UVa 11136 Hoax or what(multiset 应用)
- UVA11136 Hoax or what STL 或者 HEAP
- Uva-11136-Hoax or what
- Multiset的使用 TOJ 2196.Nuanran's Idol II 与 UVA11136 Hoax or what
- UVA - 11136 Hoax or what (multiset)
- UVA 11136 Hoax or what(multiset)
- UVA11136 Hoax or what
- uva 11136 - Hoax or what
- UVa 11136 - Hoax or what
- UVA 11136 Hoax or what
- uva 11136 Hoax or what
- UVA 11136 Hoax or what(Multiset)
- UVa 11136 Hoax or what (STL)