当前位置:网站首页>[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;
}
边栏推荐
猜你喜欢
随机推荐
QT(41)-多线程-QTThread-同步QSemaphore-互斥QMutex
深度解析:为什么跨链桥又双叒出事了?
MySQL stored procedure introduction, creation, case, delete, view "recommended collection"
WIN10系统如何开启终端
【随记】新一天搬砖 --20220727
How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?
宝塔实测-搭建中小型民宿酒店管理源码
结构体小结
mysql的存储过程介绍、创建、案例、删除、查看「建议收藏」
Getting Started with Lattice Passwords
Five Minutes Introductory Text Processing Three Musketeers grep awk sed
matlab 画图
ts集成和使用
后缀式的计算
win10终端中如何切换磁盘
Apache服务器配置多个站点
idea2021版本添加上一步和下一步操作到工具栏
2022-8-4 第七组 ptz 锁与线程池和工具类
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
idea源码无法下载