当前位置:网站首页>[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
边栏推荐
- Gbase 8s 并发控制之粒度锁介绍
- 深入解析Linux下的磁盘缓存机制与SSD的写入放大问题
- JD side: comment un thread enfant obtient - il la valeur de threadlocal du thread parent? Je suis couvert...
- Research and application of power monitoring system for employee apartment building construction project
- Daily practice (47): find different
- GBASE 8s分片表管理操作
- Introduction to gbase 8s storage structure and space management
- 2022 penetration job interview (thinking)
- GBASE 8s 共享内存缓冲池介绍
- 8GBs communication between client and server
猜你喜欢

New functions of ai2022, introduction to new functions of illustrator 2022

Soatest preliminary understanding

四级城市地区表 xlsx, sql文件,国内,中国省市县街道乡镇四级地址 (名称,联动ID,层级,是否末级(1-是))
Let's talk about passive safety again. I'll teach you to understand the rating report of China Insurance Research Institute collision test

Fault analysis | federated storage engine table causes the monitoring thread to be in the opening table state

Three technical solutions of ant group were selected as "typical solutions for information technology application and innovation in 2021"

Basic operation of Android local database | multi thread operation database | addition, deletion, modification and query of database | batch insertion into database | basic use of thread pool | Yu nia

DFS奇偶性剪枝

Application of acrel-3200 remote prepaid electric energy management system in Fuzhou Wanbao Industrial Park

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
随机推荐
VSCODE + PHP Debug + 名字空间指引
What is the legal basis and procedure for Tami dog sharing | state owned equity transfer?
直播软件|IPTV直播软件|电视直播|TVPlayer-IPTV-EasyPlayer|友窝直播|超级直播软件定制开发
Blocking type of gbase 8s concurrency control
Gbase 8s 共享内存段删除
GBASE 8s 并发控制之封锁操作
Activity preview | on April 23, a number of wonderful openmldb sharing came, which lived up to the good time of the weekend!
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
Introduction to PCIe xdma IP core (with list) - mingdeyang science and Education (mdy edu. Com)
.NET(C#) MySQL conn.Open()报错:SSL Connection error的解决方法
engine.POST()处理POST请求
京东一面:子线程如何获取父线程 ThreadLocal 的值?我蒙了。。。
那些咸鱼上买来的代码|ssm酒店客房管理系统|买来的源码是否真的可以使用|来自程序员的困惑|玉念聿辉|大丑村吴明辉
Rotation slice
Learning of gin framework -- golang
Analysis of uboot directory structure
Branch and loop statements
GBase8s SQL 引擎框架简介
Gbase 8s fragment table management operation
Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system