zoukankan      html  css  js  c++  java
  • PAT甲级——A1026 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 priviledge 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:

    9
    20:52:00 10 0
    08:00:00 20 0
    08:02:00 30 0
    20:51:00 10 0
    08:10:00 5 0
    08:12:00 10 1
    20:50:00 10 0
    08:01:30 15 1
    20:53:00 10 1
    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:50:00 20:50:00 0
    20:51:00 20:51:00 0
    20:52:00 20:52:00 0
    3 3 2
      1 #include <iostream>
      2 #include <vector>
      3 #include <algorithm>
      4 #include <cmath>
      5 using namespace std;
      6 struct person {
      7     int arrive, start, time;
      8     bool vip;
      9 }tempperson;
     10 struct tablenode {
     11     int end = 8 * 3600, num;
     12     bool vip;
     13 };
     14 bool cmp1(person a, person b) {
     15     return a.arrive < b.arrive;
     16 }
     17 bool cmp2(person a, person b) {
     18     return a.start < b.start;
     19 }
     20 vector<person> player;
     21 vector<tablenode> table;
     22 void alloctable(int personid, int tableid) {
     23     if (player[personid].arrive <= table[tableid].end)
     24         player[personid].start = table[tableid].end;
     25     else
     26         player[personid].start = player[personid].arrive;
     27     table[tableid].end = player[personid].start + player[personid].time;
     28     table[tableid].num++;
     29 }
     30 int findnextvip(int vipid) {
     31     vipid++;
     32     while (vipid < player.size() && player[vipid].vip == false) vipid++;
     33     return vipid;
     34 }
     35 int main() {
     36     int n, k, m, viptable;
     37     scanf("%d", &n);
     38     for (int i = 0; i < n; i++) {
     39         int h, m, s, temptime, flag;
     40         scanf("%d:%d:%d %d %d", &h, &m, &s, &temptime, &flag);
     41         tempperson.arrive = h * 3600 + m * 60 + s;
     42         tempperson.start = 21 * 3600;
     43         if (tempperson.arrive >= 21 * 3600) continue;
     44         tempperson.time = temptime <= 120 ? temptime * 60 : 7200;
     45         tempperson.vip = ((flag == 1) ? true : false);
     46         player.push_back(tempperson);
     47     }
     48     scanf("%d%d", &k, &m);
     49     table.resize(k + 1);
     50     for (int i = 0; i < m; i++) {
     51         scanf("%d", &viptable);
     52         table[viptable].vip = true;
     53     }
     54     sort(player.begin(), player.end(), cmp1);
     55     int i = 0, vipid = -1;
     56     vipid = findnextvip(vipid);
     57     while (i < player.size()) {
     58         int index = -1, minendtime = 999999999;
     59         for (int j = 1; j <= k; j++) {
     60             if (table[j].end < minendtime) {
     61                 minendtime = table[j].end;
     62                 index = j;
     63             }
     64         }
     65         if (table[index].end >= 21 * 3600) break;
     66         if (player[i].vip == true && i < vipid) {
     67             i++;
     68             continue;
     69         }
     70         if (table[index].vip == true) {
     71             if (player[i].vip == true) {
     72                 alloctable(i, index);
     73                 if (vipid == i) vipid = findnextvip(vipid);
     74                 i++;
     75             }
     76             else {
     77                 if (vipid < player.size() && player[vipid].arrive <= table[index].end) {
     78                     alloctable(vipid, index);
     79                     vipid = findnextvip(vipid);
     80                 }
     81                 else {
     82                     alloctable(i, index);
     83                     i++;
     84                 }
     85             }
     86         }
     87         else {
     88             if (player[i].vip == false) {
     89                 alloctable(i, index);
     90                 i++;
     91             }
     92             else {
     93                 int vipindex = -1, minvipendtime = 999999999;
     94                 for (int j = 1; j <= k; j++) {
     95                     if (table[j].vip == true && table[j].end < minvipendtime) {
     96                         minvipendtime = table[j].end;
     97                         vipindex = j;
     98                     }
     99                 }
    100                 if (vipindex != -1 && player[i].arrive >= table[vipindex].end) {
    101                     alloctable(i, vipindex);
    102                     if (vipid == i) vipid = findnextvip(vipid);
    103                     i++;
    104                 }
    105                 else {
    106                     alloctable(i, index);
    107                     if (vipid == i) vipid = findnextvip(vipid);
    108                     i++;
    109                 }
    110             }
    111         }
    112     }
    113     sort(player.begin(), player.end(), cmp2);
    114     for (i = 0; i < player.size() && player[i].start < 21 * 3600; i++) {
    115         printf("%02d:%02d:%02d ", player[i].arrive / 3600, player[i].arrive % 3600 / 60, player[i].arrive % 60);
    116         printf("%02d:%02d:%02d ", player[i].start / 3600, player[i].start % 3600 / 60, player[i].start % 60);
    117         printf("%.0f
    ", round((player[i].start - player[i].arrive) / 60.0));
    118     }
    119     for (int i = 1; i <= k; i++) {
    120         if (i != 1) printf(" ");
    121         printf("%d", table[i].num);
    122     }
    123     return 0;
    124 }
  • 相关阅读:
    sp_trace_setfilter sqlserver筛选跟踪或跟踪过滤
    sp_trace_setevent sqlserver跟踪事件及列
    通过导入虚拟电脑的方式还原centos
    sqlserver profiler 抓出来作业的代码 SQLAgent
    克隆server2008R2造成SID冲突
    sqlserver ssms ctrl+e快捷键问题
    Caffe源码解析1:Blob
    梯度下降、随机梯度下降和批量梯度下降
    Caffe CNN特征可视化
    Caffe 抽取CNN网络特征 Python
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11254672.html
Copyright © 2011-2022 走看看