您的位置:首页 > 其它

1026. Table Tennis (30)

2015-08-09 10:09 375 查看
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


提交代

————————————

真难的题,case是很多啊。

最近也比较懒,权当这样出来吧。

是孙大神的思路。。。。。

我学习下】

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define INF 0x6FFFFFFF

struct node{
int arrive,process,tag;
int serve,wait;
bool isserved;
};
struct table{
int tag;
int freetime,num;
};
int N,K,M;//N个players,K张桌子,M张VIP桌子
vector<node> usr;
vector<table> tab;

bool cmp_arrive(node a, node b){
return a.arrive<b.arrive;
}
bool cmp_serve(node a, node b){
if(a.serve==b.serve)	return a.arrive<b.arrive;
else return a.serve<b.serve;
}

void update(int usrid, int tabid){
usr[usrid].serve=max(usr[usrid].arrive, tab[tabid].freetime);
usr[usrid].wait=usr[usrid].serve-usr[usrid].arrive;
tab[tabid].num++;
tab[tabid].freetime=usr[usrid].serve+min(usr[usrid].process, 7200);
}
int main(int argc, char** argv) {
cin>>N;
int i=0;

usr.resize(N);
for(i=0; i<N; i++){
int h,m,s;
scanf("%d:%d:%d %d %d",&h,&m,&s,&usr[i].process,&usr[i].tag);
usr[i].arrive=h*60*60+m*60+s;
usr[i].process=usr[i].process*60;
usr[i].serve=INF;
usr[i].isserved=false;
}
sort(usr.begin(),usr.end(),cmp_arrive);
cin>>K>>M;

tab.resize(K);
for(i=0; i<K; i++){
tab[i].freetime=8*3600;
tab[i].tag=0;
}
for(i=0; i<M; i++){
int tmp=0;
cin>>tmp;
tab[--tmp].tag=1;
}
for(i=0; i<N; ++i){
if(usr[i].serve != INF) continue;
int minfreetime=INF;
for(int j=0; j<K; j++)
minfreetime=min(minfreetime,tab[j].freetime);
int timepoint=max(usr[i].arrive, minfreetime);
if(timepoint>=21*3600) break;
vector<int>usrlist;
vector<int>tablelist;
for(int j=i; j<N; j++)
if(usr[j].serve == INF && usr[j].arrive <= timepoint) usrlist.push_back(j);
for(int j=0; j<K; j++)
if(tab[j].freetime<=timepoint) tablelist.push_back(j);

bool flag=false;
if(usrlist.size()==1&&tablelist.size()>1){
if(usr[usrlist[0]].tag==1){
for(int j=0; j<tablelist.size(); j++){
if(tab[tablelist[j]].tag==1){
flag=true;
update(usrlist[0],tablelist[j]);
break;
}
}
}
}else if(tablelist.size()==1 && usrlist.size()>1){
if(tab[tablelist[0]].tag==1){
for(int j=0; j<usrlist.size(); j++){
if(usr[usrlist[j]].tag==1){
flag=true;
update(usrlist[j],tablelist[0]);
break;
}
}
}
}else if(tablelist.size()>1 && usrlist.size()>1){
for(int t=0; t<tablelist.size(); t++){
if(tab[tablelist[t]].tag==1){
for(int u=0; u<usrlist.size(); u++){
if(usr[usrlist[u]].tag==1){
flag=true;
update(usrlist[u],tablelist[t]);
break;
}
}
}
}
}
if(!flag) update(usrlist[0],tablelist[0]);
--i;
}

sort(usr.begin(),usr.end(),cmp_serve);
for(i=0; i<N; i++){
if(usr[i].serve>=21*3600) break;
int h1,m1,s1,h2,m2,s2;
int t=usr[i].arrive;
h1=t/3600;t%=3600;
m1=t/60; t%=60;
s1=t;
t=usr[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, (usr[i].wait+30)/60);
}
for(int i=0; i<K; i++){
i!=K-1?printf("%d ",tab[i].num):printf("%d\n",tab[i].num);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: