PAT_A 1026. Table Tennis (30模拟)

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

  • 分析:这道题做的真累!
    • 主要是有几个条件不明。条件太多。
      • they will be assigned to the available table with the smallest number.我们在安排桌子时要按照从小到达安排。安排vip桌子时也是从小开始。
      • 如果没有vip桌子可用,那要用普通桌子。
      • It is assumed that every pair of players can play for at most 2 hours.玩的时间最多2小时,超过2h,需要我们截取。pat_a 4号(第5个)测试点。牛客网有一个138人的测试点。
      • The waiting time must be rounded up to an integer minute(s). 最后输出时间,取整(round不是直接舍去多余的小数,直接进一个么!不是向上取整么!),要四舍五入到分。pat最后一个一分的测试点。牛客网没有这个测试点。
      • Notice that the output must be listed in chronological order of the serving time.输出按服务时间的先后顺序排。
      • 开放时间 8:00-21:00
    • 设计思路
      按时间轴开始,排序后的用户(到达顺序)—>处理(1、不需要等待,直接处理 2、需要等待,要寻找结束最早的桌子,时间轴为桌子)–>如果遇到vip,校正用户,时间轴为用户。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
struct _T
{
  int b;
  int p;
  int w;
  int v;
  int flag;
  int c;//table
};
int N;
int K;
int M;
vector<_T>in;
vector<_T>table;//只使用b,v
_T tmp_t;
int getVip(long int a,long int b)
{
  for(int i=b;i<N;i++)
  {
    if(in.at(i).flag>0)
      continue;
     if(in.at(i).b<=a)
     {
      if(in.at(i).v==1)
        return i;
     }else
     return -1;
  }
  return -1;
}
//按服务时间排序
bool isSmall(_T a,_T b)
{
  if(a.b+a.w<b.b+b.w)
    return true;
  else if(a.b+a.w==b.b+b.w)
  {
    if(a.v==1&&b.v==0)
      return true;
  }
  return false;
}
void  outputT(int a)
{
  int h=a/3600;
  int m=(a/60)%60;
  int s=a%60;
  printf("%02d:%02d:%02d",
        h,m,s);
}
int main()
{
  cin>>N;
  int h,m,s;
  tmp_t.w=0;
  tmp_t.flag=0;
  tmp_t.c=0;
  for(int i=0;i<N;i++)
  {
    scanf("%02d:%02d:%02d %d %d",
          &h,&m,&s,&tmp_t.p,&tmp_t.v);
    if(tmp_t.p>120)
      tmp_t.p=120;
    tmp_t.b=h*3600+m*60+s;
    tmp_t.p*=60;
    in.push_back(tmp_t);
  }
  cin>>K>>M;
  tmp_t.b=8*3600;
  tmp_t.v=0;
  table.assign(K,tmp_t);
  int v;
  for(int i=0;i<M;i++)
  {
    cin>>v;
    table.at(v-1).v=1;
  }
  //sort in
  sort(in.begin(),in.end(),isSmall);
  for(int i=0;i<N;i++)
  {
    if(in.at(i).flag==1)
      continue;
    if(in.at(i).b>=21*3600)
    {
      in.at(i).flag=2;
       continue;
    }
    //get table avalible
    int vj=-1;
    int vjj=-1;
    //+++++++++++++++++++++++++++++++++++++++++++++++++++1
    for(int j=0;j<K;j++)
    {
      //找到不需要等待,直接可以用的桌子,从小号开始
      /*
      if(table.at(j).b<=in.at(i).b)//wait
      {
      //这样合有个问题,就是没有vip桌子,但有普通桌子时,vj会显示没有桌子可用,还是分开吧
        if(in.at(i).v==1)
          if(table.at(j).v==1){vj=j;break;}
        else{  vj=j;break;}
      }
      */
      if(table.at(j).b<=in.at(i).b)//wait
      {
          vj=j;
          break;
      }
    }
    for(int j=0;j<K;j++)
    {
      if(table.at(j).b<=in.at(i).b)//wait
      {
        if(table.at(j).v==1)
        {
          vjj=j;
          break;
        }
      }
    }
    if(in.at(i).v==1)
    {
      //有vip桌子可用,没有时就是用普通桌子
      if(vjj>-1)
        vj=vjj;
    }
    //+++++++++++++++++++++++++++++++++++++++++++++++++++2
    //get min table
    /*所有的table时间小于用户到达时间时vj==-1,需要选择最小的table,这是是按table时间*/
    if(vj==-1)
    {
      vj=0;
      int tmp=table.at(0).b;
      for(int j=0;j<K;j++)
      {
        if(tmp>table.at(j).b)
        {
          vj=j;
          tmp=table.at(j).b;
        }
      }

    }
    int vi=-1;
    if(table.at(vj).b>=21*3600)
      break;

    //+++++++++++++++++++++++++++++++++++++++++++++++++++3
    int vip_pre=getVip(table.at(vj).b,i);
    //等待的人员有vip
    if(vip_pre>=0)
    {
      //找合适的vip桌子,从小号开始
      int tmp_vip=table.at(vj).b;
      for(int j=0;j<K;j++)
      {
        if(table.at(j).v==1&&table.at(j).b<=table.at(vj).b)
        {
          vj=j;
          break;
        }
      }
    }
    table.at(vj).c++;
    if(table.at(vj).v==1)vi=vip_pre;

    if(vi<=0)vi=i;
    else i--;//如果是找到vip,则需要校正等待人员

    in.at(vi).flag=1;
    if(table.at(vj).b<in.at(vi).b)//dont wait
    {
      in.at(vi).w=0;
      table.at(vj).b=in.at(vi).b;//更新服务时间
    }else   
      in.at(vi).w=table.at(vj).b-in.at(vi).b;
    //更新为服务结束时间
    table.at(vj).b+=in.at(vi).p;
  }

  //按服务时间排序
  sort(in.begin(),in.end(),isSmall);
  for(int i=0;i<in.size();i++)
  {
    if(in.at(i).flag!=1)
      continue;
    outputT(in.at(i).b);
    cout<<" ";
    outputT(in.at(i).b+in.at(i).w);
    //按满30进位
    if(in.at(i).w%60>=30)
      cout<<" "<<in.at(i).w/60+1<<endl;
    else
      cout<<" "<<in.at(i).w/60<<endl;
  }

  for(int i=0;i<K-1;i++)
    cout<<table.at(i).c<<" ";
  cout<<table.at(table.size()-1).c<<endl;
  return 0;
}

  • output
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
select distinct a.EMPI_ID, a.PATIENT_NO, a.MR_NO, a.PAT_NAME, a.PAT_SEX, a.PAT_AGE, a.PAT_PHONE_NO, b.DIAG_RESULT, a.ADMIT_DATE, a.DISCHARGE_DEPT_NAME, a.ATTEND_DR from BASIC_INFORMATION a join PA_DIAG b on a.MZZY_SERIES_NO=b.MZZY_SERIES_NO join EXAM_DESC_RESULT_CODE c on a.MZZY_SERIES_NO=c.MZZY_SERIES_NO join DRUG_INFO d on a.MZZY_SERIES_NO=d.MZZY_SERIES_NO join EMR_CONTENT e on a.MZZY_SERIES_NO=e.MZZY_SERIES_NO JOIN TEST_INFO A17 ON a.MZZY_SERIES_NO = A17.MZZY_SERIES_NO where a.PAT_AGE>='18' and (to_char(a.ADMIT_DATE,'YYYY-MM-DD') >= '2021-01-01') AND (b.DIAG_RESULT LIKE '%鼻咽癌%' or b.DIAG_RESULT LIKE '%鼻咽恶性肿瘤%' or b.DIAG_CODE LIKE '%C11/900%') and d.DRUG_NAME not in (select DRUG_NAME FROM DRUG_INFO WHERE DRUG_NAME like '卡培他滨') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%HIV阳性%') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%充血性心力衰竭%') AND to_char(( A17.TEST_DETAIL_ITEM_NAME = '中性粒细胞' AND A17.TEST_RESULT >= 1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血小板' AND A17.TEST_RESULT >= 100 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血红蛋白' AND A17.TEST_RESULT >= 9 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '丙氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '天门冬氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐清除率' AND A17.TEST_RESULT > 51 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐' AND A17.TEST_RESULT <=1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '凝血酶原时间' AND A17.TEST_RESULT <= 1.5 ))语句哪里有问题
最新发布
06-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值