1026. Table Tennis (30)
时间限制400 ms
内存限制65536 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 2Sample 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这题太鬼畜了,只能说目前AC了2015-7-31.做了一整天。但是这题里面我尝试使用了各种vector的属性事件甚么的。看起来太像在写C#了。
我的思路:
先找到最先空的一个窗口/桌子获得时间M,窗口编号mindex;
一、如果当前有普通或者Vip
if(mindex这个窗口是vip窗口)
{ if当前有vip,vip特权
else(当前有普通)普通
}
else(这个窗口不是vip窗口)
{
可能在窗口中有一个vip窗口与这个窗口同时结束,获取mv,失败mv=-1;
if(获取成功,且有vip用户)用户特权
else if(普通和vip用户同时存在,普通排在前面先)
else if(普通和vip用户同时存在,vip排在前面先)else if(只有普通,普通排)
else if(只有vip用户,vip用户排)
}
二、如果当前一个人也没有
if{ ①假如最先到的是普通的或者vip按时到的没有了,就最简单的普通人到这个mindex窗口;}
else
{
假如vip中最先到,获取满足这个vip且vip窗口的id最小,获取失败mv=-1(此时保证有vip)
if ①当获取成功vip特权mv窗口
else if ②当获取失败vip普通mindex窗口
}
联动 vector : http://www.cplusplus.com/reference/vector/vector/测试样例http://blog.csdn.net/cstopcoder/article/details/245613772015-8-1 00:56再联动一个思路超级清楚的http://blog.csdn.net/Yangsongtao1991/article/details/433171071.当有多个乒乓球台空闲时,vip顾客到了会使用最小id的vip球台,而不是最小id的球台,(这一要点我在做的时候忽略了)测试以下用例:
2 10:00:00 30 1 12:00:00 30 1 5 1 3
输出正确结果应为:
10:00:00 10:00:00 0
12:00:00 12:00:00 0
0 0 2 0 0
2.题目要求每对顾客玩的时间不超过2小时,那么当顾客要求玩的时间>2小时的时候,应该截断控制,测试以下用例:
2 18:00:00 180 1 20:00:00 60 1 1 1 1
输出的正确结果应为:
18:00:00 18:00:00 0
20:00:00 20:00:00 0
2
3.虽然题目中保证客户到达时间在08:00:00到21:00:00之间,但是根据最后的8个case来看,里面还是有不在这个时间区间内到达的顾客,所以建议还是稍加控制,测试以下用例:(这里我贴出来的代码是只控制21:00之前(不包括21:00)的数据保留没有舍掉8:00之前,2015-8-1测试通过)
1 21:00:00 80 1 1 1 1
输出的正确结果应为:
0
4.题目中说的round up to an integer minutes是严格的四舍五入,需要如下做
wtime = (stime - atime + 30) / 60
而不是:
wtime = (stime - atime + 59) / 60(PS:这里他们写着四舍五入我没有看懂,后来看了自己的结果大了很多才想到是没有把秒换成分,然后“/”这个对于整型int 来说是取整(取整数部分))----------------------------3
11:25:00 10 1
11:34:00 10 1
11:35:00 10 0
10 1
7--------------------------
11:25:00 11:25:00 0
11:34:00 11:34:00 0
11:35:00 11:35:00 0
1 1 0 0 0 0 1 0 0 0
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月01日 00:41 | 答案正确 | 30 | 1026 | C++ (g++ 4.7.2) | 13 | 628 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 308 | 14/14 |
1 | 答案正确 | 1 | 180 | 2/2 |
2 | 答案正确 | 1 | 436 | 2/2 |
3 | 答案正确 | 1 | 180 | 2/2 |
4 | 答案正确 | 1 | 308 | 2/2 |
5 | 答案正确 | 1 | 308 | 1/1 |
6 | 答案正确 | 1 | 180 | 3/3 |
7 | 答案正确 | 1 | 180 | 3/3 |
8 | 答案正确 | 13 | 628 | 1/1 |
#include<iostream> #include<vector> #include<iomanip> #include<algorithm> #define CloseTime 75600 #define StartTime 28800 using namespace std; struct TableTennisLine { int comeTime, Servetime, playTime; TableTennisLine(int c, int p) :comeTime(c), playTime(p) {} }; struct Tables { int CoUnt; int vacantTime; bool vip; Tables(int CoUnt, int vacantTime, bool vip) :CoUnt(CoUnt), vacantTime(vacantTime), vip(vip){} }; int DUreadln(vector <TableTennisLine>*Vip, vector<TableTennisLine> *Ordinary, int N) { int ss, ff, mm,play,tag,ccount; int index ; char MHc; for (index = 0 ,ccount=0; index < N; index++) { cin >> ss >> MHc >> ff >> MHc >> mm >> play>> tag; ss = ss * 3600 + ff * 60 + mm; if (ss < CloseTime) { ccount++; play = play > 120 ? 120 : play; play *=60; tag == 1 ? (*Vip).push_back(TableTennisLine(ss, play)) : (*Ordinary).push_back(TableTennisLine(ss, play)); } } return ccount; } void ZhuoStar(vector<Tables>*Tabl, int Star, int ENd, int cc, int vacant, bool vip) { while (Star++ < ENd) (*Tabl).push_back(Tables(cc,vacant,vip)); } void ZhuoVip(vector<Tables>*Tabl, int Star, int ENd, bool vip) { int index; for (; Star < ENd; Star++) { cin >> index; index--; (*Tabl).operator[](index).vip= vip; } } bool TABLEcmp(const TableTennisLine&A, const TableTennisLine&B) { return A.comeTime < B.comeTime; } int first_vacnt_tables(vector<Tables> Tabl, int Star, int ENd, int *M) { int vacanttemp, mindex = 0; (*M) = Tabl[0].vacantTime; for (; Star < ENd; Star++) { vacanttemp =Tabl[Star].vacantTime; if (vacanttemp < *M) { (*M) = vacanttemp; mindex = Star; } } return mindex; } int vip_vacant_talbe(vector<Tables> Tabl, int Star, int ENd, int *MM) { int vacanttemp, mv= -1; for (; Star < ENd; Star++) { vacanttemp = Tabl[Star].vacantTime; if (Tabl[Star].vip&&vacanttemp <= *MM)//满足且标号最小 { (*MM) = vacanttemp; mv = Star; return mv; } } return mv; } void printchild2(int timetemp) { cout << setw(2) << setfill('0') << timetemp; } void printchild1(int timet) { printchild2(timet / 3600); cout << ":"; timet %= 3600; printchild2(timet / 60); cout << ":"; printchild2(timet% 60); cout << " "; } void Xprint(int c, int s, int p) { printchild1(c); printchild1(s); cout << (p+30)/60 << endl; } void GetThisTable(vector<Tables>*Tabl, int Tindex, vector <TableTennisLine>*Turn,int v) { if ((*Tabl).operator[](Tindex).vacantTime > (*Turn).operator[](v).comeTime) { (*Turn).operator[](v).Servetime = (*Tabl).operator[](Tindex).vacantTime; (*Tabl).operator[](Tindex).vacantTime += (*Turn).operator[](v).playTime; (*Turn).operator[](v).playTime = (*Turn).operator[](v).Servetime - (*Turn).operator[](v).comeTime; } else { (*Turn).operator[](v).Servetime = (*Turn).operator[](v).comeTime; (*Tabl).operator[](Tindex).vacantTime = (*Turn).operator[](v).comeTime + (*Turn).operator[](v).playTime; (*Turn).operator[](v).playTime = 0; } if ((*Turn).operator[](v).Servetime< CloseTime) Xprint((*Turn).operator[](v).comeTime, (*Turn).operator[](v).Servetime, (*Turn).operator[](v).playTime); } int main() { vector<TableTennisLine>Vip, Ordinary; vector<Tables>Tabl; int index, N, K, M, v,mindex,mv,MM,lenv,leno; cin >> N; N=DUreadln(&Vip, &Ordinary, N); cin >> K >> M; ZhuoStar(&Tabl, 0, K, 0, StartTime, false); /*for (int v = 0; v < Tabl.size(); v++) { cout << Tabl[v].CoUnt << " "; Tabl[v].vip ? cout << "ok" : cout << "false"; cout << endl; }*/ ZhuoVip(&Tabl, 0, M, true); sort(Vip.begin(), Vip.end(), TABLEcmp); sort(Ordinary.begin(), Ordinary.end(), TABLEcmp); M = StartTime; mindex = 0; lenv = Vip.size(); leno = Ordinary.size(); for (v = 0, index = 0; v + index < N&&M <CloseTime;) { mindex = first_vacnt_tables(Tabl, 1, K, &M); if (M<CloseTime) { if (leno > index&&Ordinary[index].comeTime <= M || lenv>v&&Vip[v].comeTime <= M)//当前有队伍 { if (Tabl[mindex].vip)//当前是vip窗口 { if (lenv>v&&Vip[v].comeTime <= M) { GetThisTable(&Tabl, mindex, &Vip, v++); Tabl[mindex].CoUnt++; //有vip用户特权; } else { GetThisTable(&Tabl, mindex, &Ordinary, index++); Tabl[mindex].CoUnt++; //普通用户; } } else //当前不是vip窗口 { MM = M; mv = vip_vacant_talbe(Tabl, 0, K, &MM); if (-1 != mv&&lenv>v&&Vip[v].comeTime <= M) { GetThisTable(&Tabl, mv, &Vip, v++); Tabl[mv].CoUnt++; //有vip用户特权; } else if (leno > index&&Ordinary[index].comeTime <= M &&lenv>v&&Vip[v].comeTime <= M&&Ordinary[index].comeTime <Vip[v].comeTime ) { GetThisTable(&Tabl, mindex, &Ordinary, index++); Tabl[mindex].CoUnt++; //有空闲窗口,普通用户先到; } else if (leno > index&&Ordinary[index].comeTime <= M &&lenv > v&&Vip[v].comeTime <= M&&Ordinary[index].comeTime >= Vip[v].comeTime) { GetThisTable(&Tabl, mindex, &Vip, v++); Tabl[mindex].CoUnt++; //有空闲窗口且vip窗口满,vip用户先到; } else if (leno > index&&Ordinary[index].comeTime <= M) { GetThisTable(&Tabl, mindex, &Ordinary, index++); Tabl[mindex].CoUnt++; //有空闲窗口,只有普通用户; } else { GetThisTable(&Tabl, mindex, &Vip, v++); Tabl[mindex].CoUnt++;//有空闲窗口,只有vip用户; } } } else //当前无队伍 { if (leno>index&&(lenv > v&&Ordinary[index].comeTime < Vip[v].comeTime||lenv<=v)) { GetThisTable(&Tabl, mindex, &Ordinary, index++); Tabl[mindex].CoUnt++; //有空闲窗口,当前无vip用户; } else { MM = Vip[v].comeTime; mv = vip_vacant_talbe(Tabl, 0, K, &MM); if (lenv > v&&mv!=-1) { GetThisTable(&Tabl, mv, &Vip, v++); Tabl[mv].CoUnt++;//有空闲窗口vip窗口未满,当前无普通用户 } else if (lenv > v) { GetThisTable(&Tabl, mindex, &Vip, v++); Tabl[mindex].CoUnt++; //有空闲窗口且vip窗口满,当前无普通用户; } } } } } K--; for (index = 0; index < K; index++) cout << Tabl[index].CoUnt << " "; cout << Tabl[index].CoUnt << endl; system("pause"); return 0; }