PAT-A-1026. Table Tennis (30)
来源:互联网 发布:二小姐捏脸数据 编辑:程序博客网 时间:2024/05/20 02:25
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:920:52:00 10 008:00:00 20 008:02:00 30 020:51:00 10 008:10:00 5 008:12:00 10 120:50:00 10 008:01:30 15 120:53:00 10 13 12Sample Output:
08:00:00 08:00:00 008:01:30 08:01:30 008:02:00 08:02:00 008:12:00 08:16:30 508:10:00 08:20:00 1020:50:00 20:50:00 020:51:00 20:51:00 020:52:00 20:52:00 03 3 2
这个题目写了一下午有点头皮发麻,太啰嗦了,后面借鉴了某位大神的代码,才勉强打出来,考试遇到我是必挂了。
有很多要点需要考虑。首先是:1、客户如何到达或者轮到的时间超过21点就不需要管了;
2、如果桌子都是空闲的,有VIP用户,要把VIP用户安排到最小VIP桌子;
3、VIP与普通用户同时等待,如果VIP桌子有空闲安排VIP到VIP桌子;
时间统一化成秒,输出的时候再化成时分秒。
#include<iostream>#include<algorithm>#include<vector>#include<cstring>#include<algorithm>#include<string>#include<map>#include<queue>using namespace std;int INF=99999999;typedef struct custom{ int tag; int arrive,process,serve,wait;}cus;typedef struct table{ int tag; int freeTime,num;}tab;bool cmpA(custom a,custom b){ return a.arrive<b.arrive;}bool cmpS(custom a,custom b){ return a.serve<b.serve;}vector<cus>cu;vector<tab>ta;void update(int uid,int tid){ cu[uid].serve=max(cu[uid].arrive,ta[tid].freeTime); cu[uid].wait=cu[uid].serve-cu[uid].arrive; ta[tid].num++; ta[tid].freeTime=cu[uid].serve+min(cu[uid].process,7200);}int main(){ int hh,mm,ss,cost,n,m,k; char ch; cin>>n; cu.resize(n); for(int i=0;i<n;i++) { cin>>hh>>ch>>mm>>ch>>ss>>cost>>cu[i].tag; cu[i].arrive=hh*3600+mm*60+ss; cu[i].process=cost*60; cu[i].serve=INF; cu[i].wait=INF; } cin>>k>>m; ta.resize(k); for(int i=0;i<k;i++) ta[i].freeTime=8*3600,ta[i].num=0,ta[i].tag=0; for(int i=0;i<m;i++) { cin>>hh; hh--; ta[hh].tag=1; } sort(cu.begin(),cu.end(),cmpA); for(int i=0;i<n;++i) { if(cu[i].serve!=INF)continue; int minFreeTime=INF; for(int j=0;j<k;++j) minFreeTime=min(ta[j].freeTime,minFreeTime); int timestart=max(minFreeTime,cu[i].arrive); if(timestart>=21*3600)break; vector<int>uslist,talist; for(int j=i;j<n;j++) if(cu[j].serve==INF&&cu[j].arrive<=timestart)uslist.push_back(j); for(int j=0;j<k;j++) if(ta[j].freeTime<=timestart)talist.push_back(j); bool f=false; if(uslist.size()==1&&talist.size()>1) { if(cu[uslist[0]].tag==1) { for(int j=0;j<talist.size();j++) if(ta[talist[j]].tag==1) { f=true; update(uslist[0],talist[j]); break; } } } else if(uslist.size()>1&&talist.size()==1){ if(ta[talist[0]].tag==1) for(int j=0;j<uslist.size();j++) if(cu[uslist[j]].tag==1) { f=true; update(uslist[j],talist[0]); break; } } else if(uslist.size()>1&&talist.size()>1) { for(int c=0;c<talist.size();c++) if(ta[talist[c]].tag==1) for(int j=0;j<uslist.size();j++) if(cu[uslist[j]].tag==1) { f=true; update(uslist[j],talist[c]); break; } } if(!f)update(uslist[0],talist[0]); --i; } sort(cu.begin(),cu.end(),cmpS); for(int i=0;i<n;i++) { if(cu[i].serve>=21*3600)break; int h1,m1,s1,h2,m2,s2; int t =cu[i].arrive; h1=t/3600,t%=3600,m1=t/60,t%=60,s1=t; t=cu[i].serve; h2=t/3600,t%=3600,m2=t/60,t%=60,s2=t; printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",h1,m1,s1,h2,m2,s2,(cu[i].wait+30)/60); } for(int i=0;i<k;i++) if(i!=k-1) cout<<ta[i].num<<" "; else cout<<ta[i].num<<endl; system("pause"); return 0;}
- PAT A 1026. Table Tennis (30)
- PAT-A-1026. Table Tennis (30)
- PAT 1026. Table Tennis (30)
- 1026. Table Tennis (30)-PAT
- PAT 1026. Table Tennis (30)
- PAT 1026. Table Tennis (30)
- pat 1026. Table Tennis (30)
- PAT 1026. Table Tennis (30)
- PAT 1026. Table Tennis
- 【PAT】1026. Table Tennis
- PAT 1026. Table Tennis (30) 【26/30】
- PAT 1026. Table Tennis (30)(待修改)
- 【PAT甲级】1026. Table Tennis (30)
- PAT甲级1026. Table Tennis (30)
- 【PAT】【Advanced Level】1026. Table Tennis (30)
- PAT 甲级 1026. Table Tennis (30)
- PAT 1026 Table Tennis (30)
- 1026. Table Tennis (30) @ PAT (Advanced Level) Practise
- 卷积神经网络CNN之基础介绍
- H5 Promise使用方法
- ASP.NET – 数据库连接
- Flask学习笔记--13
- Struts2学习笔记(三)——配置详解
- PAT-A-1026. Table Tennis (30)
- iOS事件传递响应机制
- Android中运行Tensorflow程序3-遇到的错误及解决
- Patrol Robot UVA
- c#静态方法和实例方法的内存分配问题
- $(document).ready(function() {})
- 怎样从0开始搭建一个测试框架_5——邮件
- php邮件发送
- Bootstrap基础16——modal提示框