zoukankan      html  css  js  c++  java
  • 1026 Table Tennis (30分)

    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

    题目分析:对于顾客先进行排序 然后分析第一个空闲的桌子是不是vip的情况
    如果第一个空闲的桌子是vip,找到第一个vip会员进行讨论
    如果第一个空闲的桌子不是vip,看队列中第一个队员是否为vip 若不是直接给他,若是vip 在所有桌子中找到vip桌子进行讨论
    做这种题最最要的是分清楚情况 想的细一点对做题有帮助
      1 #define _CRT_SECURE_NO_WARNINGS
      2 #include<iostream>
      3 #include<vector>
      4 #include<queue>
      5 #include<stack>
      6 #include<algorithm>
      7 #include<string>
      8 #include<cmath>
      9 using namespace std;
     10 struct customer {
     11     int arriveTime = 0;
     12     int startTime = 0;
     13     int playtime = 0;
     14     int tag = 0;
     15 };
     16 struct table{
     17     int time = 3600 * 8;
     18     int humans=0;
     19     int flag=0;
     20 };
     21 vector<customer> Customer;
     22 vector<table>Table;
     23 bool compare(const customer& a, const customer& b)
     24 {
     25     return a.arriveTime < b.arriveTime;
     26 }
     27 bool cmp(const customer& a, const customer& b)
     28 {
     29     return a.startTime < b.startTime;
     30 }
     31 int findNextvipid(int vipid)
     32 {
     33     vipid++;
     34     while (vipid < Customer.size() && Customer[vipid].tag != 1)vipid++;
     35     return vipid;
     36 }
     37 void collect(int customerid, int tableid)
     38 {
     39     if (Customer[customerid].arriveTime < Table[tableid].time)
     40         Customer[customerid].startTime = Table[tableid].time;
     41     else
     42         Customer[customerid].startTime = Customer[customerid].arriveTime;
     43     Table[tableid].time = Customer[customerid].startTime + Customer[customerid].playtime;
     44     Table[tableid].humans++;
     45 }
     46 int main()
     47 {
     48     int N, K, MV, MC, viptable;
     49     cin >> N;
     50     customer c;
     51     for (int i = 0; i < N; i++)
     52     {
     53         int hh, mm, ss;
     54         scanf("%d:%d:%d %d %d", &hh,&mm,&ss,&(c.playtime),&(c.tag));
     55         c.arriveTime = hh * 3600 + mm * 60 + ss;
     56         c.startTime = 21 * 3600;
     57         if (c.arriveTime >= 21 * 3600)continue;
     58         c.playtime = (c.playtime < 120) ? c.playtime * 60 : 7200;
     59         Customer.push_back(c);
     60     }
     61     sort(Customer.begin(), Customer.end(), compare);
     62     cin >> K >> MV;
     63     Table.resize(K + 1);
     64     for (int i = 0; i < MV; i++)
     65     {
     66         scanf("%d", &viptable);
     67         Table[viptable].flag = 1;
     68     }
     69     int i = 0, vipid = -1;
     70     vipid = findNextvipid(vipid);
     71     while (i<Customer.size())
     72     {
     73         int index = -1, minendtime = 99999999;
     74         for (int j = 1; j <=K; j++)
     75         {
     76             if (minendtime > Table[j].time)
     77             {
     78                 minendtime = Table[j].time;
     79                 index = j;
     80             }
     81         }
     82         if (Table[index].time>= 21 * 3600)break;
     83         if (Customer[i].tag == 1 && i < vipid)
     84         {
     85             i++;
     86             continue;
     87         }
     88         if (Table[index].flag == 1)
     89         {
     90             if (Customer[i].tag == 1)
     91             {
     92                 collect(i, index);
     93                 if(vipid==i)vipid = findNextvipid(vipid);
     94                 i++;
     95             }
     96             else
     97             {
     98                 if (vipid < Customer.size() && Customer[vipid].arriveTime <= Table[index].time)
     99                 {
    100                     collect(vipid, index);
    101                     vipid = findNextvipid(vipid);
    102                 }
    103                 else
    104                 {
    105                     collect(i, index);
    106                     i++;
    107                 }
    108             }
    109         }
    110         else
    111         {
    112             if (Customer[i].tag != 1)
    113             {
    114                 collect(i, index);
    115                 i++;
    116             }
    117             else
    118             {
    119                 int vipindex = -1, minviptime = 99999999;
    120                 for (int j = 1; j <= K; j++)
    121                 {
    122                     if (Table[j].flag == 1 && Table[j].time < minviptime)
    123                     {
    124                         minviptime=Table[j].time;
    125                         vipindex = j;
    126                     }
    127                 }
    128                 if (vipindex != -1 && Customer[i].arriveTime >= Table[vipindex].time)
    129                 {
    130                     collect(i, vipindex);
    131                     if (i == vipid)vipid = findNextvipid(vipid);
    132                     i++;
    133                 }
    134                 else
    135                 {
    136                     collect(i, index);
    137                     if (i == vipid)vipid = findNextvipid(vipid);
    138                     i++;
    139                 }
    140             }
    141         }
    142     }
    143     sort(Customer.begin(), Customer.end(), cmp);
    144     for (i = 0; i < Customer.size() && Customer[i].startTime < 21 * 3600; i++) {
    145         printf("%02d:%02d:%02d ", Customer[i].arriveTime / 3600, Customer[i].arriveTime% 3600 / 60, Customer[i].arriveTime % 60);
    146         printf("%02d:%02d:%02d ", Customer[i].startTime / 3600, Customer[i].startTime % 3600 / 60, Customer[i].startTime % 60);
    147         printf("%.0f
    ", round((Customer[i].startTime - Customer[i].arriveTime) / 60.0));
    148     }
    149     for (int i = 1; i <= K; i++) {
    150         if (i != 1) printf(" ");
    151         printf("%d", Table[i].humans);
    152     }
    153 }
    View Code
  • 相关阅读:
    source命令
    [电脑配置]屏幕扩展过,找不到界面
    [SAS]方便查询Tips
    [Excel]方便查询Tips
    [SAS]运用函数等的一些问题
    [SAS]错误整理
    [SAS]易错例子之数值型转字符型
    [R]Precedence
    [sas]Missing Value
    [SAS]
  • 原文地址:https://www.cnblogs.com/57one/p/12004791.html
Copyright © 2011-2022 走看看