• PAT 1026 Table Tennis


    1026 Table Tennis

    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:

    1. 10
    2. 20:52:00 10 0
    3. 08:00:00 20 0
    4. 08:02:00 30 0
    5. 20:51:00 10 0
    6. 08:10:00 30 0
    7. 08:12:00 10 1
    8. 20:40:00 13 0
    9. 08:01:30 15 1
    10. 20:53:00 10 1
    11. 20:54:00 10 0
    12. 3 1
    13. 2

    Sample Output:

    1. 08:00:00 08:00:00 0
    2. 08:01:30 08:01:30 0
    3. 08:02:00 08:02:00 0
    4. 08:12:00 08:16:30 5
    5. 08:10:00 08:20:00 10
    6. 20:40:00 20:40:00 0
    7. 20:51:00 20:51:00 0
    8. 20:52:00 20:52:00 0
    9. 20:53:00 20:53:00 0
    10. 4 3 2

    总结:这种题现在的实力还写不出来,还得加油,多写写题目

     

    1. #include
    2. #include
    3. #include
    4. #include
    5. using namespace std;
    6. int n, m, k, H, M, S, t, table, vtable, cnt, now, nowt, T[100000], V[100000], num[10001], AnsI[10001], AnsO[10001], vip[10001];
    7. map<int, int> Table;
    8. queue<int> Wait, vWait;
    9. int main() {
    10. scanf("%d", &n);
    11. for (int i = 0; i < n; i++) {
    12. scanf("%d:%d:%d", &H, &M, &S);
    13. t = H * 3600 + M * 60 + S;
    14. scanf("%d %d", &T[t], &V[t]);
    15. T[t] = min(T[t], 120) * 60;//因为最多只能玩两个小时,如果超出两个小时,则取两个小时
    16. }
    17. scanf("%d %d", &m, &k);
    18. for (int i = 0; i < k; i++) {
    19. scanf("%d", &t);
    20. vip[t] = 1;//vip桌
    21. }
    22. for (int Time = 28800; Time < 75600; Time++, table = vtable = now = 0) {
    23. if (T[Time] && V[Time]) vWait.push(Time);//当前时刻有人来且这个人是vip,加入vip队列中
    24. else if (T[Time]) Wait.push(Time);//当前时刻有人来,但这个人不是vip,加入普通人队列中
    25. for (int i = 1; i <= m; i++) {//遍历每一张桌子
    26. if (Table[i] > 0) Table[i]--;//当前桌子有人玩,剩余时间秒数-1
    27. if (Table[i] == 0 && vip[i] && vtable == 0) vtable = i;//当前桌子没有玩,且是vip桌,且在此桌之前的桌子vip桌都是有人的,vtable记录当前可以的编号最小的vip桌子
    28. if (Table[i] == 0 && table == 0) table = i;//当前编号桌子没有人,且在这个编号桌子之前的桌子都是有人的,table记录当前未使用的最小编号的桌子
    29. }
    30. if (!vWait.empty() && (table || vtable)) {
    31. now = vWait.front();//将队列中第一个vip叫出来
    32. nowt = vtable;//记录当前可用的最小编号的桌子
    33. if (vtable != 0) vWait.pop();//如果有vip桌子的话,那就让那个人去打
    34. else {//否则让他去打普通的桌子
    35. nowt = table;
    36. //如果当前非vip在vip排队之前,那么让队列前面的人去打
    37. if (!Wait.empty() && Wait.front() < vWait.front()) {
    38. now = Wait.front();
    39. Wait.pop();
    40. } else vWait.pop();//否则让vip去打
    41. }
    42. } else if (!Wait.empty() && table) {//没有vip,且有桌子
    43. nowt = table;
    44. now = Wait.front();
    45. Wait.pop();
    46. }
    47. if (now == 0) continue;//如果此时刻没有人来,且没有在队列当中
    48. Table[nowt] = T[now];//更新结束时间
    49. AnsI[cnt] = now;//用户到达时间
    50. AnsO[cnt++] = Time;// 用户开始玩的时间,这两个相减可以算出用户等待时间
    51. num[nowt]++;//表示当前的桌子被用过一次,+1
    52. }
    53. for (int i = 0; i < cnt; i++)
    54. printf("%02d:%02d:%02d %02d:%02d:%02d %d\n", AnsI[i] / 3600, AnsI[i] % 3600 / 60, AnsI[i] % 60, AnsO[i] / 3600, AnsO[i] % 3600 / 60, AnsO[i] % 60, (AnsO[i] - AnsI[i] + 30) / 60);
    55. for (int i = 1; i <= m; i++) {
    56. if (i != 1) printf(" ");
    57. printf("%d", num[i]);
    58. }
    59. return 0;
    60. }

     好好学习,天天向上!

    我要考研

  • 相关阅读:
    Vue 3入门指南
    【Mysql】日期函数 、group_concat函数
    Java 中已检查和未检查异常
    习题1.23
    开放式无线运动耳机哪个好,几款最好的运动耳机推荐
    阿里云服务器(Ubuntu22)上的MySQL8更改为大小写不敏感
    【JavaScript-33】js中字符串的常用方法
    云端援手:智能枢纽应对数字资产挑战 ——华为云11.11应用集成管理与创新专区优惠限时购
    1996-2023年各省农林牧渔总产值及农业、林业、牧业、渔业总产值数据(无缺失)
    Linux·IO调度机制
  • 原文地址:https://blog.csdn.net/weixin_50679551/article/details/126907356