Advertisement
STANAANDREY

problema planificarii spectacolelor

Dec 7th, 2020 (edited)
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. #define NMAX 100
  5. int n, k;
  6.  
  7. struct Time {
  8.     int h, mins;
  9.     bool operator < (const Time &other) const  {
  10.         if (h == other.h)
  11.             return mins < other.mins;
  12.         return h < other.h;
  13.     }
  14. };
  15.  
  16. struct Spectacol {
  17.     Time st, sf;
  18.     bool operator < (const Spectacol &other) const {
  19.         return sf < other.sf;
  20.     }
  21. } vs[NMAX], sol[NMAX];
  22.  
  23. void read() {
  24.     cin >> n;
  25.     for (int i = 1; i <= n; i++) {
  26.         cin >> vs[i].st.h >> vs[i].st.mins;
  27.         cin >> vs[i].sf.h >> vs[i].sf.mins;
  28.     }
  29. }
  30.  
  31. void greedy() {
  32.     sol[++k] = vs[1];
  33.     int j = 1;
  34.     for (int i = 2; i <= n; i++) {
  35.         if (vs[j].sf < vs[i].st) {
  36.             sol[++k] = vs[i];
  37.             j = i;
  38.         }
  39.     }
  40. }
  41.  
  42. void display(Spectacol v[]) {
  43.     for (int i = 1; i <= k; i++) {
  44.         cout << "spectacol " << i << " programat de la " << v[i].st.h<< ':' << v[i].st.mins << " la ";
  45.         cout << v[i].sf.h << ':' << v[i].sf.mins << endl;
  46.     }
  47. }
  48.  
  49. int main() {
  50.     read();
  51.     sort(vs + 1, vs + n + 1);//sortez crescator dupa ora de sfarsit
  52.     greedy();
  53.     display(sol);
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement