Uva 1153 Keep the Customer Satisfied(贪心)
来源:互联网 发布:网络销售股票怎么加人 编辑:程序博客网 时间:2024/05/22 01:40
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3594
思路:
从小到大排序,依次加入,若当前值超过规定时间,则从已加入的订单中删去所需时间最大的,然后将当前订单加入记录个数即可。
#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=8e5+50;struct Node{ int need,time;};int n;Node a[maxn];priority_queue<int,vector<int>,less<int> > q;int cmp(Node a,Node b){ return a.time<b.time;}int main(){ int t,cas=0; scanf("%d",&t); while(t--) { cas++; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&a[i].need,&a[i].time); } sort(a,a+n,cmp); int now=0,ans=0; while(!q.empty()) q.pop(); for(int i=0;i<n;i++) { now+=a[i].need; ans++;q.push(a[i].need); if(now>a[i].time) { ans--; if(!q.empty()) { now-=q.top(); q.pop(); } } } if(cas!=1) printf("\n"); printf("%d\n",max(ans,0)); } return 0;}
阅读全文
0 0
- UVa 1153 Keep the Customer Satisfied 解题报告(贪心)
- UVa 1153 - Keep the Customer Satisfied(贪心)
- UVA 1153 - Keep the Customer Satisfied(贪心)
- Uva 1153 Keep the Customer Satisfied(贪心)
- 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 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
- 习题8-12 UVA - 1153 Keep the Customer Satisfied 顾客是上帝(优先队列贪心)
- UVA 1153Keep the Customer Satisfied 顾客是上帝 经典贪心 (SWE 2005)
- 1153 - Keep the Customer Satisfied(贪心+优先队列)
- Redis安装和配置
- 怎样让一段代码在主函数之前执行
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 C.Sum(找规律)
- Java多线程之队列Quene-yellowcong
- pycharm中配置pyqt4环境
- Uva 1153 Keep the Customer Satisfied(贪心)
- HDU 1078 FatMouse and Cheese (dfs + dp记忆化搜索)
- R Notes
- 指针与引用
- 输出字符串的所有组合
- L
- 《深度学习——Andrew Ng》第一课第三周编程作业
- web学习第一天
- C++基础知识 二篇