UVA1153-Keep the Customer Satisfied(贪心+优先队列)
来源:互联网 发布:linux 免费邮件服务器 编辑:程序博客网 时间:2024/04/28 01:23
题目链接
题意:有一家大型的钢铁厂,每月初都收到大量客户的订单,订单包括定制的钢铁的数量q,以及交货的截止时间d。每个单位时间只能完成一个订单的工作,不能同时进行多个,要求怎么安排使得接受的订单最多。
思路:要使得订单最多,首先我们先按照截止日期,从小到大排序。
当
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int MAXN = 800005;const int N = 2000005;struct order{ int q, d;}o[MAXN];int n;int cmp (order a, order b) { return a.d < b.d;}int solve() { priority_queue<int> Q; int t = 0, temp; for (int i = 0; i < n; i++) { if (o[i].q + t <= o[i].d) { Q.push(o[i].q); t += o[i].q; } else if (!Q.empty()){ temp = Q.top(); if (temp > o[i].q) { t = t - temp + o[i].q; Q.pop(); Q.push(o[i].q); } } } return Q.size();}int main() { int cas; scanf("%d", &cas); while (cas--) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &o[i].q, &o[i].d); sort(o, o + n, cmp); printf("%d\n", solve()); if (cas) printf("\n"); } return 0;}
0 0
- UVA1153-Keep the Customer Satisfied(贪心+优先队列)
- 【UVa1153】Keep the Customer Satisfied 顾客是上帝(贪心)
- 1153 - Keep the Customer Satisfied(贪心+优先队列)
- uva 1153 - Keep the Customer Satisfied(贪心+优先队列)
- UVa 1153 - Keep the Customer Satisfied (贪心 + 优先队列)
- poj 2786 Keep the Customer Satisfied(贪心+优先队列)
- UVa 1153 Keep the Customer Satisfied (贪心+优先队列)
- 【POJ】2786-Keep the Customer Satisfied(贪心 + 优先队列,姿势不对就要跪)
- 习题8-12 UVA - 1153 Keep the Customer Satisfied 顾客是上帝(优先队列贪心)
- 顾客是上帝 Keep the Customer Satisfied uva1153
- POJ 2786 Keep the Customer Satisfied 优先队列
- POJ 2786 Keep the Customer Satisfied 贪心
- UVALive - 3507 Keep the Customer Satisfied 贪心
- 1153 - Keep the Customer Satisfied(贪心)
- Keep the Customer Satisfied
- 顾客是上帝(Keep the Customer Satisfied, ACM/ICPC SWERC 2005, UVa1153)
- UVa 1153 Keep the Customer Satisfied 解题报告(贪心)
- UVa 1153 - Keep the Customer Satisfied(贪心)
- Mobile Web前端开发系列: 动画系列(一)
- memcache 安装启动
- HDU 1754 I Hate It【线段树】
- 解决java.lang.RuntimeException: Parcel: unable to marshal value 问题
- 菜单
- UVA1153-Keep the Customer Satisfied(贪心+优先队列)
- Max Points on a Line
- PKU #1251/HDU #1301 Jungle Roads(Kruskal+并查集)
- hdparm优化硬盘
- Javascript关于数组的一些操作
- jquery $.ajax() $.get() $.load() 区别
- Jquery 获取 radio选中值
- C中的类型强制转换
- Linux 多播例子 及修正