博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1026 Table Tennis
阅读量:4540 次
发布时间:2019-06-08

本文共 5916 字,大约阅读时间需要 19 分钟。

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:

920:52:00 10 008:00:00 20 008:02:00 30 020:51:00 10 008:10:00 5 008:12:00 10 120:50:00 10 008:01:30 15 120:53:00 10 13 12

Sample Output:

08:00:00 08:00:00 008:01:30 08:01:30 008:02:00 08:02:00 008:12:00 08:16:30 508:10:00 08:20:00 1020:50:00 20:50:00 020:51:00 20:51:00 020:52:00 20:52:00 03 3 2
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 struct person { 7 int arrive, start, time; 8 bool vip; 9 }tempperson; 10 struct tablenode { 11 int end = 8 * 3600, num; 12 bool vip; 13 }; 14 bool cmp1(person a, person b) { 15 return a.arrive < b.arrive; 16 } 17 bool cmp2(person a, person b) { 18 return a.start < b.start; 19 } 20 vector
player; 21 vector
table; 22 void alloctable(int personid, int tableid) { 23 if (player[personid].arrive <= table[tableid].end) 24 player[personid].start = table[tableid].end; 25 else 26 player[personid].start = player[personid].arrive; 27 table[tableid].end = player[personid].start + player[personid].time; 28 table[tableid].num++; 29 } 30 int findnextvip(int vipid) { 31 vipid++; 32 while (vipid < player.size() && player[vipid].vip == false) vipid++; 33 return vipid; 34 } 35 int main() { 36 int n, k, m, viptable; 37 scanf("%d", &n); 38 for (int i = 0; i < n; i++) { 39 int h, m, s, temptime, flag; 40 scanf("%d:%d:%d %d %d", &h, &m, &s, &temptime, &flag); 41 tempperson.arrive = h * 3600 + m * 60 + s; 42 tempperson.start = 21 * 3600; 43 if (tempperson.arrive >= 21 * 3600) continue; 44 tempperson.time = temptime <= 120 ? temptime * 60 : 7200; 45 tempperson.vip = ((flag == 1) ? true : false); 46 player.push_back(tempperson); 47 } 48 scanf("%d%d", &k, &m); 49 table.resize(k + 1); 50 for (int i = 0; i < m; i++) { 51 scanf("%d", &viptable); 52 table[viptable].vip = true; 53 } 54 sort(player.begin(), player.end(), cmp1); 55 int i = 0, vipid = -1; 56 vipid = findnextvip(vipid); 57 while (i < player.size()) { 58 int index = -1, minendtime = 999999999; 59 for (int j = 1; j <= k; j++) { 60 if (table[j].end < minendtime) { 61 minendtime = table[j].end; 62 index = j; 63 } 64 } 65 if (table[index].end >= 21 * 3600) break; 66 if (player[i].vip == true && i < vipid) { 67 i++; 68 continue; 69 } 70 if (table[index].vip == true) { 71 if (player[i].vip == true) { 72 alloctable(i, index); 73 if (vipid == i) vipid = findnextvip(vipid); 74 i++; 75 } 76 else { 77 if (vipid < player.size() && player[vipid].arrive <= table[index].end) { 78 alloctable(vipid, index); 79 vipid = findnextvip(vipid); 80 } 81 else { 82 alloctable(i, index); 83 i++; 84 } 85 } 86 } 87 else { 88 if (player[i].vip == false) { 89 alloctable(i, index); 90 i++; 91 } 92 else { 93 int vipindex = -1, minvipendtime = 999999999; 94 for (int j = 1; j <= k; j++) { 95 if (table[j].vip == true && table[j].end < minvipendtime) { 96 minvipendtime = table[j].end; 97 vipindex = j; 98 } 99 }100 if (vipindex != -1 && player[i].arrive >= table[vipindex].end) {101 alloctable(i, vipindex);102 if (vipid == i) vipid = findnextvip(vipid);103 i++;104 }105 else {106 alloctable(i, index);107 if (vipid == i) vipid = findnextvip(vipid);108 i++;109 }110 }111 }112 }113 sort(player.begin(), player.end(), cmp2);114 for (i = 0; i < player.size() && player[i].start < 21 * 3600; i++) {115 printf("%02d:%02d:%02d ", player[i].arrive / 3600, player[i].arrive % 3600 / 60, player[i].arrive % 60);116 printf("%02d:%02d:%02d ", player[i].start / 3600, player[i].start % 3600 / 60, player[i].start % 60);117 printf("%.0f\n", round((player[i].start - player[i].arrive) / 60.0));118 }119 for (int i = 1; i <= k; i++) {120 if (i != 1) printf(" ");121 printf("%d", table[i].num);122 }123 return 0;124 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11254672.html

你可能感兴趣的文章
求旋转数组的最小元素
查看>>
Gson解析Json数组
查看>>
Lintcode: Fast Power
查看>>
Pocket Gem OA: Log Parser
查看>>
枚举也能直接转换为对应的数值输出
查看>>
angularjs1-7,供应商
查看>>
让插件帮你优化代码
查看>>
Java之路——Java初接触
查看>>
2018.12.27学习JavaScript
查看>>
理工之 A+B Problem III
查看>>
软件工程第一次作业
查看>>
【Android 界面效果24】Intent和PendingIntent的区别
查看>>
node学习之搭建服务器并加装静态资源
查看>>
android 按menu键解锁功能的开关
查看>>
Linux 下的dd命令使用详解
查看>>
POJ-1273 Drainage Ditches 最大流Dinic
查看>>
ASP.NET学习记录点滴
查看>>
[Noip2016] 愤怒的小鸟
查看>>
JAVA wait()和notifyAll()实现线程间通讯
查看>>
python全栈脱产第11天------装饰器
查看>>