A1014 Waiting in Line

摘要
Title: A1014 Waiting in Line
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

A1014 Waiting in Line

  • 题意

  • 思路

    纯大模拟,先按顺序将人入队,剩余的写进缓冲队伍,枚举时间,如果时间符合了,就让那个人出队,缓冲队的入队
    如果时间超540min了,就不能从缓冲区进人了,最后剩余的都打上sorry

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    /*
    * @Author: NEFU AB-IN
    * @Date: 2022-09-03 17:46:21
    * @FilePath: \GPLT\A1014\A1014.cpp
    * @LastEditTime: 2022-09-03 21:04:44
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define N n + 100
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr)
    #define DEBUG(X) cout << #X << ": " << X << '\n'
    typedef pair<int, int> PII;

    signed main()
    {
    IOS;
    int n, m, k, q, x;
    cin >> n >> m >> k >> q;

    queue<PII> g[N], p; // g表示窗口, p代表候补处
    vector<int> time(N), ans(k + 10);
    // time 每个窗口累计时间
    // ans 结果
    int id = 0;
    while (true)
    {
    if (!k)
    break;
    if (SZ(g[0]) >= m)
    {
    while (k--)
    {
    cin >> x;
    p.push({++id, x});
    }
    break;
    }
    for (int j = 0; j < n; ++j)
    {
    if (k)
    {
    cin >> x;
    g[j].push({++id, x}); // 编号,时间
    k--;
    }
    }
    }
    for (int i = 1; i <= 1000; ++i)
    { // 枚举分钟
    for (int j = 0; j < n; ++j)
    { // 枚举窗口
    if (SZ(g[j]))
    {
    auto tp = g[j].front();
    int id = tp.first, t = tp.second;
    if (i == t + time[j])
    {
    g[j].pop();
    ans[id] = i;
    time[j] += t;

    if (i >= 540)
    {
    while (SZ(g[j]))
    {
    auto tp = g[j].front();
    ans[tp.first] = -1; // 超时了
    g[j].pop();
    }
    }

    if (i < 540 && SZ(p))
    {
    g[j].push(p.front());
    p.pop();
    }
    }
    }
    }
    }

    for (int i = 0; i < n; ++i)
    { // 处理窗口剩余情况
    while (SZ(g[i]))
    {
    auto tp = g[i].front();
    ans[tp.first] = -1; // 超时了
    g[i].pop();
    }
    }

    while (SZ(p))
    {
    auto tp = p.front();
    ans[tp.first] = -1; // 超时了
    p.pop();
    }

    while (q--)
    {
    int x;
    cin >> x;
    int t = ans[x];
    if (t == -1)
    {
    printf("Sorry\n");
    continue;
    }

    int h = t / 60, m = t % 60;
    printf("%02lld:%02lld\n", 8 + h, m);
    }

    return 0;
    }
使用搜索:谷歌必应百度