Uva 6440 - Emergency Handling 多个优先队列维护
2013-12-01 22:40
369 查看
题意:
再一个二维平面内,不断的有射线插入(1<=N<=100000)..同时也会在某些x处询问这些射线中最大的y值...请输出这些y值...
题解:
突破口在题目给出了斜率范围是[1,100]的整数.. 所以可以构造100个优先队列..优先级是在这个斜率下..y值大...那么每次要么就是往100个中某个优先队列丢入一个线..要么是输出..找出这100个中..栈顶y最大的..然后将其弹栈...
Program:
再一个二维平面内,不断的有射线插入(1<=N<=100000)..同时也会在某些x处询问这些射线中最大的y值...请输出这些y值...
题解:
突破口在题目给出了斜率范围是[1,100]的整数.. 所以可以构造100个优先队列..优先级是在这个斜率下..y值大...那么每次要么就是往100个中某个优先队列丢入一个线..要么是输出..找出这100个中..栈顶y最大的..然后将其弹栈...
Program:
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <queue> #include <string.h> using namespace std; typedef long long ll; priority_queue<int> Q[102]; int main() { int C,cases,n,t,s,r,num,w,temp,h,data; char c; scanf("%d",&C); for (cases=1;cases<=C;cases++) { scanf("%d",&n); for (r=0;r<=100;r++) while (Q[r].size()) Q[r].pop(); printf("Case #%d:\n",cases); num=0; while (n--) { do { c=getchar(); }while (c!='P' && c!='A'); if (c=='P') { scanf("%d%d%d",&t,&s,&r); s-=t*r; Q[r].push(s); }else { data=-(1<<30); scanf("%d",&t); for (r=0;r<=100;r++) if (Q[r].size()) { h=Q[r].top(); temp=h+t*r; if (temp>=data) { data=temp; w=r; } } h=Q[w].top(),Q[w].pop(); printf("%d %d\n",h+t*w,w); } } } return 0; }
相关文章推荐
- UVALive - 3135 - Argus (优先队列!!)
- The kth great number-优先队列的k维护
- UVa 136 Ugly Numbers【优先队列】
- 【优先队列之多路合并】UVA - 11997 K Smallest Sums
- UVa 11997 (优先队列 多路归并) K Smallest Sums
- Codeforces 845 C Two TVs(贪心之优先队列维护)
- K Smallest Sums(Uva 11997) 多路归并+优先队列
- UVA 6440 Emergency Handling 队列
- UVa-136-Ugly Number STL 优先队列的基础使用
- UVA 10954 STL优先队列 模拟Huffmancode
- codevs2069 油画 — 动态维护优先队列
- uva11134贪心加优先队列
- 优先队列 UVA 11997 K Smallest Sums
- uva 136(Ugly Numbers, 优先队列基础)
- I - Argus UVA - 1203 --优先队列
- Uva11997——优先队列,多路合并
- uva 11997 k个最小和(优先队列实现多路归并)题解
- 二叉堆维护优先队列
- UVA 11134 Fabled Rooks 优先队列
- UVa 12100 - Printer Queue【队列和优先队列】