UVALive 6440 Emergency Handling 优先队列
来源:互联网 发布:义乌淘宝培训学校 编辑:程序博客网 时间:2024/06/02 00:08
题目连接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4451
题目意思:给你一个公式计算每个病人的危机程度,之后给你一定量的的admission表示这个时间允许治疗一个病人,让你每次输出当前时间下,危险程度最高的病人。
分析:可以对公式预处理一下,存一个处理 S= st0 - R * T0, 这样子,就相当于每个人都是进来的初始时间一样。 公式变成 ans =S + R * T ; 现在就只剩下 S 和 R这两个变量。 我们可以每次按照 相同的R 值, 比较S 找出 S 最大的值 就是每个人最危险的。 然后比较这些 S 输出 最大的那个S。 可以用默认的优先队列。直接就能输出相同R下S的最大值。
#include <stdio.h>#include <iostream>#include <math.h>#include <string.h>#include <stdlib.h>#include <algorithm>#include <bitset>#include <queue>#define MIN (1<<30)-1#define exp 1e-8using namespace std;#define ll long longstruct pat{ int st,r;}p[100086];int Max[105],maxx; priority_queue < int > q[110];int main(){ int i,j; int st,t0,r,a; int T,n; scanf("%d",&T); for(int t=1;t<=T;t++) { for(i=0;i<=100;i++) Max[i]=-MIN; for(i=0;i<=110;i++) //清空队列 初始化 { while(!q[i].empty()) q[i].pop(); } printf("Case #%d:\n",t); scanf("%d",&n); char str; for(i=0;i<n;i++) { getchar(); j = 0; scanf("%c", &str); if(str == 'P') { scanf("%d%d%d",&t0,&st,&p[j].r); p[j].st = st - t0 * p[j].r; q[p[j].r].push( p[j].st ); } else if(str == 'A') { scanf("%d",&a); int s; int ans = -MIN , num; for( s = 0; s<=100 ; s++) { if(!q[s].empty()) { if(ans <= q[s].top() + (a * s)) { ans = q[s].top() + (a * s); num = s; } } } q[num].pop(); printf("%d %d\n", ans , num); } } } return 0;}
0 0
- UVALive 6440 Emergency Handling 优先队列
- Uva 6440- Emergency Handling 多个优先队列维护
- UVA 6440 Emergency Handling 队列
- UvaLive 6440 - Emergency Handling(数据结构)
- UVALive 6093 Emergency Room --优先队列实现的模拟
- 1003. Emergency (25) <优先队列>
- UvaLive 4254 Processor 优先队列
- UVALive - 3135 Argus 优先队列
- UVALive - 3135 Argus 优先队列
- UVALive - 3135 Argus【优先队列】
- UVALive - 3135 - Argus (优先队列!!)
- UVALive - 4254 Processor 二分+优先队列
- UVALive 3135 Argus(优先队列)
- UVALive - 2757 Supermarket 贪心+优先队列
- UVALive - 4327 Parade DP + 优先队列
- UVALive 3135 Argus(优先队列)
- UVaLive 2757 Supermarket (贪心+优先队列)
- UVALive 3135--Argus+自定义优先队列的优先规则
- Android 网络开发框架的选择
- CRM系统与Excel电子表格
- protobuf-c学习总结
- TrackingPoint:高精度自动制导步枪 菜鸟变枪神
- CRM系统 - 有助于吸引和留住按揭信息
- UVALive 6440 Emergency Handling 优先队列
- CRM的新技术倡议
- char *p="abcdef"和char s[]="abcdef"存储在哪里?
- C++继承:公有 私有 保护
- 编译安装mysql
- linux执行python的脚本文件,提示提示No such file or directory
- LeetCode | Length of Last Word(最后一个单词的长度)
- vector,map,list,queue区别
- android shape使用方法