Advertisement
Guest User

cursuri

a guest
Oct 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. #define dim 1000
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("cursuri.in");
  8. ofstream fout("cursuri.out");
  9.  
  10. struct curs
  11. {
  12.     int start,stop;
  13. }v[dim+5],crt;
  14.  
  15. int  cer,n,k;
  16.  
  17. void citire()
  18. {
  19.     fin>>c>>n>>k;
  20.         for(int i=1;i<=n;i++)
  21.             fin>>v[i].start>>v[i].stop;
  22. }
  23.  
  24. bool comp(curs a,curs b)
  25. {
  26.     return a.stop<b.stop;
  27. }
  28.  
  29. void greedy()
  30. {
  31.     int cate=0;
  32.     curs s[dim+5];
  33.         if(c==1)
  34.            {
  35.                for(int i=1;i<=k;i++)
  36.                     s[i].start=s[i].stop=0;
  37.                         for(int i=1;i<=n;i++)
  38.                             {
  39.                                     int p=0;
  40.                                         for(int j=1;j<=k;j++)
  41.                                             if(v[i].start>=s[j].stop)
  42.                                                 p=j;
  43.                                                     if(p)
  44.                                                         s[p]=v[i],cate++;
  45.                             }
  46.             }
  47.                
  48. }
  49.  
  50. int main()
  51. {
  52.     citire();
  53.         sort(v+1,v+n+1,comp);
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement