UVA - 1153 Keep the Customer Satisfied
来源:互联网 发布:手机数据为啥自动打开 编辑:程序博客网 时间:2024/05/29 19:40
题目大意:有n个客户,去买一家商场,结算时候排队,每个顾客有一个等待时间,过了等待时间顾客就会不满,然后每个顾客又有一个结算时间,问说最多让几个顾客满意。
解题思路:先按照等待时间从小到大排列,然后遍历一遍,每次加上当前人的时间,如果时间超过了当前的等待时间,则减掉前面满意人当中结算时间最长的那个人的时间。
#include <cstdio>#include <queue>#include <algorithm>using namespace std;struct Order { int q; int d; bool operator < (const Order& a) const { return d < a.d; }} A[800010];int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &A[i].q, &A[i].d); sort(A, A + n); int cur = 0; priority_queue<int> que; for (int i = 0; i < n; i++) { cur += A[i].q; que.push(A[i].q); if (cur > A[i].d) { cur -= que.top(); que.pop(); } } printf("%ld\n", que.size()); if (T) puts(""); } return 0;}
0 0
- uva uva 1153 - Keep the Customer Satisfied
- UVa - 1153 - Keep the Customer Satisfied
- UVA - 1153 Keep the Customer Satisfied
- UVA 1153 - Keep the Customer Satisfied
- UVA 1153(p255)----Keep the Customer Satisfied
- UVA 1153 Keep the Customer Satisfied
- uva 1153 - Keep the Customer Satisfied(贪心+优先队列)
- UVa 1153 Keep the Customer Satisfied 解题报告(贪心)
- UVa 1153 - Keep the Customer Satisfied (贪心 + 优先队列)
- UVa #1153 Keep the Customer Satisfied (习题8-12)
- UVa 1153 - Keep the Customer Satisfied(贪心)
- uva 1153—— Keep the Customer Satisfied
- UVA 1153 - Keep the Customer Satisfied(贪心)
- UVA 1153 Keep the Customer Satisfied(贪心2.0)
- Uva 1153 Keep the Customer Satisfied(贪心)
- UVa 1153 Keep the Customer Satisfied (贪心+优先队列)
- uva 1613 Keep the Customer Satisfied
- Keep the Customer Satisfied
- LightOJ 1422 Halloween Costumes (区间DP)
- 自已实现一个UI库-UI核心绘图层管理
- cocos2d-x游戏开发(十六)帧动画
- 智能储物柜/快递柜系统解析<一>
- Java高级个人笔记(java常用集合总结)
- UVA - 1153 Keep the Customer Satisfied
- Activity栈+单例模式
- coredata 小结
- 视差动画引导界面
- alter database datafile offline 和offline drop的区别
- liunx源码 makefile详细分析
- android中Thread对于Adapter出现的报错情况的处理以及如何正确使用Spinner与SimpleCurosorAdapter
- I2C
- Js获取当前日期时间及其它操作