本篇内容主要讲解“如何编写代码实现外卖店优先级效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何编写代码实现外卖店优先级效果”吧!
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N=100010;
int score[N];//优先级
int last[N];
bool st[N];//是否在缓存
int n,m,T;
PII order[N];//订单二元组
int main(){
scanf("%d%d%d",&n,&m,&T);
for(int i=0;i<m;i++) scanf("%d%d", &order[i].x, &order[i].y);
sort(order,order+m);
//枚举每个订单
for(int i=0;i<m;i++){
int j=i;
while(j<m && order[i]==order[j]) j++;
int t=order[i].x,id=order[i].y,cnt=j-i;//时间 id 个数
i=j-1;
score[id] -= t-last[id]-1;
//最低减到0
if(score[id]<0) score[id]=0;
if(score[id]<=3) st[id]=false;//以上处理的是t时刻之前的信息
score[id]+=2*cnt;
if(score[id]>5) st[id]=true;
last[id]=t;
}
for(int i=1;i<=n;i++){
if(last[i]<T){
score[i]-=T-last[i];
if(score[i]<=3) st[i]=false;
}
}
int res=0;
for(int i=1;i<=n;i++) res+=st[i];
printf("%d\n",res);
return 0;
}
到此,相信大家对“如何编写代码实现外卖店优先级效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/zhengbaby66/blog/5017109