当前位置:网站首页>[蓝桥杯][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
边栏推荐
- Gbase 8s query processing and optimization
- “自虐神器”一夜爆火:用手柄控制自己的脸,代码自取,后果自负
- 【服务器数据恢复】服务器硬盘进水后服务器崩溃的数据恢复案例
- API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
- Small example of gin - get request 1-handle handles get requests
- Gbase 8s shared memory segment deletion
- Innovative practice of short video content understanding and generation technology in meituan
- App uses the template message from WeChat official account for message push.
- Interface automation session authentication solution
- Is it difficult for girls to learn software testing?
猜你喜欢

Generating class diagram with EA reverse engineering code

"Open source summer" activity is hot. In the registration, rich bonuses are waiting for you to get!
![[Ethernet switching security] - switch flow control / DHCP snooping / IP source guard](/img/cc/bbabc5621b8485d04ffa7d4d5fad2e.png)
[Ethernet switching security] - switch flow control / DHCP snooping / IP source guard

Tdengine deployment cluster installation

京東一面:子線程如何獲取父線程 ThreadLocal 的值?我蒙了。。。

On regular expression matching cryptography

The origin explanation and use example of image pre training model
Let's talk about passive safety again. I'll teach you to understand the rating report of China Insurance Research Institute collision test

Pilotage growth · ingenuity empowerment -- yonmaster developer training and pilotage plan is fully launched

In depth report: in the heterogeneous era, chips need to integrate multiple templates
随机推荐
Detailed explanation of the usage of C language getchar
Interface automation session authentication solution
GBASE 8s 共享内存缓冲池介绍
IMX6ULL裸机开发之硬件IIC分析及配置过程
Generating class diagram with EA reverse engineering code
Project manager's thinking mode worth trying: project success equation
那些咸鱼上买来的代码|ssm酒店客房管理系统|买来的源码是否真的可以使用|来自程序员的困惑|玉念聿辉|大丑村吴明辉
The origin explanation and use example of image pre training model
Hardware SPI analysis and configuration process of imx6ull bare metal development
体育训练中心项目电力监控系统的研究与应用
8GBs communication between client and server
Huawei CDN is fast everywhere
IMX6ULL裸机开发之GPT通用定时器分析及配置过程
The complete form of smart home and the development of "small homekit"
Five commonly used order receiving platforms recommended by programmers
GBASE 8s 并发控制之封锁操作
Pilotage growth · ingenuity empowerment -- yonmaster developer training and pilotage plan is fully launched
Scope of define
GBase 8s 备份介绍
Zhang Jian of Huawei cloud IOT expert group: he has become a senior engineer of Huawei since he was 22. The code is what I want to say to the world