[luoguP2949] [USACO09OPEN]工作调度Work Scheduling(贪心 + 优先队列)


传送门

这个题类似于建筑抢修。

先按照时间排序。

如果当前时间小于任务截止时间就选,

否则,看看当前任务价值是否比已选的任务的最小价值大,

如果是,就替换。

可以用优先队列。

——代码

1 #include <queue> 2 #include <cstdio> 3 #include <iostream> 4 #include <algorithm> 5 #define LL long long 6 7 const int MAXN = 1e6 + 5; 8 int n; 9 LL tim, ans; 10 struct node 11 p[MAXN]; 14 std::priority_queue <LL, std::vector <LL>, std::greater <LL> > q; 15 16 inline LL read() 17 24 25 inline bool cmp(node x, node y) 26 29 30 int main() 31 45 } 46 printf("%lld\n", ans); 47 return 0; 48 }
View Code



上一篇:[luoguP1879] [USACO06NOV]玉米田Corn Fields(DP)

下一篇:高精度


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