当前位置:网站首页>[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
2022-08-04 20:55:00 【Uchiha one hit seven~】
题目描述

输入

输出

样例输入
1
5 3
2 4
1 3
5 1
3 4
4 2
样例输出
7
题意
有npersonal shopping,有m个窗口,Everyone has time to arrive and time to spend,When everyone arrives, they pick a queue with fewer people,If there are two or more teams with the least number of people, the team with the lowest sequence number is selected,When I ask how long it takes, everyone buys it all.
思路
Because this process is a deterministic process,比较清晰,So it's a simulation,As for how to simulate this requires a little skill,If for everyoneO(m)The complexity of querying the length of each queue is too high,So say we can maintain oneset,这个setThe node information inside is the number and label of each queue,Then maintain a priority queue,The information of each node in this priority queue is the time,人的编号,出队/入队,Then it's sorted by time,如果时间相同,Then, queue up according to the first out of the queue and then in the queue,Then there is the simulation process,具体可以看代码
#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;
}
边栏推荐
猜你喜欢

【TypeScript】深入学习TypeScript枚举

搭建MyCat2一主一从的MySQL读写分离

WIN10系统如何开启终端
![[Data Mining] Written Exam Questions for Sohu Data Mining Engineers](/img/d9/450eeecd5c7835d40ac38da41fc08e.png)
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers

阿里的arthas使用,入门报错:Unable to attach to 32-bit process running under WOW64

【2022杭电多校5 1012题 Buy Figurines】STL的运用

【2022牛客多校5 A题 Don‘t Starve】DP

【2022杭电多校5 1003 Slipper】多个超级源点+最短路

STP --- 生成树协议

QT(42)-QT线程-线程调用槽函数
随机推荐
大资本已开始逃离加密领域?
[21天学习挑战赛——内核笔记](二)——设备树基础
【2022杭电多校5 1012题 Buy Figurines】STL的运用
顺序队列
阿里的arthas使用,入门报错:Unable to attach to 32-bit process running under WOW64
linkboy 5.0 正式发布,新增语音识别、图像识别
该如何训练好深度学习模型?
dotnet 使用 lz4net 压缩 Stream 或文件
暴雨中的人
文章复现:超分辨率网络-VDSR
Web3安全风险令人生畏,应该如何应对?
链队
adb控制常用命令
WIN10系统如何开启终端
微信小程序云开发 | 赠、删、改城市名称信息的应用实现
for 循环中的 ++i 与 i++
jekyll 在博客添加流程图
构建Buildroot根文件系统(I.MX6ULL)
后缀式的计算
mdk5.14无法烧录