当前位置:网站首页>[蓝桥杯][2019年第十届真题]外卖店优先级
[蓝桥杯][2019年第十届真题]外卖店优先级
2022-04-23 01:21:00 【OldLeft】
“饱了么”外卖系统中维护着 N 家外卖店,编号 1∼N。每家外卖店都有一个优先级,初始时 (0时刻) 优先级都为 0。每经过 1个时间单位,如果外卖店没有订单,则优先级会减少 1,最低减到 0;而如果外卖店有订单,则优先级不减反加,每有一单优先级加 2。如果某家外卖店某时刻优先级大于 5,则会被系统加入优先缓存中;如果优先级小于等于 3,则会被清除出优先缓存。
给定 T时刻以内的 M 条订单信息,请你计算 T时刻时有多少外卖店在优先缓存中。
输入格式
第一行包含 3个整数 N,M,T。
以下 M行每行包含两个整数 ts 和 id,表示 ts 时刻编号 id的外卖店收到一个订单。
输出格式
输出一个整数代表答案。
数据范围
1≤N,M,T≤10^5,
1≤ts≤T,
1≤id≤N
输入样例:
2 6 6
1 1
5 2
3 1
6 2
2 1
6 2
输出样例:
1
样例解释
6时刻时,1 号店优先级降到 3,被移除出优先缓存;2 号店优先级升到 6,加入优先缓存。所以是有 1
家店 (2 号) 在优先缓存中。
#include<bits/stdc++.h>
using namespace std;
int n,m,T;
struct Time{
int t;//时刻
int id;//外卖店编号
}ti[100005];
struct Shop{
int pre;//上一个收到订单的时刻
int prior;//当前店的优先级
bool flag;//当前店是否在优先缓存?是:true 否:false
}s[100005];
bool cmp(Time x,Time y){
if(x.t!=y.t){
return x.t<y.t;
}else return x.id<y.id;
}
int cnt;
int main(){
cin>>n>>m>>T;
for(int i=0;i<m;i++){
cin>>ti[i].t>>ti[i].id;
}
sort(ti,ti+m,cmp);
for(int i=0;i<m;i++){
if(ti[i].t>=T+1){
break;
}
//因为一个时刻一个外卖店可能收到多份订单,所以需要判断一下
if(s[ti[i].id].pre!=ti[i].t) s[ti[i].id].prior-=(ti[i].t-s[ti[i].id].pre-1);
if(s[ti[i].id].prior<0) s[ti[i].id].prior=0;
if(s[ti[i].id].prior<=3&&s[ti[i].id].flag){
s[ti[i].id].flag=false;
}
s[ti[i].id].prior+=2;
if(s[ti[i].id].prior>5&&!s[ti[i].id].flag){
s[ti[i].id].flag=true;
}
s[ti[i].id].pre=ti[i].t;
}
for(int i=1;i<=n;i++){
if(s[i].flag){
int temp=s[i].prior-(T-s[i].pre);
if(temp<=3) s[i].flag=false;
}
}
for(int i=1;i<=n;i++){
cnt+=s[i].flag;
}
cout<<cnt<<endl;
return 0;
}
版权声明
本文为[OldLeft]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43833610/article/details/115647360
边栏推荐
- Basic knowledge of software testing (detailed version) collection of this article is enough
- In depth report: in the heterogeneous era, chips need to integrate multiple templates
- Configuration of imx6ull bare metal development analysis and configuration process of elcdif lighting RGB LCD
- 直播软件|IPTV直播软件|电视直播|TVPlayer-IPTV-EasyPlayer|友窝直播|超级直播软件定制开发
- Detailed explanation of the usage of C language getchar
- Gbase 8s客户端与服务器的通信
- IMX6ULL裸机开发之硬件IIC分析及配置过程
- How does zhiting connect Xiaomi smart speakers?
- 智能手表的下半场,机遇与挑战并存
- Ampere computing releases the computing power of observation cloud "core" and jointly promotes the development of observability
猜你喜欢
IMX6ULL裸机开发之配置eLCDIF点亮RGB液晶屏分析及配置过程
C language guessing game and trickery game
Here's the point. Have you mastered the most complete Web3 jargon guide?
Acrel-5000型建筑能耗监测系统在西咸空港花园项目的研究与应用
Android本地数据库基础操作|多线程操作数据库|数据库的增删改查|批量插入数据库|线程池基础使用|玉念聿辉
Acrel-2000型电力监控系统在兴庆坊新兴广场配电所配电回路用电的实时监控和管理
【服务器数据恢复】服务器硬盘进水后服务器崩溃的数据恢复案例
智能照明控制系统在医院的设计与应用
IMX6ULL裸机开发之硬件IIC分析及配置过程
Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
随机推荐
VRF in Mina
Hardware IIC analysis and configuration process of imx6ull bare metal development
In depth report: in the heterogeneous era, chips need to integrate multiple templates
Hardware SPI analysis and configuration process of imx6ull bare metal development
Pilotage growth · ingenuity empowerment -- yonmaster developer training and pilotage plan is fully launched
GBase 8t索引
Basic knowledge of software testing (detailed version) collection of this article is enough
Gbase 8s客户端与服务器的通信
Gbase 8s shared memory segment deletion
Gbase 8s数据库日志简介及管理
The complete form of smart home and the development of "small homekit"
What is the legal basis and procedure for Tami dog sharing | state owned equity transfer?
计蒜客:数独(DFS)
Gbase 8s检查点简介
GBASE 8s 共享内存缓冲池介绍
[actf2020 freshman competition]
Comp1011 programming solution
Introduction to gbase 8s shared memory buffer pool
The origin explanation and use example of image pre training model
GBase 8s查询处理和优化