1026. Table Tennis (30)-PAT

1026. Table Tennis (30)

时间限制
400 ms
内存限制
32000 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
推荐指数:※※
题目本身并不难,需要考虑的业务因素比较多。PAT上很多题目都属于这种类型,题目本身不难,就是有很多业务因素要考虑(有时候是还没说清楚...)。
1.21:00:00时刻就不提供服务了
2.每组最多玩120分钟,超过时间直接赶人。
3.VIP首先会选择VIP球台,让后才是其他球台。
#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include<sstream>
#include<queue>
#include<string.h>
#include<math.h>
#include<stdio.h>
using namespace std;
int intime(){
	string in_time;
	int timeofint,tmp;
	cin>>in_time;
	stringstream streamint;

	streamint.clear();
	streamint<<in_time.substr(0,2);
	streamint>>tmp;
	timeofint=tmp*3600;

	streamint.clear();
	streamint.str(in_time.substr(3,5));
	streamint>>tmp;
	timeofint+=tmp*60;

	streamint.clear();
	streamint.str(in_time.substr(6,8));
	streamint>>tmp;
	timeofint+=tmp;

	return timeofint;
}
typedef struct play{
	int arr_time;
	int play_time;
	int tag;
	bool is_served;
}play;
void inttotime(int time_num){
	int hh,mm,ss;
	hh=time_num/3600;
	mm=(time_num%3600)/60;
	ss=((time_num%3600)%60)%60;
	printf("%02d:%02d:%02d",hh,mm,ss);
}
const int ear_time=8*3600;
vector< play > players;
int *tables, *servers,*vip_t;

void print_play(int f_play,int play_table,int tick){
	players[f_play].is_served=true;
	tables[play_table]=tick+players[f_play].play_time*60;
	servers[play_table]++;
	inttotime(players[f_play].arr_time);
	cout<<" ";
	inttotime(tick);
	printf(" %d\n",(tick-players[f_play].arr_time+30)/60);
}
int find_first_play(int tick,int is_vip_play){//find a person 
	int f_time=21*3600,f_play=-1;
	for(int t=0;t<players.size();t++){
		if(players[t].tag==1||is_vip_play==0)
			if(players[t].arr_time<f_time&&players[t].arr_time>=ear_time&&players[t].arr_time<=tick&&players[t].is_served==false){
				f_time=players[t].arr_time;
				f_play=t;
			}
	}
	return f_play;
}
int main()
{
	int n,k,m;
	int i,j,t;
	cin>>n;//total number of plays
	for(i=0;i<n;i++){
		play p;
		p.arr_time=intime();
		cin>>p.play_time;
		p.play_time=p.play_time>2*60?2*60:p.play_time;
		cin>>p.tag;
		p.is_served=false;
		players.push_back(p);
	}
	cin>>k;//number of tables
	tables=new int[k+1];
	servers=new int[k+1];
	vip_t=new int[k+1];
	for(i=1;i<=k;i++)
		tables[i]=8*3600;
	memset(servers,0,sizeof(int)*(k+1));
	memset(vip_t,0,sizeof(int)*(k+1));
	cin>>m;//the number of VIP tables;
	for(i=0;i<m;i++){
		int num;
		cin>>num;
		vip_t[num]=1;
	}
	int tick=0;
	for(tick=8*3600;tick<21*3600;tick++){
		for(j=1;j<=k;j++){
			if(tables[j]<=tick&&vip_t[j]==1){//fist check vip table
				int f_play;
				f_play=find_first_play(tick,1);
				if(f_play!=-1)//
					print_play(f_play,j,tick);

			}
		}
		for(j=1;j<=k;j++){//check every table [1,k]
			if(tables[j]<=tick){//this table is empty
				int f_play;
				f_play=find_first_play(tick,0);
				if(f_play!=-1)
					print_play(f_play,j,tick);
			}
		}
	}
	for(i=1;i<=k;i++){
		cout<<servers[i];
		if(i<k)
			cout<<" ";
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值