UVA 1153 - Keep the Customer Satisfied
来源:互联网 发布:网络歌手易言照片 编辑:程序博客网 时间:2024/06/05 02:48
贪心 按d从小到大排序,res=0,每次res+=q,如果res超了就删掉前面的人中q最大的那个人
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>using namespace std;const int maxn = 800000+10;int T, n;struct node{ int q, d; bool operator < (const node a) const { return q < a.q; }}str[maxn];bool cmp(const node& a, const node&b){ return a.d < b.d;}int main(){ scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%d%d", &str[i].q, &str[i].d); sort(str, str+n, cmp); int res = 0, ans = 0; priority_queue<node> s; for(int i = 0; i < n; ++i) { s.push(str[i]); res += str[i].q; if(res > str[i].d) { node t = s.top(); s.pop(); res -= t.q; --ans; } ++ans; } if(ans <= 0) ans = 0; printf("%d\n", ans); if(T) printf("\n"); } 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
- mybatis学习教程中级(九)mybatis一级缓存、二级缓存(重点)
- oracle简单小知识
- Unity3D显示中文的各种方案的比较
- 网络编程
- 谈业务流程全生命周期管理支撑业务流程再造(1)
- UVA 1153 - Keep the Customer Satisfied
- html滚动效果实现
- abap ALV 报表入门
- 微信开发(4)微信支付3.7C#版
- U3D里UI相关逻辑和文件的组织关系的各种形式的比较
- Saltstack
- 统计思维:程序员数学之概率统计(第2版)——互动出版网
- PowerOff 定时关机软件
- Android 发通知NotificationManager和Notification的详解