[BZOJ1572] [Usaco2009 Open]工作安排Job(贪心 + 堆)


传送门

把任务按照d排序

一次加入到堆中,如果当前放不进堆中,并且比堆中最小的大,

就从堆中弹出一个数,再把当前的数放进去

#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 100001 #define LL long long using namespace std; int n; LL ans; priority_queue <LL, vector <LL>, greater <LL> > q; struct node a[N]; inline LL read() inline bool cmp(node x, node y) int main() while(!q.empty()) ans += q.top(), q.pop(); printf("%lld\n", ans); return 0; }

  



上一篇:[luoguP3668] [USACO17OPEN]Modern Art 2 现代艺术2(栈)

下一篇:[BZOJ1590] [Usaco2008 Dec]Secret Message 秘密信息(字典树)


stl 贪心
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图