Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cmath>
  4. #include "Queue.h"
  5.  
  6. using namespace std;
  7.  
  8. struct TYPE
  9. {
  10. int t,d;
  11.  
  12. };
  13.  
  14. Queue <TYPE> q;
  15. TYPE clients[NMAX];
  16. TYPE order;
  17.  
  18. int main()
  19. {
  20. ifstream cin ("test.in");
  21. ofstream cout ("test.out");
  22.  
  23. int N,T;
  24. int currentMIN = 0, currentMAX = 0;
  25.  
  26. cin>>N>>T;
  27.  
  28. for(int i=1;i<=N;++i)
  29. cin>>clients[i].t>>clients[i].d;
  30.  
  31. order.d =clients[1].d;
  32. order.t =clients[1].t;
  33.  
  34. q.enqueue(order);
  35.  
  36. int i=2,k=0;
  37.  
  38. currentMIN = order.t;
  39. currentMAX = order.t + order.d;
  40. //cout<<"Order 1"<<" : expected completion time = "<< order.t + order.d<<", "<<"actual completion time = "<<currentMAX<< "\n";
  41.  
  42. while(k<N)
  43. {
  44.  
  45. while( clients[i].t <= currentMAX && clients[i].t >= currentMIN && i<=N)
  46. {
  47. q.enqueue(clients[i]);
  48. ++i;
  49. }
  50.  
  51. q.dequeue();
  52.  
  53. cout<<"Order "<<++k<<" : expected completion time = "<< order.t + order.d<<", "<<"actual completion time = "<<currentMAX<< ";\n";
  54.  
  55. if(q.isEmpty() && currentMAX <= T && k<N)
  56. {
  57. cout<< "The chef takes a break (the queue is empty) between the times "<<currentMAX<<" and "<<clients[i].t<< ";\n";
  58. currentMAX = clients[i].t;
  59. }
  60.  
  61.  
  62.  
  63. if(!q.isEmpty())
  64. order = q.peek();
  65. else if(currentMAX <= T)
  66. {
  67. q.enqueue(clients[i++]);
  68. order = q.peek();
  69.  
  70. }
  71. if(k<N)
  72. currentMIN = currentMAX , currentMAX += order.d;
  73.  
  74.  
  75.  
  76. }
  77.  
  78. if(currentMAX >= T)
  79. 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";
  80. else
  81. cout<<"We don't have orders which are completed after the closing of the restaurant.\n";
  82.  
  83. for(i=1,currentMAX=0;i<=N;++i)
  84. currentMAX = max(currentMAX,clients[i].d);
  85. cout<<"The maximum duration the chef has to work on an order = "<<currentMAX<<";\n";
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement