如何编写代码实现外卖店优先级效果

发布时间:2021-10-14 10:38:45 作者:iii
来源:亿速云 阅读:113

本篇内容主要讲解“如何编写代码实现外卖店优先级效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何编写代码实现外卖店优先级效果”吧!

#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;
}

到此,相信大家对“如何编写代码实现外卖店优先级效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 怎么编写直播源代码实现分栏
  2. 如何编写代码实现超级胶水

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

acwing

上一篇:SCTP一对多模式的服务器端代码怎么写

下一篇:怎么实现几个字符串常用函数

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》