pat 甲级 快乐模拟 A1026 Table Tennis (30分)!!!!!!!!!

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 privilege 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
#include <iostream>
#include<vector> 
#include<algorithm>
using namespace std;
struct node{
	int id,arrtime,tag,playtime;
};
bool cmp(node a,node b){
	return a.arrtime<b.arrtime;
}
int n,k,m;
int main(){
	cin>>n;
	vector<node> player(n),vipplayer;
	int h,mm,s,pt,tag;
	for(int i=0;i<n;i++){
		scanf("%d:%d:%d %d %d",&h,&mm,&s,&pt,&tag);
		player[i].id=i;
		player[i].arrtime=h*3600+mm*60+s;
		player[i].tag=tag;
		player[i].playtime=min(pt*60,7200);
		if(tag==1) vipplayer.push_back(player[i]);
	}
	sort(player.begin(),player.end(),cmp);
	sort(vipplayer.begin(),vipplayer.end(),cmp);
	scanf("%d %d",&k,&m);
	int v;
	vector<int> viptable(k+1,0),endtime(k+1,0),isserved(n,0),tablecnt(k+1,0);
	for(int i=0;i<m;i++){
		scanf("%d",&v);
		viptable[v]=1;
	}
	int tempNorm=0,tempVip=0;
	for(int i=0;i<n;i++){
		while(isserved[player[tempNorm].id]==1) tempNorm++;
		node serve=player[tempNorm];//serve是当前玩家
		int min=endtime[1],tableid=1;//endtime 为本桌子结束服务的时间 
		for(int j=2;j<=k;j++){
			if(min<=serve.arrtime) break;//有桌子结束服务 且目前没人在等待 
			if(min>endtime[j]){//寻找最早结束服务的桌子 
				min=endtime[j];
				tableid=j;
			} 
		}
		if(min>=75600||serve.arrtime>=75600) break;
		while(tempVip<vipplayer.size()&&isserved[vipplayer[tempVip].id]==1)
		tempVip++;
		//空桌是VIP,但玩家不是。看vipplayer里面的VIP用户 若满足到达时间小于等于空桌结束时间,说明早已经在等待,为该vip用户分配此vip桌子。 
		if(viptable[tableid]==1&&serve.tag==0&&tempVip<vipplayer.size()&&vipplayer[tempVip].arrtime<=min)
		 serve=vipplayer[tempVip];
		 //空桌不是VIP 而玩家是VIP。看有没有别的空桌子是VIP桌子的。
		if(viptable[tableid]==0&&serve.tag==1){
			for(int j=tableid+1;j<=k;j++){
				if(viptable[j]==1&&endtime[j]<=serve.arrtime){//假设存在vip桌子空着,则换vip桌子
					tableid=j;
					break;
				}
			}
		}
		printf("%02d:%02d:%02d ",serve.arrtime/3600,serve.arrtime%3600/60,serve.arrtime%60);
		if(endtime[tableid]<serve.arrtime)//若该桌子空出来的时间早于 用户到达的时间,则用户开始被服务的时间就是该用户的到达时间。
		 {
		 	endtime[tableid]=serve.arrtime; 
		 }
		 //否则 说明用户在桌子空出之前 已经在等待。那么此用户开始被服务的时间就是桌子空出来的时间 
		 printf("%02d:%02d:%02d ",endtime[tableid]/3600,endtime[tableid]%3600/60,endtime[tableid]%60);
		 int waittime=max(endtime[tableid]-serve.arrtime,0);
		 waittime=(int)((1.0*waittime)/60+0.5);
		 printf("%d\n",waittime);
		 tablecnt[tableid]++;
        endtime[tableid]+=serve.playtime;
        isserved[serve.id]=1;
	}
	cout<<tablecnt[1];
	for(int i=2;i<=k;i++)
	cout<<" "<<tablecnt[i];
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值