首页 > 其他分享 >PAT Advanced 1026 Table Tennis(30)

PAT Advanced 1026 Table Tennis(30)

时间:2022-08-23 23:36:03浏览次数:44  
标签:00 1026 PAT int 08 Tennis vip time 20

题目描述:

A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the smallest number. If all the tables are occupied, they will have to wait in a queue. It is assumed that every pair of players can play for at most 2 hours.

Your job is to count for everyone in queue their waiting time, and for each table the number of players it has served for the day.

One thing that makes this procedure a bit complicated is that the club reserves some tables for their VIP members. When a VIP table is open, the first VIP pair in the queue will have the privilege to take it. However, if there is no VIP in the queue, the next pair of players can take it. On the other hand, if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.

Input Specification:

Each input file contains one test case. For each case, the first line contains an integer N (≤10000) - the total number of pairs of players. Then N lines follow, each contains 2 times and a VIP tag: HH:MM:SS - the arriving time, P - the playing time in minutes of a pair of players, and tag - which is 1 if they hold a VIP card, or 0 if not. It is guaranteed that the arriving time is between 08:00:00 and 21:00:00 while the club is open. It is assumed that no two customers arrives at the same time. Following the players' info, there are 2 positive integers: K (≤100) - the number of tables, and M (< K) - the number of VIP tables. The last line contains M table numbers.

Output Specification:

For each test case, first print the arriving time, serving time and the waiting time for each pair of players in the format shown by the sample. Then print in a line the number of players served by each table. Notice that the output must be listed in chronological order of the serving time. The waiting time must be rounded up to an integer minute(s). If one cannot get a table before the closing time, their information must NOT be printed.

Sample Input:

10
20:52:00 10 0
08:00:00 20 0
08:02:00 30 0
20:51:00 10 0
08:10:00 30 0
08:12:00 10 1
20:40:00 13 0
08:01:30 15 1
20:53:00 10 1
20:54:00 10 0
3 1
2

Sample Output:

08:00:00 08:00:00 0
08:01:30 08:01:30 0
08:02:00 08:02:00 0
08:12:00 08:16:30 5
08:10:00 08:20:00 10
20:40:00 20:40:00 0
20:51:00 20:51:00 0
20:52:00 20:52:00 0
20:53:00 20:53:00 0
4 3 2

算法描述:排队问题 结构体

题目大意:

k张桌子,玩家到店后总是选择编号最小的桌子。如果训练时间超过2h会被压缩成2h,如果到达时间没有球桌空闲则加入等待队列
k张桌子中m张是vip桌,如果vip桌子有空闲,而且队列里面有vip成员,那么等待队列中的第一个vip球员会到最小的vip球桌训练。如果没有vip球桌空闲,那么vip球员就当作普通人处理。
给出每个球员的到达时间、游戏时长、是否vip(1是VIP)。给出球桌数和所有vip球桌的编号,输出所有得到游戏体验的用户的到达时间、游戏开始时间、等待时长(取整数,四舍五入),营业时间为8点到21点。

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

int n, m, k; // n人数   m会员桌数    k桌数
vector<int> v; // 存储得到服务的人编号
struct player
{
    int come_time, play_rime, ser_time = 0, lea_time;// 到店时间  玩耍时间  开始游戏时间  离开时间
    int is_vip; // 1为vip
    // 重写排序函数
    bool operator< (const player& t)const
    {
        return come_time < t.come_time;
    }
}p[10010];

struct table
{
    int cnt = 0, serve = -1; //服务次数  当前服务玩家编号
    int is_vip = 0; // 0为普通桌  1为VIP桌
}t[110];

void print_time(int time)
{
    printf("%02d:%02d:%02d ", time / 3600, time % 3600 / 60, time % 60);
}

int main()
{
    cin >> n;
    for(int i = 0 ; i < n ; i ++)
    {
        int hh, mm, ss;
        scanf("%d:%d:%d %d %d", &hh, &mm, &ss, &p[i].play_rime, &p[i].is_vip);
        p[i].come_time = hh * 3600 + mm * 60 + ss; // 以秒为单位存储
        p[i].play_rime *= 60;
        if(p[i].play_rime > 7200)   p[i].play_rime = 7200;
    }
    cin >> k >> m;
    while(m --)
    {
        int x;
        cin >> x;
        t[x].is_vip = 1;
    }
    
    sort(p, p + n); // 按到店时间从小到大排序
    queue<int> q1, q2; // q1普通队列   q2会员队列
    int cursor = 0; // 当前来店玩家编号
    for(int time = 28800 ; time < 75600 ; time ++)
    {
        // 送客
        for(int i = 1 ; i <= k ; i ++)
            if(t[i].serve >= 0)
            {
                int j = t[i].serve;
                if(p[j].lea_time == time)
                    t[i].serve = -1;
            }
        // 入队
        while(cursor < n && p[cursor].come_time == time)
        { // VIP加入两个队列   普通用户加入q1
            q1.push(cursor);
            if(p[cursor].is_vip == 1)   q2.push(cursor);
            cursor ++;
        }
        // 迎客
        while(q2.size() && p[q2.front()].ser_time != 0)  q2.pop(); //先过滤已经在普通桌玩耍的VIP ser_time != 0即已经得到服务
        // 先处理VIP桌
        for(int i = 1 ; i <= k ; i ++) // 遍历所有桌子
        {
            if(!t[i].is_vip)    continue;
            if(t[i].serve < 0 && q2.size()) // VIP桌闲置 且 VIP队列有人
            { // 修改VIP桌信息:服务编号为j,服务总数增加     玩家信息:更新服务时间和离开时间  
                int j = q2.front();
                v.push_back(j);
                t[i].serve = j;
                t[i].cnt ++;
                p[j].ser_time = time;
                p[j].lea_time = time + p[j].play_rime;
                while(q2.size() && p[q2.front()].ser_time != 0)  q2.pop();
            }
        }
        // 处理普通桌
        while(q1.size() && p[q1.front()].ser_time != 0)  q1.pop();
        for(int i = 1 ; i <= k ; i ++) // 遍历所有桌子
        {
            if(t[i].serve < 0 && q1.size()) // VIP桌闲置 且 VIP队列有人
            { // 修改VIP桌信息:服务编号为j,服务总数增加     玩家信息:更新服务时间和离开时间    
                int j = q1.front();
                v.push_back(j);
                t[i].serve = j;
                t[i].cnt ++;
                p[j].ser_time = time;
                p[j].lea_time = time + p[j].play_rime;
                while(q1.size() && p[q1.front()].ser_time != 0)  q1.pop();
            }
        }
    }
    for(int x : v)
    {
        print_time(p[x].come_time);
        print_time(p[x].ser_time);
        cout << (p[x].ser_time - p[x].come_time + 30) / 60 << endl; // 四舍五入
    }
    for(int i = 1 ; i <= k ; i ++) 
    {
        cout << t[i].cnt;
        if(i != k)  cout << ' ';
    }
    return 0;
}

标签:00,1026,PAT,int,08,Tennis,vip,time,20
From: https://www.cnblogs.com/yztozju/p/16618247.html

相关文章