随笔分类 - 堆
摘要:problem在一条直线上有n个坑,要种k棵树。不能在相邻两个坑种树。已知在每个坑种树会有一个获利,求最大获利。n#includeusing namespace std;const int maxn = 5e5+10;struct node{ int id, v...
阅读全文
摘要:problemsolutioncodes//动态维护大根堆,贪心减少入队元素个数#include#include#includeusing namespace std;const int maxn = 100010;int n, a[maxn], b[maxn];//...
阅读全文
摘要:problemn个建筑需要抢修第i个建筑需要T1时间抢修,必须在T2时间之前抢修完毕求最多能抢修多少建筑solution先按照 t2 从小到大排列(对于每一个建筑,我们肯定等它快到限制的时候再修复它。)对于一个建筑,如果能修理就修理;如果不能修,就比较他和前面修理了的...
阅读全文
摘要:problemsolutioncodes#include #include #include using namespace std; int l[20005]; int main() { int n; while(cin>>n){ ...
阅读全文
摘要:description输入M个数,当已输入的个数为奇数个时输出此时的中位数。 一共有M/2+1个中位数要输出,每一行10个。solution维护两个优先队列。 大根堆q1维护比当前中位数小的元素。 小跟堆q2维护比当前中位数大的元素。我们把中位数放在大根堆q1的堆顶,...
阅读全文