5.5 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也是可以的。
P - My pretty girl Noora
Q - Lineland Mail
超级无敌水题。。。。。
R - Berland National Library
水题
S - Producing Snow
multiset加前缀和
T - Geometric Progression
一开始甚至想到了各种可持久化数据结构,然后发现我已经不会写了。
实际上也是个水题(笑),如果C++的range能够更方便一些的话多好啊,这样的事情,或许得等到C++20才能实现吧。
可是啊,有更多的事情,就算愿意付出时间去等待,也是没有结果的吧。就算等到了,感觉大概也是完全不同的。正如C++20+一定会在某一天变成编译器的默认配置,但是那个时候,我早已退役,默认选项是什么,已经不重要了。
multiset的count好像格外的慢呢。或许是通过distance(lower_bound,upper_bound)实现的吧,log(n)都变成nlog(n)了,这种计数还是用map吧。
U - One-Dimensional Battle Ships
维护一下每一段最多能放下的个数之和。
V - King's Path
看起来像个什么离散化后最短路一样的东西。实际上map套map就可以了。
//(如果强行说正解是树套树会不会显得高级一点?)
W - Glass Carving
跟上面那个U差不多,只是xy轴要分开维护。
正版题解上还有一种线性时间复杂度的离线算法,把正序切割改成倒序合并即可。
End
那么这一堆内容就结束了。