PAT 1026. Table Tennis
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
- 此题很遗憾,之拿到23分,但是觉得很有成就感
- // 1026pat.cpp : 定义控制台应用程序的入口点。
- //
- #include <fstream>
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <time.h>
- #include <math.h>
- using namespace std;
- const int NP=;
- const int NT=;
- const int INF=0x7fffffff;
- const int closeTime=*;
- struct Player
- {
- string arrive_time; //arrive time in string format
- string serve_time; //serve time in string format
- int serve_second; //serve time int seconds of integer
- int arrive_second; //arrive time in seconds of integer
- int play_time; //play time in minutes
- int play_second; //play time in seconds
- int wait_time; //wait time
- bool VIP; //Vip
- bool operator<(const Player& rhs) const
- {
- return arrive_time<rhs.arrive_time;
- }
- };
- struct Table
- {
- int serve_nums;
- int next_available_time;
- bool VIPT;
- };
- vector<Player> players;
- vector<Player> RecordPlayers;
- vector<Table> tables;
- vector<int> vipTables;
- int n,k,m;;
- int find_available_table(int arrive_time)
- {
- for(int i=;i<=k;++i)
- {
- if(tables[i].next_available_time<=arrive_time)
- return i;
- }
- return -;
- }
- int find_earlist_table()
- {
- int min=INF;
- int table;
- for(int i=;i<=k;++i)
- {
- if(tables[i].next_available_time<min)
- {
- min=tables[i].next_available_time;
- table=i;
- }
- }
- return table;
- }
- bool isVipTable(int x)
- {
- for(int i=;i<m;++i)
- {
- if(vipTables[i]==x)
- return true;
- }
- return false;
- }
- bool isVipPlayer(const Player& player)
- {
- if(player.VIP)
- return true;
- else
- return false;
- }
- int findVip_available_table(int arrive_second)
- {
- for(int i=;i<m;++i)
- {
- if(tables[vipTables[i]].next_available_time<=arrive_second)
- return vipTables[i];
- }
- return -;
- }
- int findVip_player_Inqueue(int cur,int available_time)
- {
- for(int i=cur+;i<n;++i)
- {
- if(players[i].VIP&&players[i].arrive_second<=available_time)
- return i;
- }
- return -;
- }
- class T:public binary_function<Player,Player,bool>
- {
- public:
- bool operator()(const Player& lhs,const Player& rhs) const
- {
- return lhs.serve_time<rhs.serve_time;
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {while(cin>>n)
- {
- //clear the buffer
- players.clear();
- tables.clear();
- vipTables.clear();
- Player player;
- int h,min,s;
- for(int i=;i<=n;++i)
- {
- cin>>player.arrive_time>>player.play_time>>player.VIP;
- sscanf(player.arrive_time.c_str(),"%d:%d:%d",&h,&min,&s);
- player.arrive_second=*h+*min+s;
- if(player.play_time>)
- player.play_time=;
- player.play_second=*player.play_time;
- player.wait_time=;
- players.push_back(player);
- }
- sort(players.begin(),players.end());
- cin>>k>>m;
- Table table;
- table.VIPT=;
- tables.push_back(table);
- for(int i=;i<=k;++i)
- {
- table.next_available_time=*;
- table.VIPT=;
- table.serve_nums=;
- tables.push_back(table);
- }
- int vip;
- for(int i=;i<=m;++i)
- {
- cin>>vip;
- vipTables.push_back(vip);
- tables[vip].VIPT=;
- }
- //deal with the core process
- int tnum;
- bool nvip=false;
- for(int i=;i<n;++i)
- {
- if(players[i].VIP)//vip player case
- {
- tnum=findVip_available_table(players[i].arrive_second);
- if(tnum>)//vip player vip table
- {
- if(tables[tnum].next_available_time<closeTime)
- {
- ++tables[tnum].serve_nums;
- players[i].serve_second=players[i].arrive_second;
- tables[tnum].next_available_time=players[i].arrive_second+players[i].play_second;
- RecordPlayers.push_back(players[i]);
- }
- else
- nvip=true;
- }//vip player vip table
- else
- {
- tnum=find_available_table(players[i].arrive_second);
- if(tnum>)
- {
- if(tables[tnum].next_available_time<closeTime)
- {
- ++tables[tnum].serve_nums;
- players[i].serve_second=players[i].arrive_second;
- tables[tnum].next_available_time=players[i].arrive_second+players[i].play_second;
- RecordPlayers.push_back(players[i]);
- }
- else
- {
- if(nvip)
- break;
- }
- }//vip player common table
- else
- {
- tnum=find_earlist_table();
- if(tables[tnum].next_available_time<closeTime)
- {
- ++tables[tnum].serve_nums;
- players[i].serve_second=tables[tnum].next_available_time;
- players[i].wait_time=tables[tnum].next_available_time-players[i].arrive_second;
- tables[tnum].next_available_time=tables[tnum].next_available_time+players[i].play_second;
- RecordPlayers.push_back(players[i]);
- }
- else
- break;
- }//vip player have to wait
- }
- }//vip player case
- else //common player case
- {
- tnum=find_available_table(players[i].arrive_second);
- if(tnum>)
- {
- if(tables[tnum].next_available_time<closeTime)
- {
- ++tables[tnum].serve_nums;
- players[i].serve_second=players[i].arrive_second;
- tables[tnum].next_available_time=players[i].arrive_second+players[i].play_second;
- RecordPlayers.push_back(players[i]);
- }
- else
- break;
- }//available table
- else
- {
- tnum=find_earlist_table();
- if(tables[tnum].next_available_time<closeTime)
- {
- int vp=findVip_player_Inqueue(i,tables[tnum].next_available_time);
- if(vp>-)
- {
- ++tables[tnum].serve_nums;
- players[vp].serve_second=tables[tnum].next_available_time;
- players[vp].wait_time=tables[tnum].next_available_time-players[vp].arrive_second;
- tables[tnum].next_available_time+=players[vp].play_second;
- RecordPlayers.push_back(players[vp]);
- players.erase(players.begin()+vp);
- --i;
- --n;
- continue;
- }
- else
- {
- ++tables[tnum].serve_nums;
- players[i].serve_second=tables[tnum].next_available_time;
- players[i].wait_time=tables[tnum].next_available_time-players[i].arrive_second;
- tables[tnum].next_available_time+=players[i].play_second;
- RecordPlayers.push_back(players[i]);
- }
- }
- else
- break;
- }//common player have to wait
- }//common player case
- }//the core calculation process
- //output the result
- for(vector<Player>::iterator iter=RecordPlayers.begin();iter!=RecordPlayers.end();++iter)
- {
- int hr,me,sd;
- hr=iter->serve_second/;
- me=(iter->serve_second/)%;
- sd=iter->serve_second%;
- char tmp[];
- tm hms;
- hms.tm_hour=hr;
- hms.tm_min=me;
- hms.tm_sec=sd;
- strftime(tmp,sizeof(tmp),"%H:%M:%S",&hms);
- iter->serve_time=tmp;
- iter->wait_time=(1.0*iter->wait_time/60.0+0.5);
- }
- sort(RecordPlayers.begin(),RecordPlayers.end(),T());
- for(vector<Player>::iterator iter=RecordPlayers.begin();iter!=RecordPlayers.end();++iter)
- {
- cout<<iter->arrive_time<<" "<<iter->serve_time<<" "<<iter->wait_time<<endl;
- }
- bool flag=true;
- for(vector<Table>::iterator iter=tables.begin()+;iter!=tables.end();++iter)
- {
- if(flag)
- {
- cout<<iter->serve_nums;
- flag=false;
- }
- else
- cout<<" "<<iter->serve_nums;
- }
- cout<<endl;
- }
- return ;
- }
PAT 1026. Table Tennis的更多相关文章
- PAT 1026 Table Tennis[比较难]
1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...
- PAT 1026 Table Tennis (30)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- PAT甲级1026. Table Tennis
PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...
- PAT 甲级 1026 Table Tennis(模拟)
1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- 1026. Table Tennis (30)
题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...
- PAT A1026 Table Tennis (30 分)——队列
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- 1026 Table Tennis (30)(30 分)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- 1026 Table Tennis (30分)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
随机推荐
- (转载)在Delphi中利用MSDASC来配置数据库链接
在Delphi中利用MSDASC来配置数据库链接 在运行期进行数据库的连接是一个问题,自己写一个窗体配置吧,数据库不一样,所用的参数也不一样,还有那讨厌的连接字符串,有时真不知该写什么好.那天无意中发 ...
- HTML 5 video 视频标签全属性详解
Video标签的使用 Video标签含有src.poster.preload.autoplay.loop.controls.width.height等几个属性, 以及一个内部使用的标签<sour ...
- 本博客css style
#navList { min-height: 60px; } #navList li { height: 60px; } #navList a { margin: 0px 5px !important ...
- CSS3 学习
border-radius: 半径,不用学了,用得很熟了,但要记得它的某一个角的写法是border-top/bottom-left/right-radius: ,参数中的两个值为先左右后上下,支持百分 ...
- Js 简单分页(二)
此次使用了http://www.purecss.org/ 的前端Css 效果图 上代码 //更新分页工具栏的效果展示 function updatepagetoolshow(){ //判断当前页 及 ...
- 结缘PDO
起因 一直没有注意看数据库相关知识 几个月之前,无意打开如下一段代码: 被人吐槽是N年前的写法.后来也是学习需要,单一mysql已经不合适了.于是上网搜了一下好方法,PDO迎面而来. 诱惑 上网浏览时 ...
- Linux发行版
Linux 发行版(英语:Linux distribution,也被叫做GNU/Linux 发行版),为一般用户预先集成好的Linux操作系统及各种应用软件.一般用户不需要重新编译,在直接安装之后,只 ...
- WebService学习整理(一)——客户端三种调用方式整理
1 WebService基础 1.1 作用 1, WebService是两个系统的远程调用,使两个系统进行数据交互,如应用: 天气预报服务.银行ATM取款.使用邮箱账号登录各网站等. 2, ...
- Visual Studio 内置快速生产代码简写集合
工作之余,整理了一下,Visual Studio 里面的快速生产代码缩写集合,这个拿出来分享想一下,希望对您有所帮助. 文件下载地址:VS内置生产代码缩写集合文档.rar 首字母 简写 生成代码 a ...
- webserver<2>
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wai ...