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

题目大意:

一个乒乓球俱乐部有N个可供公众使用的桌子。桌子的编号从1到N。对于任意一对玩家,如果在他们到达的时候一些桌子是空着的,那么他们将被分到编号小的桌子上。如果所有的桌子都被占用着,那么他们必须排队等候。假设每对选手玩的时间不会超过2个小时。
你的任务是计算出每个人排队等待的时间,和一天中每个桌子上玩家的数量。
有一件事情让这个过程有点复杂,那就是俱乐部为他们的VIP会员准备了一些桌子。当VIP桌子时空着的时候,队列中的一对VIP会员将优先使用。然而如果队列中没有VIP会员,则下一对玩家将会使用。另一方面,如果轮到VIP会员但没有VIP桌子可用,那么他们将和普通玩家一样分配桌子。
输入规格:
每个输入文件包含一个测试用例。对于每个测试用例,第一行包含一个整数N(<=10000)-代表玩家的对数。接下来是N行,每行包括2个时间和一个VIP标签:HH:MM:SS - 代表到达时间,P-代表一对玩家玩多少分钟,标签-如果是1代表拥有VIP卡,如果是0则没有。保证到达时间在08:00:00和21:00:00俱乐部是开放的。假设没有两个客户同时到达。根据玩家信息,有两个整数:K(<=100)-桌子的数量。M(<K)-VIP桌子的数量。最后一行包含M个数字。
输出规范:
对于每个测试用例,首先打印到达时间、服务时间和每对参与者的等待时间。然后在一行中打印每个桌子所服务的玩家的数量。注意必须按开始服务的时间顺序输出。等待时间必须被四舍五入到整分钟。如果一对玩家不能在俱乐部关闭之前得到一个桌子,那么它们的信息就不能被打印出来。

代码:

#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
struct player
{
    int arrivetime;
    int starttime;
    int servetime;
    int waittime;
    int vip;
};
struct table
{
    int vip;
    int vacanttime;
    int cnt;
}tab[110];
vector<player> ordinaryplayer;
vector<player> vipplayer;
vector<player> allplayer;

bool cmpplayer(player a,player b)
{
    return a.arrivetime<b.arrivetime;
}
bool cmpall(player a,player b)
{
    return a.starttime<b.starttime;
}
int main()
{
    int i,j,n,m,k,t,h,s,w,v;
    player temp;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d:%d:%d %d %d",&h,&m,&s,&w,&v);
        temp.arrivetime=h*60*60+m*60+s;
        if(w>120)
        {
            w=120;
        }
        temp.servetime=w*60;
        temp.vip=v;
        if(temp.arrivetime>=3600*21)
        {
            continue;
        }
        if(v==1)
        {
          vipplayer.push_back(temp);
        }
        else
        {
            ordinaryplayer.push_back(temp);
        }
    }
    if(vipplayer.size()!=0)
    {
        sort(vipplayer.begin(),vipplayer.end(),cmpplayer);
    }
    if(ordinaryplayer.size()!=0)
    {
        sort(ordinaryplayer.begin(),ordinaryplayer.end(),cmpplayer);
    }
    scanf("%d %d",&k,&m);
    for(i=1;i<=k;i++)
    {
        tab[i].vacanttime=8*60*60;
    }
    for(i=0;i<m;i++)
    {
        scanf("%d",&t);
        tab[t].vip=1;
    }
    while(vipplayer.size()!=0||ordinaryplayer.size()!=0)
    {
      int mintime=1<<30;
      int index;
      int vipmintime=1<<30;
      int vipindex;
      for(i=1;i<=k;i++)
      {
          if(mintime>tab[i].vacanttime)
          {
              mintime=tab[i].vacanttime;
              index=i;
          }
          if(tab[i].vip==1&&vipmintime>tab[i].vacanttime)
          {
              vipmintime=tab[i].vacanttime;
              vipindex=i;
          }
      }
      if(tab[index].vacanttime>=21*3600)
      {
          break;
      }
      player nextplayer;
      if(vipplayer.size()==0)
      {
          nextplayer=ordinaryplayer.front();
          ordinaryplayer.erase(ordinaryplayer.begin());
      }
      else if(ordinaryplayer.size()==0)
      {
          nextplayer=vipplayer.front();
          vipplayer.erase(vipplayer.begin());
      }
      else
      {
          if(tab[index].vip==1)
          {
              if((vipplayer.front().arrivetime<ordinaryplayer.front().arrivetime)||tab[index].vacanttime>=vipplayer.front().arrivetime)
              {
                  nextplayer=vipplayer.front();
                  vipplayer.erase(vipplayer.begin());
              }
              else
              {
                  nextplayer=ordinaryplayer.front();
                  ordinaryplayer.erase(ordinaryplayer.begin());
              }
          }
          else
          {
              if(vipplayer.front().arrivetime<ordinaryplayer.front().arrivetime)
              {
                  nextplayer=vipplayer.front();
                  vipplayer.erase(vipplayer.begin());
              }
              else
              {
                  nextplayer=ordinaryplayer.front();
                  ordinaryplayer.erase(ordinaryplayer.begin());
              }
          }
      }
      if(nextplayer.vip==1&&nextplayer.arrivetime>=tab[vipindex].vacanttime)
      {
          nextplayer.waittime=0;
          tab[vipindex].vacanttime=nextplayer.arrivetime+nextplayer.servetime;
          nextplayer.starttime=nextplayer.arrivetime;
          tab[vipindex].cnt++;
      }
      else
      {
          if(tab[index].vacanttime<=nextplayer.arrivetime)
      {
          nextplayer.waittime=0;
          tab[index].vacanttime=nextplayer.arrivetime+nextplayer.servetime;
          nextplayer.starttime=nextplayer.arrivetime;
      }
      else
      {
          nextplayer.waittime=tab[index].vacanttime-nextplayer.arrivetime;
          nextplayer.starttime=tab[index].vacanttime;
          tab[index].vacanttime+=nextplayer.servetime;

      }
      tab[index].cnt++;
      }
      allplayer.push_back(nextplayer);
    }
    sort(allplayer.begin(),allplayer.end(),cmpall);
    int ahour,aminute,asecond,shour,sminute,ssecond,wait;
    for(i=0;i<allplayer.size();i++)
    {
        ahour=allplayer[i].arrivetime/3600;
        aminute=(allplayer[i].arrivetime/60)%60;
        asecond=allplayer[i].arrivetime%60;
        shour=allplayer[i].starttime/3600;
        sminute=(allplayer[i].starttime/60)%60;
        ssecond=allplayer[i].starttime%60;
        wait=allplayer[i].waittime/60;
        if(allplayer[i].waittime%60>=30)
            wait++;
        printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",ahour,aminute,asecond,shour,sminute,ssecond,wait);
    }
    for(i=1;i<=k;i++)
    {
        if(i==1)
        {
            printf("%d",tab[i].cnt);
        }
        else
        {
           printf(" %d",tab[i].cnt);
        }
    }
    printf("\n");
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The following is the data that you can add to your input file (as an example). Notice that the first line is going to be a line representing your own hobbies. In my case, it is the Vitaly,table tennis,chess,hacking line. Your goal is to create a class called Student. Every Student will contain a name (String) and an ArrayList<String> storing hobbies. Then, you will add all those students from the file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here is an example file containing students (the first line will always represent yourself). NOTE: eventually, we will have a different file containing all our real names and hobbies so that we could find out with how many people each of us share the same hobby. Vitaly,table tennis,chess,hacking Sean,cooking,guitar,rainbow six Nolan,gym,piano,reading,video games Jack,cooking,swimming,music Ray,piano,video games,volleyball Emily,crochet,drawing,gardening,tuba,violin Hudson,anime,video games,trumpet Matt,piano,Reading,video games,traveling Alex,swimming,video games,saxophone Roman,piano,dancing,art Teddy,chess,lifting,swimming Sarah,baking,reading,singing,theatre Maya,violin,knitting,reading,billiards Amy,art,gaming,guitar,table tennis Daniel,video games,tennis,soccer,biking,trumpet Derek,cooking,flute,gaming,swimming,table tennis Daisey,video games,guitar,cleaning,drawing,animated shows,reading,shopping Lily,flute,ocarina,video games,baking Stella,roller skating,sudoku,watching baseball,harp Sophie,viola,ukulele,piano,video games
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值