1026. Table Tennis (30)

102 篇文章 0 订阅
37 篇文章 0 订阅

1026. Table Tennis (30)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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
这题太鬼畜了,只能说目前AC了2015-7-31.做了一整天。但是这题里面我尝试使用了各种vector的属性事件甚么的。看起来太像在写C#了。
我的思路:
先找到最先空的一个窗口/桌子获得时间M,窗口编号mindex;
一、如果当前有普通或者Vip
if(mindex这个窗口是vip窗口) 
{ if当前有vip,vip特权
     else(当前有普通)普通 
 }
else(这个窗口不是vip窗口)
     可能在窗口中有一个vip窗口与这个窗口同时结束,获取mv,失败mv=-1;
     if(获取成功,且有vip用户)用户特权
    else if(普通和vip用户同时存在,普通排在前面先)
    else if(普通和vip用户同时存在,vip排在前面先)
   else  if(只有普通,普通排)
   else if(只有vip用户,vip用户排) 

  
  
二、如果当前一个人也没有
if{ ①假如最先到的是普通的或者vip按时到的没有了,就最简单的普通人到这个mindex窗口;}
else 
假如vip中最先到,获取满足这个vip且vip窗口的id最小,获取失败mv=-1(此时保证有vip)
if ①当获取成功vip特权mv窗口
else if ②当获取失败vip普通mindex窗口 
联动 vector : http://www.cplusplus.com/reference/vector/vector/
测试样例http://blog.csdn.net/cstopcoder/article/details/24561377
2015-8-1 00:56再联动一个思路超级清楚的http://blog.csdn.net/Yangsongtao1991/article/details/43317107

1.当有多个乒乓球台空闲时,vip顾客到了会使用最小id的vip球台,而不是最小id的球台,(这一要点我在做的时候忽略了)测试以下用例:

2
10:00:00 30 1
12:00:00 30 1
5 1
3
输出正确结果应为:
10:00:00 10:00:00 0
12:00:00 12:00:00 0
0 0 2 0 0
 
2.题目要求每对顾客玩的时间不超过2小时,那么当顾客要求玩的时间>2小时的时候,应该截断控制,测试以下用例:
2
18:00:00 180 1
20:00:00 60 1
1 1
1
输出的正确结果应为:
18:00:00 18:00:00 0
20:00:00 20:00:00 0
2
3.虽然题目中保证客户到达时间在08:00:00到21:00:00之间,但是根据最后的8个case来看,里面还是有不在这个时间区间内到达的顾客,所以建议还是稍加控制,测试以下用例:(这里我贴出来的代码是只控制21:00之前(不包括21:00)的数据保留没有舍掉8:00之前,2015-8-1测试通过)
1
21:00:00 80 1
1 1
1
输出的正确结果应为:
0
4.题目中说的round up to an integer minutes是严格的四舍五入,需要如下做
wtime = (stime - atime + 30) / 60
而不是:
wtime = (stime - atime + 59) / 60(PS:这里他们写着四舍五入我没有看懂,后来看了自己的结果大了很多才想到是没有把秒换成分,然后“/”这个对于整型int 来说是取整(取整数部分))
----------------------------
3
11:25:00 10 1
11:34:00 10 1
11:35:00 10 0
10 1
7
--------------------------
11:25:00 11:25:00 0
11:34:00 11:34:00 0
11:35:00 11:35:00 0
1 1 0 0 0 0 1 0 0 0

  

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户
8月01日 00:41答案正确301026C++ (g++ 4.7.2)13628datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确130814/14
1答案正确11802/2
2答案正确14362/2
3答案正确11802/2
4答案正确13082/2
5答案正确13081/1
6答案正确11803/3
7答案正确11803/3
8答案正确136281/1
 
#include<iostream>   
#include<vector>
#include<iomanip>
#include<algorithm>
#define CloseTime 75600
#define StartTime 28800
using namespace std;  
struct  TableTennisLine
{
  int comeTime, Servetime, playTime; 
  TableTennisLine(int c,  int p) :comeTime(c), playTime(p) {}
};
struct Tables
{
  int CoUnt;
  int vacantTime;
  bool vip;
  Tables(int CoUnt, int vacantTime, bool vip) :CoUnt(CoUnt), vacantTime(vacantTime), vip(vip){}
};
int DUreadln(vector <TableTennisLine>*Vip, vector<TableTennisLine> *Ordinary, int N)
{ 
  int ss, ff, mm,play,tag,ccount;
  int index ;
  char MHc;
  for (index = 0 ,ccount=0; index < N; index++)
  {
    cin >> ss >> MHc >> ff >> MHc >> mm >> play>> tag;
    ss = ss * 3600 + ff * 60 + mm;
    if (ss < CloseTime)
    { 
      ccount++;
      play = play > 120 ? 120 : play;
      play *=60;
      tag == 1 ? (*Vip).push_back(TableTennisLine(ss, play)) : (*Ordinary).push_back(TableTennisLine(ss, play));
    }
  } 
  return ccount;
}
void ZhuoStar(vector<Tables>*Tabl, int Star, int ENd, int cc, int vacant, bool vip)
{
  while (Star++ < ENd) 
    (*Tabl).push_back(Tables(cc,vacant,vip)); 
}
void ZhuoVip(vector<Tables>*Tabl, int Star, int ENd, bool vip)
{
  int index;
  for (; Star < ENd; Star++)
  {
    cin >> index;
    index--;
    (*Tabl).operator[](index).vip= vip; 
  }
    
}
bool TABLEcmp(const TableTennisLine&A, const TableTennisLine&B)
{
  return A.comeTime < B.comeTime;
}
int first_vacnt_tables(vector<Tables> Tabl, int Star, int ENd, int *M)
{
  int vacanttemp, mindex = 0;  
  (*M) = Tabl[0].vacantTime;
  for (; Star < ENd; Star++)
  { 
    vacanttemp =Tabl[Star].vacantTime;
    if (vacanttemp < *M)
    {
      (*M) = vacanttemp;
      mindex = Star;
    } 
  }
  return mindex;
}
int vip_vacant_talbe(vector<Tables> Tabl, int Star, int ENd, int *MM)
{
  int vacanttemp, mv= -1; 
  for (; Star < ENd; Star++)
  {
    vacanttemp = Tabl[Star].vacantTime;
    if (Tabl[Star].vip&&vacanttemp <= *MM)//满足且标号最小
    {
      (*MM) = vacanttemp;
      mv = Star;
          return mv;
    }
  }
  return mv;
}
void printchild2(int timetemp)
{
  cout << setw(2) << setfill('0') << timetemp;
}
void printchild1(int timet)
{
  printchild2(timet / 3600);
  cout << ":";
  timet %= 3600;
  printchild2(timet / 60);
  cout << ":"; 
  printchild2(timet% 60);
  cout << " ";
}
void Xprint(int c, int s, int p)
{
  printchild1(c);
  printchild1(s);
  cout << (p+30)/60 << endl;
}
void GetThisTable(vector<Tables>*Tabl, int Tindex, vector <TableTennisLine>*Turn,int v)
{
  if ((*Tabl).operator[](Tindex).vacantTime > (*Turn).operator[](v).comeTime)
  {
    (*Turn).operator[](v).Servetime = (*Tabl).operator[](Tindex).vacantTime;
    (*Tabl).operator[](Tindex).vacantTime += (*Turn).operator[](v).playTime;
    (*Turn).operator[](v).playTime = (*Turn).operator[](v).Servetime - (*Turn).operator[](v).comeTime;
  }
  else
  {
    (*Turn).operator[](v).Servetime = (*Turn).operator[](v).comeTime;
    (*Tabl).operator[](Tindex).vacantTime = (*Turn).operator[](v).comeTime + (*Turn).operator[](v).playTime;
    (*Turn).operator[](v).playTime = 0;
  } 
  if ((*Turn).operator[](v).Servetime< CloseTime)
    Xprint((*Turn).operator[](v).comeTime, (*Turn).operator[](v).Servetime, (*Turn).operator[](v).playTime);
}
int main()
{     
  vector<TableTennisLine>Vip, Ordinary;
  vector<Tables>Tabl;
  int index, N, K, M, v,mindex,mv,MM,lenv,leno;
  cin >> N;
  N=DUreadln(&Vip, &Ordinary, N);
  cin >> K >> M;
  ZhuoStar(&Tabl, 0, K, 0, StartTime, false); 
  /*for (int v = 0; v < Tabl.size(); v++)
  {
    cout << Tabl[v].CoUnt << " ";
    Tabl[v].vip ? cout << "ok" : cout << "false"; cout << endl;
  }*/
  ZhuoVip(&Tabl, 0, M, true); 
  sort(Vip.begin(), Vip.end(), TABLEcmp); 
  sort(Ordinary.begin(), Ordinary.end(), TABLEcmp);
  M = StartTime;
  mindex = 0;
  lenv = Vip.size();
  leno = Ordinary.size(); 
  for (v = 0, index = 0; v + index < N&&M <CloseTime;)
  {
    mindex = first_vacnt_tables(Tabl, 1, K, &M);   
    if (M<CloseTime)
    { 
      if (leno > index&&Ordinary[index].comeTime <= M || lenv>v&&Vip[v].comeTime <= M)//当前有队伍
      {
        if (Tabl[mindex].vip)//当前是vip窗口
        {
          if (lenv>v&&Vip[v].comeTime <= M)
                    {
            GetThisTable(&Tabl, mindex, &Vip, v++);
            Tabl[mindex].CoUnt++;
            //有vip用户特权;
          }
          else
          {
            GetThisTable(&Tabl, mindex, &Ordinary, index++);
            Tabl[mindex].CoUnt++; //普通用户; 
          }
        }
        else     //当前不是vip窗口
         { 
           MM = M;
           mv = vip_vacant_talbe(Tabl, 0, K, &MM);
           if (-1 != mv&&lenv>v&&Vip[v].comeTime <= M)
           {
             GetThisTable(&Tabl, mv, &Vip, v++);
             Tabl[mv].CoUnt++;
             //有vip用户特权;
           }
           else if (leno > index&&Ordinary[index].comeTime <= M &&lenv>v&&Vip[v].comeTime <= M&&Ordinary[index].comeTime <Vip[v].comeTime )
          {
            GetThisTable(&Tabl, mindex, &Ordinary, index++);
            Tabl[mindex].CoUnt++; //有空闲窗口,普通用户先到;  
          }
          else if (leno > index&&Ordinary[index].comeTime <= M &&lenv > v&&Vip[v].comeTime <= M&&Ordinary[index].comeTime >= Vip[v].comeTime)
          {
                         GetThisTable(&Tabl, mindex, &Vip, v++);
             Tabl[mindex].CoUnt++;
            //有空闲窗口且vip窗口满,vip用户先到;
          }
          else if (leno > index&&Ordinary[index].comeTime <= M)
          { 
            GetThisTable(&Tabl, mindex, &Ordinary, index++);
            Tabl[mindex].CoUnt++; //有空闲窗口,只有普通用户;
            } 
          else 
          {
            GetThisTable(&Tabl, mindex, &Vip, v++);
            Tabl[mindex].CoUnt++;//有空闲窗口,只有vip用户;
          } 
         }
          
        } 
      else //当前无队伍
      { 
      if (leno>index&&(lenv > v&&Ordinary[index].comeTime < Vip[v].comeTime||lenv<=v))
      {
        GetThisTable(&Tabl, mindex, &Ordinary, index++); 
        Tabl[mindex].CoUnt++; //有空闲窗口,当前无vip用户;
      }
      else  
      {  
        MM = Vip[v].comeTime;
        mv = vip_vacant_talbe(Tabl, 0, K, &MM);
        if (lenv > v&&mv!=-1)
        {
          GetThisTable(&Tabl, mv, &Vip, v++);
          Tabl[mv].CoUnt++;//有空闲窗口vip窗口未满,当前无普通用户
        }
        else if (lenv > v)
        {
          GetThisTable(&Tabl, mindex, &Vip, v++);
          Tabl[mindex].CoUnt++;
          //有空闲窗口且vip窗口满,当前无普通用户;
        } 
      } 
       } 
    }
          
  }
  K--;
  for (index = 0; index < K; index++)
    cout << Tabl[index].CoUnt << " ";
  cout << Tabl[index].CoUnt << endl;
  system("pause");   
  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、付费专栏及课程。

余额充值