Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <cmath>
- #include "Queue.h"
- using namespace std;
- struct TYPE
- {
- int t,d;
- };
- Queue <TYPE> q;
- TYPE clients[NMAX];
- TYPE order;
- int main()
- {
- ifstream cin ("test.in");
- ofstream cout ("test.out");
- int N,T;
- int currentMIN = 0, currentMAX = 0;
- cin>>N>>T;
- for(int i=1;i<=N;++i)
- cin>>clients[i].t>>clients[i].d;
- order.d =clients[1].d;
- order.t =clients[1].t;
- q.enqueue(order);
- int i=2,k=0;
- currentMIN = order.t;
- currentMAX = order.t + order.d;
- //cout<<"Order 1"<<" : expected completion time = "<< order.t + order.d<<", "<<"actual completion time = "<<currentMAX<< "\n";
- while(k<N)
- {
- while( clients[i].t <= currentMAX && clients[i].t >= currentMIN && i<=N)
- {
- q.enqueue(clients[i]);
- ++i;
- }
- q.dequeue();
- cout<<"Order "<<++k<<" : expected completion time = "<< order.t + order.d<<", "<<"actual completion time = "<<currentMAX<< ";\n";
- if(q.isEmpty() && currentMAX <= T && k<N)
- {
- cout<< "The chef takes a break (the queue is empty) between the times "<<currentMAX<<" and "<<clients[i].t<< ";\n";
- currentMAX = clients[i].t;
- }
- if(!q.isEmpty())
- order = q.peek();
- else if(currentMAX <= T)
- {
- q.enqueue(clients[i++]);
- order = q.peek();
- }
- if(k<N)
- currentMIN = currentMAX , currentMAX += order.d;
- }
- if(currentMAX >= T)
- cout<<"After computing the orders, we find out that the last one will be finished at t="<<currentMAX<<". Therefore, we have orders which are completed after the closing of the restaurant.\n";
- else
- cout<<"We don't have orders which are completed after the closing of the restaurant.\n";
- for(i=1,currentMAX=0;i<=N;++i)
- currentMAX = max(currentMAX,clients[i].d);
- cout<<"The maximum duration the chef has to work on an order = "<<currentMAX<<";\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement