UVALive - 6440
题目链接: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+;
const int maxn=2e4+;
const int maxk=+;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
priority_queue<int>p[];//优先队列
void init()
{
for(int i=;i<=;i++)
{
while(!p[i].empty())//使得队列为空
//while(p[i].size())
p[i].pop();
}
}
int main()
{
int t;
int sum=;
cin>>t;
while(t--)
{
init();
printf("Case #%d:\n",sum++);
ll n,st0,t0,t1,r,id,va;
char a[];
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a;
if(a[]=='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=-;
va=-INF;
for(int j=;j>=;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 ;
}
UVALive - 6440的更多相关文章
- UVALive - 6440(模拟)
题目链接:https://vjudge.net/contest/241341#problem/G 题目大意:输入一个N,n次操作.对于第一种操作增加一个病人,告诉病人的t0,st0,r.第二种操作,在 ...
- UESTC 2016 Summer Training #6 Div.2
我好菜啊.. UVALive 6434 给出 n 个数,分成m组,每组的价值为最大值减去最小值,每组至少有1个,如果这一组只有一个数的话,价值为0 问 最小的价值是多少 dp[i][j] 表示将 前 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- BZOJ1727:[Usaco2006 Open]The Milk Queue挤奶队列
我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html 题目传送门:https://www.lydsy.com/JudgeOnl ...
- bzoj 2632 [ neerc 2011 ] Gcd guessing game —— 贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2632 官方题解:http://neerc.ifmo.ru/archive/2011/neer ...
- 51单片机的TXD、 RXD 既接了 232 又接了 485芯片 ,会导致通信失败!
51单片机的TXD. RXD 既接了 232 又接了 485 ,会导致通信失败! 下面是绘制电路板用的部分电路图: 通信现象: 1.我使用了USB-232的下载模块,把它接到P4上,发现单片机只能发送 ...
- C#设计模式(10)——组合模式
一.概念 组合模式有时候又叫做部分-整体模式,它使我们树型结构的问题中,模糊了简单元素和复杂元素的概念,客户程序可以向处理简单元素一样来处理复杂元素,从而使得客户程序与复杂元素的内部结构解耦. 二.组 ...
- 报错apachectl restart
httpd not running, trying to start(98)Address already in use: make_sock: could not bind to address [ ...
- Sharepoint 对于是否签出文件进行编辑区别
在库设置----版本控制设置 一.需要签出才能编辑 例如需要对以上通用盒进行修改时,若在“使用资源管理器中打开”粘贴文件时会提示必须先签出项目 签出文件后,再粘贴文件到文档库中,可以选择签入的版本类型 ...
- Linux服务器监控工具--Nmon介绍
一.Nmon介绍(详细请参考百度百科) 是一款分析 AIX 和 Linux 性能的免费工具,这个高效的工具可以工作于任何哑屏幕.telnet 会话.甚至拨号线路.另外,它并不会消耗大量的 CPU 周期 ...
- geneid/genesymbol/ensemblid等之间的转换
在基因注释时,难免碰到各种GENE在不同数据库之间的ID转换(例如,Ensembl ID 转Entrez ID,或者Entrez ID与GENE Symbol之间的转换).这里介绍一下常用的三个在线网 ...
- 36.浅谈DLL劫持
最近在搞内网,需要实现免杀后门,大佬推荐了dll劫持,DLL劫持后,能干很多事情,比如杀软对某些厂商的软件是实行白名单的,你干些敏感操作都是不拦截,不提示的.还有留后门,提权等等.本文主要介绍如何检测 ...
- kinect2跑高博的orbslam2的过程(仅供自己参考记录)
首先感谢高博的无私奉献!http://www.cnblogs.com/gaoxiang12/p/5161223.html 程序所在的目录为:/home/zty/catkin_ws/src/iai_ki ...