题目链接:https://vjudge.net/contest/241341#problem/G

Indonesia, as well as some neighboring Southeast Asian countries and some other East Asian countries, is located in the Pacific Ring of Fire which rather frequently causes volcanic eruptions, large earthquakes, and tsunamis. Handling hospital emergency situations effectively is critical for such countries laden with natural disasters. A leading local hospital recently has asked some computer scientists to help them optimize their emergency handling especially under large volume of cases. During a day, patients may come to the emergency department with different severity (e.g. suffering from broken bone is more severe than suffering from flu) and with different rate of increase of severity (e.g., burn injury if not treated immediately can be very dangerous, compared to broken bone) For a simplified model, suppose a patient arrives at time t0 with initial severity s(t0) and rate of increase of severity per unit of time r. Then the severity at time t becomes s(t) = s(t0) + r·(t−t0) The hospital has only limited facility and workforce to handle the patients so they want to prioritize the handling the best they can. More precisely, at any time t, if the hospital can admit one of the patients to treat, it must choose the patient with the highest severity s(t) at that time t. If there are ties, it must choose the patient with the highest rate of increase of severity r. If there are still ties, any one of the tied patients can be chosen. We assume that once a patient is chosen and given care, the patient will be safe and is no longer in the list of waiting patients. Given the sequence of incoming patients and admission of patients, help the hospital to determine the best patient to admit at each admission event.
Input The first line of input contains an integer T (T ≤ 5) denoting the number of cases. Each case begins with an integer N (1 ≤ N ≤ 100,000) denoting the number of events. For the next N lines, each line describes either an incoming patient or an admission event. • For an incoming patient, the line contains a character ‘P’ and three integers t0, s(t0) and r that describe the patient (0 ≤ t0 ≤ 106; 0 ≤ s(t0) ≤ 108; 0 ≤ r ≤ 100). • For an admission, the line contains a character ‘A’ followed by an integer t, which is the time of the event. You may assume that there is at least one patient waiting in the emergency department when this admission event occurs.
The events are specified in strictly increasing order of time. The number of ‘P’ and ‘A’ events will be roughly balanced.
Output
For each case, output ‘Case #X:’ in a line, where X is the case number starts from 1. For each of the admission event, output two integers separated by a single space: the current severity of the chosen patient at the admission time and that patient’s rate of increase of severity.
Sample Input
2 9 P 10 10 1 P 30 20 1 A 35 P 40 20 2 P 60 50 3 A 75 P 80 80 3 A 100 A 110 6 P 1 10 2 A 5 P 10 10 1 P 11 1 10 A 15 A 20
Sample Output
Case #1: 35 1 95 3 140 3 160 2 Case #2: 18 2 41 10 20 1

题目大意:输入t,t组样例,输入n,n个操作,接下来如果输入的是'P',那么代表此刻有人进来,如果输入的是'A,代表可以有一个病人去看病,求每次看病最严重的增加率最高的病人

思路:这里要介绍一下优先队列这个概念:优先队列可以自动按从大到小排序或者从小到大排序,取元素用p.top(),删除元素用p.pop()····,然后具体从小到大还是从大到小学习这篇博客:

https://blog.csdn.net/c20182030/article/details/70757660

具体思路看代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const int maxn=2e4+10;
const int maxk=100+10;
const int maxx=1e4+10;
const ll maxe=1000+10;
#define INF 0x3f3f3f3f3f3f
priority_queue<int>p[110];//优先队列
void init()
{for(int i=0;i<=100;i++){while(!p[i].empty())//使得队列为空//while(p[i].size())
            p[i].pop();}
}
int main()
{int t;int sum=1;cin>>t;while(t--){init();printf("Case #%d:\n",sum++);ll n,st0,t0,t1,r,id,va;char a[5];cin>>n;for(int i=1;i<=n;i++){cin>>a;if(a[0]=='P'){cin>>t0>>st0>>r;p[r].push(st0-r*t0);//注意这里为什么要这样处理,因为st=st0+(t-t0)*r····所以呢,可以得到stt=t*r; 这样的//话st就只和r有关了,不管初始大小多大,当r一样时,两者相对来说差距是不变的
            }else{cin>>t1;id=-1;va=-INF;for(int j=100;j>=0;j--)//为什么从100开始呢?因为如果va相等,优先取r更大的,题目要求
                {if(p[j].empty()) continue;// if(p[j].size()==0) continue;ll vaa=p[j].top();//这里每次都会取在r相同情况下最大的vaa,这也是优先队列的好处vaa=vaa+j*t1;if(vaa>va){va=vaa;id=j;}}p[id].pop();cout<<va<<" "<<id<<endl;}}}return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/9392288.html

UVALive - 6440相关推荐

  1. UVALive - 6440(模拟)

    题目链接:https://vjudge.net/contest/241341#problem/G 题目大意:输入一个N,n次操作.对于第一种操作增加一个病人,告诉病人的t0,st0,r.第二种操作,在 ...

  2. DP UVALive 6506 Padovan Sequence

    题目传送门 /*题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大DP:状态转移方程:dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[ ...

  3. The UVALIVE 7716 二维区间第k小

    The UVALIVE 7716 二维区间第k小 /** 题意:给一个n * n的矩阵,有q个查询每次查询r,c,s,k表示已(r,c)为右上角 大小为s的正方形中 第k小的元素n <= 250 ...

  4. UVALive 8513 lovers 2017 西安区域赛 B 贪心+multiset

    UVALive 8513 有2种人,每个人有自己的权值$A_i$ $B_i$ 当$A_i + B_i >=K$时 两个人可以配对 问最多多少人可以配对 解法 : 把$/{ A_i /}$ 排序 ...

  5. 训练指南 UVALive - 3713 (2-SAT)

    layout: post title: 训练指南 UVALive - 3713 (2-SAT) author: "luowentaoaa" catalog: true mathja ...

  6. 逆序数 UVALive 6508 Permutation Graphs

    题目传送门 1 /* 2 题意:给了两行的数字,相同的数字连线,问中间交点的个数 3 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 4 用归并排序或线段树求 ...

  7. Infinite Fraction Path UVALive - 8207

    Infinite Fraction Path UVALive - 8207 题意: 给你n个数,每个数在0到9之间,每个数的下标一次是0~n-1,然后他所能走到的数为(i^2+1)%n,i为他本身的下 ...

  8. F - Heron and His Triangle UVALive - 8206

    F - Heron and His Triangle UVALive - 8206 题意: 给你应该n,然后求一个最小的t,问长度为t-1,t,t+1所组成的三角形的面积为整数,t>=n 题解: ...

  9. Tree UVALive - 8212

    Tree UVALive - 8212 题意: 有n个点,k个颜色,每个点都要被染色,相同颜色之间的边算是被该颜色覆盖,问有多少边被所有颜色覆盖 题解: 题目给的是无根树,我们可以将1默认为根然后求所 ...

最新文章

  1. Android Studio编译问题-Error:Could not find org.jetbrains.trove4j
  2. 初步了解Telerik for WPF 控件
  3. js获取时间段内属于星期一的日期们
  4. BPM实例方案分享:表单子表自动填入数据
  5. x86服务器中网络性能分析与调优(高并发、大流量网卡调优)
  6. 更新fielddata为true_在pytorch中停止梯度流的若干办法,避免不必要模块的参数更新...
  7. java word模板替换多行_Java动态替换word模板的最佳实践
  8. 移植性问题のerror C2664: strcpy : 不能将参数 2 从 CString 转换为 const char *怎么回事?...
  9. 数据库系统基础教程(1)数据库系统世界
  10. 德勤 oracle par面,经验 | 德勤19par面合集+楼主新鲜audit par面经验
  11. 【Errors】Errors during downloading metadata for repository ‘AppStream‘:
  12. 携程后台开发笔试第二题
  13. Java常用环境配置(Maven、Mybatis、Spring、SpringMvc、Mybatis)
  14. Python练习题答案: IRR计算 - 盈利能力的评价【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战
  15. 关于框架学习的过程和启发
  16. VS2010使用DX报错 VS报错之混合模式程序集是针对“v1.1.4322”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。...
  17. 百度地图之标注物聚合
  18. JavaScript知识点4
  19. hdoj 1878 欧拉回路
  20. OA成为中国制造企业的最大挑战

热门文章

  1. idea中Terminal显示不全或不显示问题的解决办法
  2. 解决vue多个路由共用一个页面的问题
  3. 红杉中国2021企业数字化年度指南:企业如何制胜数字化浪潮?
  4. 【干货】从数字化洞察新消费趋势看数字化如何赋能企业.pdf(附下载链接)
  5. 【干货】华为管理干部内部资料:华为管理者应知应会之咨询方法论.pdf(附下载链接)...
  6. 【报告分享】德勤-教育行业发展报告(政策、资本、AI、职业教育).pdf2019年中国外卖产业调查研究报告.pdf...
  7. 简单代码大全_VBA爱好者请进:VBA代码宝概述
  8. 国外疫情严峻,口罩需求量增加,大批跨境卖家通过独立站销售防疫物资
  9. 饼状图改变数据显示位置_Tableau--饼图大作战
  10. JAVA开发面试常问问题总结4