Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <set>
  6.  
  7. using namespace std;
  8.  
  9. struct Event {
  10.     int time_;
  11.     int type; //0 - пришел человек, 1 - парикмахер освободился
  12.     int manNum;
  13.     int parNum;
  14.     Event() {}
  15.     Event(int time_, int type, int manNum, int parNum) :time_(time_), type(type),
  16.         manNum(manNum), parNum(parNum) {}
  17.     bool operator <(const Event& other) {
  18.         return time_ < other.time_ || (time_ == other.time_ && type > other.type);
  19.     }
  20. };
  21.  
  22. int main() {
  23.     set<Event> ev;
  24.     int N;
  25.     cin >> N;
  26.     for (int i = 0; i < N; ++i) {
  27.         int h, m;
  28.         cin >> h >> m;
  29.         ev.insert(Event(h * 60 + m, 0, i, -1));
  30.     }
  31.     queue<int> q;
  32.     vector<bool> freePar(3, true);
  33.     vector<int> ans(N);
  34.     while (!ev.empty()) {
  35.         Event cur = *ev.begin();
  36.         ev.erase(ev.begin());
  37.         if (cur.type == 0) {
  38.             bool good = false;
  39.             for (int i = 0; i < 3; ++i) {
  40.                 if (freePar[i]) {
  41.                     ev.insert(Event(cur.time_ + 30, 1, cur.manNum, i));
  42.                     good = true;
  43.                     freePar[i] = false;
  44.                     break;
  45.                 }
  46.             }
  47.             if (!good) {
  48.                 q.push(cur.manNum);
  49.             }
  50.         } else {
  51.             ans[cur.manNum] = cur.time_;
  52.             if (q.empty()) {
  53.                 freePar[cur.parNum] = true;
  54.             } else {
  55.                 int curMan = q.front();
  56.                 q.pop();
  57.                 ev.insert(Event(cur.time_ + 30, 1, curMan, cur.parNum));
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement