1026. Table Tennis (30)

Source: Internet
Author: User

A Table Tennis Club have N tables available to the public. The tables is numbered from 1 to N. For any pair of players, if there is some tables open when they arrive, they'll be assigned to the available table with The smallest number. If all the tables is occupied, they'll has the to wait in a queue. It is assumed this every pair of players can play for at the most 2 hours.

your job is to count for everyone in queue their waiting time, and for each table the number of P Layers It has served for the day.

One thing that makes this procedure a bit complicated are the the club reserves some tables for their VIP members. When a VIP table was open, the first VIP pair in the queue would 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-it is the turn of a VIP pair, yet no VIP table was available, they can be assigned as any Ordina Ry players.

Input Specification:

each input file contains one test case. For each case, the first line contains a 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, the arriving time is between 08:00:00, and 21:00:00 while the club is open. It is assumed, that no, customers arrives at the same time. Following the players ' info, there is 2 positive integers:k (<=100)-The number of tables, and M (< K)-The Numb Er 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 Forma T shown by the sample. Then print with a line the number of players served by each table. Notice that the output must is listed in chronological order of the serving time. The waiting time must is 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:0 0 20:51:00 020:52:00 20:52:00 03 3 2
Idea: Typical event-driven simulations
Problems encountered: 1. There are waiting VIP players, and there is free VIP ball table, priority to use the small number of VIP table, or VIP and ordinary players like; 2. Event-Triggered priority: Trigger Event->vip-> arrival time (last Test point will be involved); 3. Duration needs to be truncated (2hours);
#include <vector> #include <string> #include <algorithm> #include <queue> #include <deque > #include <cstdio>using namespace std; #define Closetime 21*3600#define opentime 8*3600struct Table {table (): Vip_tag (0), count (0), busy (0) {};int vip_tag;int count;int busy;}; struct Player {player (): Arrive_h (0), arrive_m (0), arrive_s (0), During_time (0), VIP (0), table ( -1) {};int arrive_h;int Arrive_m;int arrive_s;int during_time;int vip;int table;}; struct Event {event (player p, int h, int m, int s, int t):p (p), Occur_h (h), Occur_m (M), occur_s (s), type (t) {};p layer p;int o Ccur_h;int occur_m;int occur_s;int type;}; struct CMP {bool operator () (Event &a, event &b) {int T1 = a.occur_h*3600 + a.occur_m* + a.occur_s;int t2 = B.OCC ur_h*3600 + b.occur_m*60 + b.occur_s;if (t1 = = t2) {//Event-triggered event priority if (A.P.VIP = = B.P.VIP) {//For the last case is important, the event trigger time is the same as VIP priority, VIP Same case arrival time First int at1 = a.p.arrive_h* 3600+a.p.arrive_m*60+a.p.arrive_s;int at2 = b.p.arrive_h* 3600+b.p.arrive_m*60+ b.p.arrive_s;return AT1 > AT2;} return A.P.VIP < B.P.VIP;} return t1 > t2;}}; int main () {int n;scanf ("%d", &n);vector<player> players (N); int i;for (i = 0; i < N; i++) {Player &t = Playe RS[I];SCANF ("%d:%d:%d%d%d", &t.arrive_h, &t.arrive_m,&t.arrive_s, &AMP;T.DURING_TIME,&AMP;T.VIP); T.during_time >) t.during_time = 120;} int K, M;SCANF ("%d%d", &k, &m);vector<table> tables (K); for (i = 0; i< M; i++) {int t;scanf ("%d", &t); t Ables[t-1].vip_tag = 1;} Priority_queue<event,vector<event>,cmp> eq;deque<event> q;for (i = 0; i< N; i++) {int tt = 3600* Players[i].arrive_h+60*players[i].arrive_m+players[i].arrive_s;if (TT < closetime && tt >= OPENTIME) Eq.push (Event (players[i],players[i].arrive_h,players[i].arrive_m, players[i].arrive_s, 0));} while (!eq.empty ()) {Event E = Eq.top (), Eq.pop (), if (E.type = = 0) {//arrive eventint j;if (E.P.VIP) {//vip prio to select VIP TA ble firstlyint v = -1;for (j = 0; j< K; j + +) {//find a freE Tableif (!tables[j].busy) {if (v = =-1) v = j;if (Tables[j].vip_tag) break;}} if (j = = K) if (v! =-1) j = V;} Else{for (j = 0; j< K; j + +) {//find a free tableif (!tables[j].busy) break;} if (j! = K) {//if j is a free tabletables[j].busy = 1;tables[j].count++;e.p.table = J;int During_time = E.p.during_time;int s = e.occur_s;int m = E.occur_m+during_time;int h = e.occur_h + M/60;eq.push (Event (E.P, H,m%60, S, 1));//output the Res Ultint wait_t = (3600*e.occur_h+60*e.occur_m+e.occur_s-3600*e.p.arrive_h-60*e.p.arrive_m-e.p.arrive_s+30)/60; printf ("%02d:%02d:%02d%02d:%02d:%02d%d\n", e.p.arrive_h,e.p.arrive_m,e.p.arrive_s,e.occur_h,e.occur_m,e.occur_s , wait_t);} else{//If there is no free tableq.push_back (e);}} Else{//leave eventint h = e.occur_h, M = e.occur_m, s = e.occur_s;player &p = E.p;tables[p.table].busy = 0;if (!q.empty ()) {int v = 0;if (Tables[p.table].vip_tag) {for (v = 0, v < q.size (); v++) {if (Q[V].P.VIP) break;} if (v = = q.size ()) v = 0;} int tt = 3600*h + 60*m + s;if (TT < closetime) {EQ. Push (Event (Q[V].P, h,m,s,0)); Q.erase (Q.begin () +v);} Else{break;}}}} int flag = 0;for (i=0; i< tables.size (); i++) {if (!flag) {flag = 1;printf ("%d", Tables[i].count);} elseprintf ("%d", Tables[i].count);} printf ("\ n"); return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

1026. Table Tennis (30)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.