PAT (Advanced Level) 1014. Waiting in Line (30)

简单模拟题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
using namespace std;

struct X
{
    int st;
    int len;
    int en;
}p[1500];
queue<int>Q[25];
int n,m,k,s;

bool check()
{
    for(int i=1;i<=n;i++)
        if(!Q[i].empty()) return 1;
    return 0;
}

int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&s);
    for(int i=1;i<=k;i++) scanf("%d",&p[i].len);
    int pos;
    for(pos=1;pos<=min(k,n);pos++) { p[pos].st=480; Q[pos].push(pos); }
    for(;pos<=min(n*m,k);pos++)
    {
        int id=pos%n; if(id==0) id=n;
        Q[id].push(pos);
    }
    while(1)
    {
        if(check()==0) break;
        int Min=999999;
        for(int i=1;i<=n;i++)
        {
            if(Q[i].empty()) continue;
            int id=Q[i].front();
            Min=min(Min,p[id].st+p[id].len);
        }

        for(int i=1;i<=n;i++)
        {
            if(Q[i].empty()) continue;
            int id=Q[i].front();
            if(p[id].st+p[id].len==Min)
            {
                p[id].en=p[id].st+p[id].len;
                Q[i].pop();
                if(pos<=k) Q[i].push(pos++);
                if(!Q[i].empty()) p[Q[i].front()].st=p[id].en;
            }
        }
    }
    for(int i=1;i<=s;i++)
    {
        int id; scanf("%d",&id);
        if(p[id].st/60>=17) printf("Sorry\n");
        else printf("%02d:%02d\n",p[id].en/60,p[id].en%60);
    }
    return 0;
}
时间: 2024-10-05 16:12:14

PAT (Advanced Level) 1014. Waiting in Line (30)的相关文章

PAT (Advanced Level) 1014 Waiting in Line

题解 排队模拟.需要注意的是,如果一个人在17:00及以后还没有开始服务,这种情况才输出“Sorry”.一个人在17:00之前已经开始了服务,就算结束服务在17:00之后,这样也是没问题的. 代码 #include<bits/stdc++.h> using namespace std; const int inf = 0x7fffffff; struct node { int num,finish_time; queue<int> people; }windows[25]; boo

1014. Waiting in Line (30)——PAT (Advanced Level) Practise

题目信息: 1014. Waiting in Line (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 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 rule

PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)

1014 Waiting in Line (30 分) 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

PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列

题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个.如果有多个可选,选窗口id最小的.输出查询客户的服务结束时间. 如果客户在17点(注意是包括的!!!就在这里被坑了,一开始还以为不包括...)或者以后还没开始服务,就输出Sorry如果已经开始了,无论多长都会继续服务的. 思路:建立一个优先级队列,存储在黄线之内的所有客户.对于m*n之前的人,依此

1014. Waiting in Line (30)(模拟题)

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

1014. Waiting in Line (30)

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

PAT (Advanced Level) 1095. Cars on Campus (30)

模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<cstring> #include<stack> #include<vector> #include<iostream> using namesp

PAT (Advanced Level) 1018. Public Bike Management (30)

先找出可能在最短路上的边,图变成了一个DAG,然后在新图上DFS求答案就可以了. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; const int INF=0x7FFFFFFF; co

PAT (Advanced Level) 1076. Forwards on Weibo (30)

最短路. 每次询问的点当做起点,然后算一下点到其余点的最短路.然后统计一下最短路小于等于L的点有几个. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm>