当前位置: 首页 > news >正文

1014 Waiting in Line

1014 Waiting in Line
分数 30

全屏浏览

切换布局
作者 CHEN, Yue
单位 浙江大学
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:

The space inside the yellow line in front of each window is enough to contain a line with M customers. Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line.
Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number.
Customer iwill take T i minutes to have his/her transaction processed.
The first N customers are assumed to be served at 8:00am.
Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.

For example, suppose that a bank has 2 windows and each window may have 2 customers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, customer 1 is served at window 1while customer 2 is served at window 2. Customer 3  will wait in front of window 1 and customer 4
​ will wait in front of window 2. Customer 5  will wait behind the yellow line.At 08:01, customer 1
​  is done and customer 5 enters the line in front of window 1 since that line seems shorter now. Customer 2 will leave at 08:02, customer 4  at 08:06, customer 3 at 08:07, and finally customer 5
​at 08:10.

Input Specification:
Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (≤20, number of windows), M (≤10, the maximum capacity of each line inside the yellow line), K (≤1000, number of customers), and Q (≤1000, number of customer queries).

The next line contains K positive integers, which are the processing time of the K customers.

The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.

Output Specification:
For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17] and MM is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output Sorry instead.

Sample Input:
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7

Sample Output:
08:07
08:06
08:10
17:00
Sorry

1.分析

        1.只要是17:00之前开始服务的,就必须把服务做完。

2.代码

#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int MAX=1100;
int re[MAX],queries[MAX],t[22],num=1;
int n,m,k,Q;
queue<int> q[22];
void display(int x){       //输出函数
    x=re[x];
    int hh=x/60+8;
    int mm=x%60;
    printf("%02d:%02d\n",hh,mm);
}
int main(){
    memset(re,-1,sizeof re);      //初始化结果数组
    cin>>n>>m>>k>>Q;
    for(int i=1;i<=k;i++){
        cin>>queries[i];
    }
    for(int i=0;i<540;i++){
        for(int j=1;j<=n;j++){  
            if(!q[j].empty()){          //判断是否满足出队条件
                int k=q[j].front();
                if(queries[k]+t[j]<=i){
                    q[j].pop();
                    t[j]=i;              //更新改窗口的开始服务时间
                }
            }
            if(q[j].size()<m){             //判断队列是否有空缺
                if(num<=k) q[j].push(num++);
            }
            if(!q[j].empty()){             //计算正在被服务对象的结束时间
                int k=q[j].front();
                if(re[k]==-1) re[k]=queries[k]+t[j];
            }
        }
    }
    while(Q--){           //处理询问
        int query;
        cin>>query;
        if(re[query]==-1) cout<<"Sorry"<<endl;
        else display(query);
    }
    return 0;
}

http://www.dtcms.com/a/99215.html

相关文章:

  • C++中shared_ptr 是线程安全的吗?
  • 使用 Avada 主题实现高级表单功能的技术指南
  • Day2 蓝桥杯省赛冲刺精炼刷题 —— 递归与递推
  • 浙江大学公开课|第二季|从大模型、智能体到复杂AI应用系统的构建——以产业大脑为例
  • final+模版设计模式的理解
  • [操作系统,学习记录]3.进程(2)
  • -PHP 应用文件上传函数缺陷条件竞争二次渲染黑白名单JS 绕过
  • AI大模型从0到1记录学习 day09
  • 求解AX=XB 方法
  • 车载软件刷写 --- 由擦除例程问题带来的反思
  • Java 图片压缩:高效压缩方案解析
  • 基于三维数字图像相关(DIC)技术的生物材料多尺度力学性能原位表征方法研究
  • 基于django优秀少儿图书推荐网(源码+lw+部署文档+讲解),源码可白嫖!
  • Centos安装Python3.7(亲测可用)
  • github——SSH连接配置文档
  • @Slf4j注解
  • python的内存管理
  • Knife4j 接口文档使用流程分析
  • 7.3 主成分分析(PCA)
  • Python切片中的步长秘密
  • Python 序列构成的数组(切片)
  • sqli-labs靶场 less 10
  • prometheus+grafana监控虚拟机实操
  • Windows 11 VS Code C/C++ 开发环境搭建——一种尽量“绿色”的方法
  • defconfig配置宏的规则
  • C. Assembly via Minimums
  • 一种C# Winform的UI处理
  • Python第六章18:数据容器的通用操作
  • 简单ELK框架搭建
  • 为pip设置国内镜像源