Advertisement
AlexandruDu

Problema Spectacolelor V2

Dec 8th, 2020 (edited)
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct timp{int h,m,x;};
  4. struct {timp s,f;int cod;}v[101];
  5. int n,i,j,sol[101],k;
  6. void greedy()
  7. {
  8.     k=1;
  9.     sol[1]=1;
  10.     int j=1;
  11.     for(int i=1;i<=n;i++)
  12.         if(v[i].s.x>=v[j].f.x)
  13.         {
  14.             sol[++k]=i;
  15.             j=i;
  16.         }
  17. }
  18. int main()
  19. {
  20.     //citire
  21.     cin>>n;
  22.     for(i=1;i<=n;i++)
  23.     {
  24.         v[i].cod=i;
  25.         cin>>v[i].s.h>>v[i].s.m;
  26.         v[i].s.x=v[i].s.h*60+v[i].s.m;
  27.         cin>>v[i].f.h>>v[i].f.m;
  28.         v[i].f.x=v[i].f.h*60+v[i].f.m;
  29.     }
  30.     //sortare
  31.     for(i=1;i<n;i++)
  32.         for(j=i+1;j<=n;j++)
  33.             if(v[i].f.x>v[j].f.x) swap(v[i],v[j]);
  34.     greedy();
  35.     //afisare
  36.     for(i=1;i<=k;i++)
  37.         cout<<endl<<v[sol[i]].cod<<' '<<v[sol[i]].s.h<<' '<<v[sol[i]].s.m<<" - "
  38.         <<v[sol[i]].f.h<<' '<<v[sol[i]].f.m;
  39.     return 0;
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement