当前位置:网站首页>[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
边栏推荐
- Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
- 无关联进程间通信 —— 命名管道的创建和使用
- Redis forgets the password and resets the password
- Unity结合iTextSharp生成PDF 准备dll
- Good test data management, in the end how to do?
- 清研环境深交所上市:年营收1.8亿 市值41亿
- App uses the template message from WeChat official account for message push.
- DFS奇偶性剪枝
- What is October 24th? Why are there no senior programmers in China in their fifties and sixties, while foreigners,,, Yu Nianyu Hui take you to celebrate the 1024 programmer Festival
- 引爆炸弹(DFS)
猜你喜欢
![[course summary] Hello harmonyos series of courses, take you to zero foundation introduction](/img/65/96ff0b526cd8f507df82c80a47a35e.jpg)
[course summary] Hello harmonyos series of courses, take you to zero foundation introduction

Soatest preliminary understanding

What is October 24th? Why are there no senior programmers in China in their fifties and sixties, while foreigners,,, Yu Nianyu Hui take you to celebrate the 1024 programmer Festival

Im instant messaging development how to design a database that can support millions of concurrent users

Function encapsulation such as addition, deletion, modification and query of linked list (summary)

World reading day: 18 it books with Douban score above 9.0 are worth collecting

无关联进程间通信 —— 命名管道的创建和使用

Text justify, orientation, combine text attributes

Redis forgets the password and resets the password

Completely uninstall antidote 10? What if the antidote uninstall is not clean?
随机推荐
Introduction to gbase 8s checkpoint
Let's talk about passive safety again. I'll teach you to understand the rating report of China Insurance Research Institute collision test
直播软件|IPTV直播软件|电视直播|TVPlayer-IPTV-EasyPlayer|友窝直播|超级直播软件定制开发
代码实现发邮件---sendemails
Gbase 8s fragment table management operation
Application of safe electricity management platform in Jingbian Museum safe electricity management system
JD side: how can a child thread get the value of the parent thread ThreadLocal? I got...
Scope of define
Activity preview | on April 23, a number of wonderful openmldb sharing came, which lived up to the good time of the weekend!
Gbase 8s shared memory segment deletion
Here's the point. Have you mastered the most complete Web3 jargon guide?
gin -get请求的小示例1-Handle处理GET请求
Earth day collection: Microsoft and Intel invite you to get the green Ambassador badge and give you negative carbon emission!
Detailed explanation of Milvus 2.0 quality assurance system
GBASE 8s分片表管理操作
计蒜客家谱(dfs求直系后代数)
计蒜客:数独(DFS)
GBase 8t索引
VS+C# 实现窗体输入框默认显示灰色文字
Traversal of ladder race l2-6 tree