4.1 KiB
CUGACM2019寒假作业(一)-- 灵活使用STL
A - 水果
map<string, map<string, int>> 模拟即可
B - Hacker, pack your bags!
对于每一天,维护这一天之前结束的相同时长的所有旅程中cost最小的,不然暴力会TLE。
C - The Union of k-Segments
前缀和瞎搞搞就可以了。
D - Sockets
将电脑(连同id)一起扔进multimap里,然后对socket排序,从最小的开始(这是个什么神奇道理)检查是否有符合的电脑,如果没有就(x+1)/2,直到找到这样的电脑或比当前最小电脑所用量还小(其实直接循环个31次应该也能过)。
E - Bipartite Graph
首先已知这是一个二分图,将其染色并统计两部分数量。将孤立的点选择加到集合一还是二,取最大值即可,时间复杂度与输入复杂度相同。
F - Pearls in a Row
拿set随便一搞就过了,注意Codeforces默认是32位编译的。实在拿不定怎么输出就cout吧(笑)
G - Kiki & Little Kiki 1
multiset.upper_bound()
H - 传递
题意看起来非常奇怪,但是实际上只要用bitset存一下一个点连向了哪些点即可。只要保证对于每一条边,其终点所连向的点的集合为起点连向的点的集合的子集即可判断这个图是“传递”的。
I - HDU Today
map/unordered_map+单源最短路
J - Counter Strike
转换为减掉平均值后求出的前缀和的顺序对数。
K - 区间交
说实话,没怎么看懂题解。望大佬们不吝告知。
L - Music in Car
This problem can be solved with help of two pointers. We will store two sets — set with songs with full time and set with songs with partly time. How to move left and right pointers and recalculate current answer? Let left end of the current segment island right end of the segment isr. Let the set of songs with partly time ishalfand with full time —full. In this sets we will store pairs — time of listening each song and it number.
Right end we will move in the following way: if we can add partly song and we have enough time to listen it — we take it (also add this song tohalf) and add to time$(t_r + 1) / 2$and add to the answer$a_r$. In the other case we have two cases. First — we add current song as full song, second — we add current song as partly song. Here we need to choose case with less with the total time. Also here we need to correctly add song to sets and update total time and the answer. If total time became more thankwe are not allowed to mover. Now we need to update global answer with the current value of answer.
Left end we will move in the following way: if we took song as full song we delete it fromfull, subtract from total time length of this song. In the other case we delete it fromhalfand subtract from the total time the$(t_r + 1) / 2$. After that we try to take some song fromfull. If the size offullis 0, we can not do that. If we done it we need to change total time on the songs on the current segment.
M - Alice and Bob
multiset搞一下(又忘记clear了)
N - Moo University - Financial Aid
按成绩排序后用两个堆分别维护每头牛前后花钱最少的n/2头牛,逆序扫一遍即可。
辣鸡poj不让用
bits/stdc++.h
O - Leaving Auction
看完题愣了几秒,发现自己做过。去翻记录,竟然是去年10月份的事情了。深感久日无功,停滞不前,一事无成。
很多时候勇于面对事情并不能带来成功,但是如果害怕这种事情的发生而不这样做的话,那就甚至算不上失败了。
回到这个题,用一个set来存每个人出的最高价格(因为set自带排序,可以便捷的求出剩下的人出的最高价格)。但是此时我们不能直接输出,而是应当找到出价第二高的人的最高出价,并且在购得者的出价序列里找一个刚好大于此价格的价格,语义上应该使用upper_bound,但是在这题的限制里,lower_bound也是可以的。