Title Description
Assuming that banks have K windows provide services, set up a yellow line before the window, all customers in arrival time after the yellow line arranged in a long queue. When a window is idle, the next customer that is the window to process transactions. Alternatively, when a plurality of windows, assuming the customer is always selects the lowest numbered window.
This question came to wait for service request output of the average N-bit customer waiting time, the maximum waiting time, to complete the final time.
Entry
Enter line 1 gives a positive integer N ( ≤), the total number of customers; followed by N lines, each line gives every customer's arrival time T
and transaction time P
, and assume that the input data according to the time of arrival has already lined up order ; the last line gives a positive integer K ( ≤), the number of windows opened to business.
Export
The average waiting time the output line (output to one decimal place), the maximum waiting time, time last completed, separated by a space between the end of the line can not have extra space.
Sample input
Sample Output
prompt
#include<iostream> #include<queue> #include<iomanip> using namespace std; int queindex(int total,queue<int>Q) { int index=0; queue<int>temp=Q; while(!temp.empty()) { temp.pop(); index++; } return total-index+1; } int main () { int virclock=0; double averagewait=0; int maxwait=0; int alreadytime=0; Queue < int > arrivetime; /// customers to time Queue < int > solvetime; /// do business time int T; CIN >> T; int TIMEWAIT [T]; /// each customer waiting time, the initialization is 0 for ( int I = 0 ; I <T; I ++ ) timewait[i]=0; for(int i=0;i<T;i++) { int n,t; cin>>n>>t; arrivetime.push(n); solvetime.push(t); } int K; cin>>K; queue<int>bank[K]; int done=0; while(done==0) { for(int i=0;i<K;i++) { IF (Bank [I] .empty ()) /// bank gapped { IF (! arrivetime.empty () && arrivetime.front () <= virclock) /// was bank { bank[i].push(solvetime.front()); arrivetime.pop(); solvetime.pop (); } } } int bankemp = 0 ; /// bank and several vacancies, vacancy when a judgment is 0 if there are people waiting for ( int I = 0 ; I <K; I ++ ) IF (Bank [I] .empty () ) bankemp ++ ; if (bankemp == 0 ) { Queue < int > the TEMP = arrivetime; the while (! temp.empty () && temp.front () <= virclock) /// If someone like he was the first to find a few clients, array plus waiting time { int Number The = queindex ( T, temp); timewait[number-1]+=1; temp.pop(); } } for ( int I = 0 ; I <K; I ++) /// the minute processing { IF (! Bank [I] .empty ()) { int temp=bank[i].front()-1; bank[i].pop(); bank[i].push(temp); if(bank[i].front()==0) { bank[i].pop(); } } } int EMP = . 1 ; /// determining whether a complete end for ( int I = 0 ; I <K; I ++ ) { if(!bank[i].empty()) { emp=0; break; } } if(emp==1&&arrivetime.empty()&&solvetime.empty()) done=1; virclock ++; /// into the next min } for ( int I = 0 ; I <T; I ++) /// calculates the average waiting time and the maximum waiting time { IF (maxWait < TIMEWAIT [I]) maxwait=timewait[i]; averagewait+=timewait[i]; } averagewait/=T; alreadytime=virclock; cout<<fixed<<setprecision(1)<<averagewait<<" "; cout<<maxwait<<" "; cout<<alreadytime<<endl; return 0; }