UVA 1153(p255)----Keep the Customer Satisfied
来源:互联网 发布:机锋网推荐的淘宝商家 编辑:程序博客网 时间:2024/06/07 08:22
#include<iostream>#include<cstdio>#include<queue>#include<algorithm>using namespace std;const int maxn=1e6;struct point{ int need,d; bool operator <(const point& rhs) const { return need<rhs.need; }};int n;point a[maxn];priority_queue<point> q;int cmp(point a,point b){ if(a.d==b.d) return a.need<b.need; else return a.d<b.d;}int main(){ int t; scanf("%d",&t); while(t--) { while(!q.empty()) q.pop(); scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].need,&a[i].d); sort(a,a+n,cmp); int now=0; for(int i=0;i<n;i++) { if(now+a[i].need<=a[i].d){q.push(a[i]);now+=a[i].need;} else { point tmp=q.top(); if(!q.empty()&&a[i].need<tmp.need) { now=now-tmp.need+a[i].need; q.pop(); q.push(a[i]); } } } printf("%d\n",q.size()); if(t) printf("\n"); } return 0;}
0 0
- UVA 1153(p255)----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 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
- UVA 1152(p237)----4 Values Whose Sum is Zero
- 【hdu2251】Dungeon Master——bfs
- Mac Jenkins 环境搭建
- static_cast、const_cast用法
- TCP/IP详解学习笔记
- UVA 1153(p255)----Keep the Customer Satisfied
- VMware下对Ubuntu进行扩充磁盘大小
- HTML select option基础理解及使用
- CodeForces 629E(#343)|Famil Door and Roads|树形dp|概率
- nginx-rtmp-module和ffmpeg搭建流媒体服务器
- Cpp_构造函数
- UVA 1210(p343)----Sum of Consecutive Prime Numbers
- PAT (Basic Level) Practise 1002. 写出这个数
- Qt键盘事件