当前位置:网站首页>[Blue Bridge Cup] [10th real topic in 2019] priority of takeout shop
[Blue Bridge Cup] [10th real topic in 2019] priority of takeout shop
2022-04-23 01:25:00 【OldLeft】
“ Are you full ” The takeout system maintains N Take away shop , Number 1∼N. Every takeaway has a priority , At the beginning (0 moment ) The priority is 0. Each pass 1 Time units , If there's no order at the takeout , The priority will be reduced 1, At least to 0; And if the takeout shop has an order , Then the priority is not decreased but increased , Every order with priority plus 2. If the priority of a takeout store is higher than 5, It will be added to the priority cache by the system ; If the priority is less than or equal to 3, Will be cleared out of the priority cache .
Given T In time M Order information , Please calculate T How many takeout stores are in the priority cache at the moment .
Input format
The first line contains 3 It's an integer N,M,T.
following M Each line contains two integers ts and id, Express ts Time number id 's take out shop received an order .
Output format
Output an integer to represent the answer .
Data range
1≤N,M,T≤10^5,
1≤ts≤T,
1≤id≤N
sample input :
2 6 6
1 1
5 2
3 1
6 2
2 1
6 2
sample output :
1
Sample explanation
6 At the moment ,1 The priority of store No. 2 is reduced to 3, Is removed from the priority cache ;2 The priority of store No 6, Add priority cache . So there is 1
stores (2 Number ) In the priority cache .
#include<bits/stdc++.h>
using namespace std;
int n,m,T;
struct Time{
int t;// moment
int id;// Takeout number
}ti[100005];
struct Shop{
int pre;// The last time an order was received
int prior;// Priority of the current store
bool flag;// Whether the current store is in priority cache ? yes :true no :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;
}
// Because a takeout store may receive multiple orders at a time , So we need to judge
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://yzsam.com/2022/04/202204230120462812.html
边栏推荐
- Live broadcast software | IPTV live broadcast software | TV live broadcast | tvplayer IPTV easyplayer | youwo live broadcast | customized development of super live broadcast software
- What is the legal basis and procedure for Tami dog sharing | state owned equity transfer?
- Common problems and solutions of crashsight access reporting
- [course summary] Hello harmonyos series of courses, take you to zero foundation introduction
- GBASE 8s并发控制之封锁类型
- gin框架的学习--golang
- 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
- 12 years of testing predecessors give you some suggestions for learning software testing
- VS+C# 实现窗体输入框默认显示灰色文字
- Workplace PUA, five sins of managers
猜你喜欢
What is the legal basis and procedure for Tami dog sharing | state owned equity transfer?
App中使用微信公众号的模版消息来进行消息推送
Activity preview | on April 23, a number of wonderful openmldb sharing came, which lived up to the good time of the weekend!
CVPR | 2022 | expressed by transformer learning multiple hypotheses! A new framework for 3D human pose estimation!
engine.POST()处理POST请求
Android本地数据库基础操作|多线程操作数据库|数据库的增删改查|批量插入数据库|线程池基础使用|玉念聿辉
Cloud native Virtualization: building edge computing instances based on kubevirt
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!
Is 2022 software testing easy to learn? How long will it take? (learning roadmap attached)
随机推荐
无关联进程间通信 —— 命名管道的创建和使用
Gbase 8s存储结构简介及空间管理
VS+C# 实现窗体输入框默认显示灰色文字
GBASE 8s分片表管理操作
Function encapsulation such as addition, deletion, modification and query of linked list (summary)
2n皇后问题
Gbase 8s 并发控制之粒度锁介绍
计蒜客(踏青)(染色块问题的DFS和BFS解法)
Generating class diagram with EA reverse engineering code
On regular expression matching cryptography
计蒜客:等边三角形(DFS)
Live broadcast software | IPTV live broadcast software | TV live broadcast | tvplayer IPTV easyplayer | youwo live broadcast | customized development of super live broadcast software
Optical cat super account password, reset optical cat to obtain super account password
gin--hello
Gbase 8s检查点简介
Scope of define
Introduction to gbase 8s shared memory buffer pool
200. Number of islands
New functions of ai2022, introduction to new functions of illustrator 2022
Introduction and management of gbase 8s database log