• PAT1026


    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1026

    注意几点:1.21点包括21点来的都不给服务。 2.最多玩2小时    

    特别注意几点: 1.if there are some tables open when they arrive, they will be assigned to the available table with the smallest number. 与  if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.  就是当有普通桌子 和  vip桌子同时 空闲时, vip优先选vip桌子!

    2.   The waiting time must be rounded up to an integer minute(s).   这里指的四舍五入(最后一个case就是这个坑)。3.注意处理关了门,但是还没玩完的。

      1 #include<iostream>
      2 #include<vector>
      3 #include<string>
      4 #include<queue>
      5 #include<algorithm>
      6 using namespace std;
      7 
      8 struct Players
      9 {
     10     string arrivetime;
     11     string servingtime;
     12     int playingtime;
     13     int vip;
     14 };
     15 
     16 struct Tables
     17 {
     18     int vip;
     19     int servednums;
     20     queue<Players> table;
     21 }t1={0,0};
     22 
     23 bool comp(Players p1, Players p2)
     24 {
     25     if(p1.arrivetime < p2.arrivetime)
     26         return true;
     27     else
     28         return false;
     29 }
     30 
     31 bool comp1(Players p1, Players p2)
     32 {
     33     if(p1.servingtime < p2.servingtime)
     34         return true;
     35     else
     36         return false;
     37 }
     38 
     39 int date2second(string end, string start)
     40 {
     41     int hh(0), mm(0), ss(0);
     42     for(int i=0; i<3; ++i)
     43          if(i == 0)     
     44          { 
     45              ss = (end[6]-start[6])*10 + (end[7]-start[7]);
     46              if(ss < 0 )
     47              {--mm; ss +=60;}
     48          }
     49          else if(i == 1)
     50          {
     51              mm += (end[3]-start[3])*10 + (end[4]-start[4]);
     52              if(mm < 0)
     53                  {--hh; mm+=60;}        
     54          }
     55          else
     56              hh +=  (end[0]-start[0])*10 + (end[1]-start[1]);
     57     int sec = hh*3600+mm*60+ss;
     58     if(sec%60 == 0)
     59         return sec/60;
     60     else if(sec%60 >= 30)
     61         return sec/60 +1;
     62     else
     63         return sec/60;
     64     /*两个时间点之间差的时间, sec秒数*/
     65 }
     66 
     67 /*时间加1秒 然后返回string*/
     68 string plus1ss(string s)
     69 {
     70     s[7] = (char)((s[7]-'0'+1) + '0');
     71     if(s[7] > '9')
     72     {
     73         s[7] ='0';
     74         s[6] = (char)((s[6]-'0'+1) + '0');
     75     }
     76     if(s[6] == '6')
     77     {
     78         s[6] = '0';
     79         s[4] = (char)((s[4]-'0'+1) + '0');
     80     }
     81     if(s[4] > '9')
     82     {
     83         s[4] ='0';
     84         s[3] = (char)((s[3]-'0'+1) + '0');
     85     }
     86     if(s[3] == '6')
     87     {
     88         s[3] = '0';
     89         s[1] = (char)((s[1]-'0'+1) + '0');
     90     }
     91     if(s[1] > '9')
     92     {
     93         s[1] = '0';
     94         s[0] = (char)((s[0]-'0'+1) + '0');
     95     }
     96     return s;
     97 }
     98 
     99 int main()
    100 {
    101     int N;
    102     while(cin>>N)
    103     {
    104         queue<Players> ordinary;
    105         queue<Players> vip;
    106         vector<Players> temp;
    107         for(int i=0; i<N; ++i)
    108         {
    109             string at; int pt, tag;
    110             cin>>at>>pt>>tag;
    111             if(at < "21:00:00" && at >= "08:00:00")
    112             {
    113                 if(pt > 120)
    114                     pt = 120*60;
    115                 else
    116                     pt = pt*60;
    117                 Players p={at, "", pt, tag};
    118                 temp.push_back(p);
    119             }
    120         }
    121         sort(temp.begin(), temp.end(), comp);
    122         for(int i=0; i<temp.size(); ++i)
    123             if(temp[i].vip == 0)
    124                 ordinary.push(temp[i]);
    125             else
    126                 vip.push(temp[i]);
    127         int K, M; cin>>K>>M;
    128         vector<Tables> tb(K, t1);
    129 
    130         for(int i=0; i<M; ++i)
    131         {
    132             int a; cin>>a;
    133             tb[a-1].vip = 1;
    134         }
    135         temp.clear();
    136         string time("08:00:00");
    137         while(time < "21:00:00" )
    138         {
    139             /*先遍历下,给vip分配桌子*/
    140             for(int i=0; i<tb.size(); ++i)
    141                 if(tb[i].table.empty() && tb[i].vip == 1 && !vip.empty() && vip.front().arrivetime <= time)
    142                 {
    143                     vip.front().servingtime = time;
    144                     tb[i].table.push(vip.front());
    145                     vip.pop();
    146                 }
    147             /*普通分配*/
    148             for(int i=0; i<tb.size(); ++i)
    149                 if(tb[i].table.empty())
    150                     if(!vip.empty() && !ordinary.empty())
    151                     {
    152                         if(vip.front().arrivetime < ordinary.front().arrivetime && vip.front().arrivetime <= time)
    153                         {
    154                                 vip.front().servingtime = time;
    155                                 tb[i].table.push(vip.front());
    156                                 vip.pop();
    157                         }
    158                         else if(ordinary.front().arrivetime <= time)
    159                         {
    160                                 ordinary.front().servingtime = time;
    161                                 tb[i].table.push(ordinary.front());
    162                                 ordinary.pop();
    163                         }
    164                     }
    165                     else if(vip.empty() && !ordinary.empty())
    166                     {
    167                         if(ordinary.front().arrivetime <= time)
    168                             {
    169                                  ordinary.front().servingtime = time;
    170                                 tb[i].table.push(ordinary.front());
    171                                 ordinary.pop();
    172                             }
    173                     }
    174                     else if(!vip.empty() && ordinary.empty())
    175                     {
    176                         if(vip.front().arrivetime <= time)
    177                             {
    178                                 vip.front().servingtime = time;
    179                                 tb[i].table.push(vip.front());
    180                                 vip.pop();
    181                             }
    182                     }
    183             time = plus1ss(time);
    184             for(int i=0; i<tb.size(); ++i)
    185                 if(!tb[i].table.empty())
    186                     if(--tb[i].table.front().playingtime == 0)
    187                     {
    188                         temp.push_back(tb[i].table.front());
    189                         tb[i].table.pop();
    190                         ++tb[i].servednums;
    191                     }
    192         }
    193         /*处理关了门,但是还没玩完的*/
    194         for(int i=0; i<tb.size(); ++i)
    195             if(!tb[i].table.empty())
    196             {    
    197                 temp.push_back(tb[i].table.front());
    198                 ++tb[i].servednums;
    199             }
    200         sort(temp.begin(), temp.end(), comp1);
    201         for(int i=0; i<temp.size(); ++i)
    202             cout<<temp[i].arrivetime<<" "<<temp[i].servingtime<<" "
    203             <<date2second(temp[i].servingtime, temp[i].arrivetime)<<endl;
    204         for(int i=0; i<tb.size()-1; ++i)
    205             cout<<tb[i].servednums<<" ";
    206         cout<<tb[tb.size()-1].servednums<<endl;
    207     }
    208     return 0;
    209 }
  • 相关阅读:
    浏览器的同源策略及跨域解决方案
    前端开发工具系列
    初始Vue
    form表单组件
    聚合和分组F,Q和事物,cookie,session
    js循环找id
    div模拟textarea文本域轻松实现高度自适应
    prototype原型
    Javascript异步编程方法
    js中map、filter用法
  • 原文地址:https://www.cnblogs.com/bochen-sam/p/3375136.html
Copyright © 2020-2023  润新知