Home > Back-end >  1017. PAT serie a Queueing at Bank (25) [simulation] last test points for help!!
1017. PAT serie a Queueing at Bank (25) [simulation] last test points for help!!

Time:01-27

The title here https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968
 
#include
#include
using namespace std;

Struct customer
{
Int arrive_t;
Int need_t;
Int serve_start;
};

The customer customers [10000];
Int Windows [100];//record each window free time

Bool CMP (customer a, customer b) {
Return a.a rrive_t & lt; B.a rrive_t;
}

Int chooseAwindow (int arrive_t, int k) {//choose one of the earliest available time that window
Int choose=1;
Int earliest=17 * 60 * 60 + 2;
for (int i=0; I & lt; k; I++) {
If (Windows [I] Choose=I;
The earliest=Windows [I];
}
}
Return to choose.
}

Int main () {
Int n, k;
Cin & gt;> N & gt;> k;
int count=0;
for (int i=0; I & lt; n; I++) {
Int hh, mm, ss, need_t;
Scanf_s (" % d: % d: % d % d ", & amp; Hh, & amp; Mm, & amp; Ss, & amp; Need_t);
If (hh mm * 60 * 60 * 60 + + ss & gt; 17 * 60 * 60) continue;//than arrive 17:00:01
Customers [count] arrive_t=hh mm * 60 * 60 * 60 + + ss;
Customers [count] need_t=need_t * 60;
Customers [count] serve_start=0;
count++;
}
N=count;//this is the actual can accept the number of customer service
If (n==0) {
Printf (" 0.0 ");
return 0;
}
Sort (customers, customers + n, CMP);
For (int j=0; J & lt; k; J++)
Windows [j]=8 * 60 * 60;//start at 8 o 'clock service
Double the result=0.0;
for (int i=0; I & lt; n; I++) {
Int choice=chooseAwindow (customers [I] arrive_t, k);
If (customers [I] arrive_t & gt; Windows [choice]) {//show window and
Windows (choice)=customers [I] arrive_t + customers [I] need_t;
Customers [I] serve_start=customers [I] arrive_t;
}
The else {//window, such as
The result +=(Windows/choice - customers [I] arrive_t);
Customers [I] serve_start=Windows (choice);
Windows (choice) +=customers [I] need_t;
}
}
Int waitsum=0;
for (int i=0; I & lt; n; I++)
Waitsum +=(customers [I] serve_start - customers [I] arrive_t);
Double avg_wait=waitsum/60.0/n;//here can't write "/(60 * n)"
Printf (" % 1 f ", result/60.0/n);
return 0;
}


Have to consider before 17 o 'clock to 17 points after service also counted, but not the last test points

CodePudding user response:

Input and output format
Boundary condition
.
  • Related