当前位置:网站首页>【2022杭电多校5 1012题 Buy Figurines】STL的运用
【2022杭电多校5 1012题 Buy Figurines】STL的运用
2022-08-04 20:44:00 【宇智波一打七~】
题目描述

输入

输出

样例输入
1
5 3
2 4
1 3
5 1
3 4
4 2
样例输出
7
题意
有n个人去买东西,有m个窗口,每个人都有到达时间和花费时间,每个人到的时候都是挑一条人少的队排,如果有两个以上的队人最少的话就挑序号最小的队排,问多少时间的时候所有人全部买完。
思路
因为这个过程是确定性的过程,比较清晰,所以就是个模拟题,至于怎么模拟这个就需要点技巧了,如果对于每一个人都O(m)的查询每个队列的长度的话那么复杂度就太高了,所以说我们可以维护一个set,这个set里面的节点信息是每个队列的人数和标号,然后再维护一个优先队列,这个优先队列里面的每一个节点信息是时间,人的编号,出队/入队,然后是按照时间来排的,如果时间相同,那么按照先出队后入队来排,然后就是模拟的过程了,具体可以看代码
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
typedef long long LL;
typedef pair<int,int> PII;
struct Que{
LL tim;
int id,status;
bool operator<(const Que&t)const{
if(tim == t.tim) return status > t.status;
return tim > t.tim;
}
Que(LL a=0,int b=0,int c=0):tim(a),id(b),status(c){
}
};
struct mdui{
LL num;
int id;
bool operator<(const mdui&t)const{
if(num == t.num) return id < t.id;
return num < t.num;
}
mdui(LL a=0,int b=0):num(a),id(b){
}
};
mdui q[N];
priority_queue<Que> que;
PII data[N];
set<mdui> dui;
LL last[N];
int Queselect[N];
void solve(){
dui.clear();
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d%d",&data[i].first,&data[i].second);
que.push(Que(data[i].first,i,1));
}
for(int i=1;i<=m;i++){
last[i] = 0;q[i].id = i;q[i].num = 0;
dui.insert(q[i]);
}
while(que.size()){
auto t = que.top();que.pop();
LL tim = t.tim;
int id = t.id,status = t.status;
if(t.status == 0){
int x = Queselect[id];
dui.erase(mdui(q[x].num,q[x].id));
dui.insert(mdui(--q[x].num,q[x].id));
}
else{
auto x = *dui.begin();
dui.erase(x);
if(x.num == 0) last[x.id] = tim + data[id].second;
else last[x.id] += data[id].second;
q[x.id].num ++,x.num++;
Queselect[id] = x.id;
dui.insert(x);
que.push(Que(last[x.id],id,0));
}
}
LL ans = 0;
for(int i=1;i<=m;i++) ans = max(ans,last[i]);
printf("%lld\n",ans);
}
int main(){
int _;
scanf("%d",&_);
while(_--) solve();
return 0;
}
边栏推荐
- SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值试读版
- 简单理解 JS 事件循环
- About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
- 面试官:Redis中过期的key是怎么被删除的?
- Feign 与 OpenFeign
- win10终端中如何切换磁盘
- [Data Mining] Written Exam Questions for Sohu Data Mining Engineers
- [TypeScript] In-depth study of TypeScript enumeration
- C#移动OA办公系统源码(基于微信企业号)
- Unreal 本地化 国家化 多语言
猜你喜欢

Desthiobiotin-PEG4-Azide_脱硫生物素-叠氮化物 100mg

【TypeScript】深入学习TypeScript枚举

Oreo域名授权验证系统v1.0.6公益开源版本网站源码

KubeSphere简介,功能介绍,优势,架构说明及应用场景

文章复现:超分辨率网络-VDSR

Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO

Interviewer: How is the expired key in Redis deleted?

使用百度EasyDL实现森林火灾预警识别

web漏洞扫描器-awvs

for 循环中的 ++i 与 i++
随机推荐
EasyUi常用代码
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
香港暂停进口俄罗斯部分地区禽肉及禽类产品
宝塔实测-搭建中小型民宿酒店管理源码
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
如何用好建造者模式
暴雨中的人
ASP.NET商贸进销存管理系统源码(带数据库文档)源码免费分享
MySQL field type
About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
Tear down the underlying mechanism of the five JOINs of SparkSQL
经验分享|盘点企业进行知识管理时的困惑类型
win10终端中如何切换磁盘
CAS :80750-24-9(脱硫生物素 NHS 酯)
【debug】postgres数据存储错乱
Zero-knowledge proof - zkSNARK proof system
MYSQL gets the table name and table comment of the database
新式茶饮,卷完水果还能卷什么?
for 循环中的 ++i 与 i++
刷题-洛谷-P1307 数字反转