Advertisement
PedalaVasile

NMSCSNP

Jan 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. ifstream fin("NMSCSNP.in");
  10. ofstream fout("NMSCSNP.out");
  11.  
  12.  
  13. struct Panou {
  14.     int sus, st;
  15.     int jos, dr;
  16. };
  17.  
  18.  
  19. int g[1001];
  20. int maxime[1001];
  21.  
  22. queue < int > q;
  23.  
  24. vector < vector < int > > l;
  25. vector < Panou > v;
  26.  
  27. bool SeIntersecteaza(Panou a, Panou b)
  28. {
  29.     return (!(a.st <= b.dr && b.st <= a.dr && a.sus >= b.jos && b.jos >= a.sus));
  30. }
  31.  
  32. int main()
  33. {
  34.     int n;
  35.  
  36.     cin >> n;
  37.  
  38.     l.resize(n);
  39.  
  40.     for(int i = 0; i < n; i++)
  41.     {
  42.         Panou aux;
  43.  
  44.         cin >> aux.sus >> aux.st >> aux.jos >> aux.dr;
  45.  
  46.         v.push_back(aux);
  47.     }
  48.  
  49.     for(int i = 0; i < n - 1; i++)
  50.     {
  51.         for(int j = i + 1; j < n; j++)
  52.         {
  53.             if(SeIntersecteaza(v[i], v[j]))
  54.             {
  55.                 g[i]++;
  56.                 g[j]++;
  57.                 maxime[i]++;
  58.                 maxime[j]++;
  59.             }
  60.         }
  61.     }
  62.  
  63.     sort(maxime, maxime + n, greater < int >());
  64.  
  65.     for(int i = 0; i < n; i++)
  66.     {
  67.         if(g[i] == maxime[0])
  68.         {
  69.             q.push(i);
  70.             break;
  71.         }
  72.     }
  73.  
  74.     int nr = 0;
  75.     int posMax = 1;
  76.  
  77.     while(!q.empty())
  78.     {
  79.         int k = q.front();
  80.         nr++;
  81.  
  82.         for(auto elem : l[k])
  83.         {
  84.             g[elem]--;
  85.             if(g[elem] == maxime[posMax] && maxime[posMax])
  86.             {
  87.                 cout << elem << ' ' << g[elem] << ' ' << maxime[posMax] << '\n';
  88.                 q.push(elem);
  89.             }
  90.         }
  91.  
  92.         posMax++;
  93.         q.pop();
  94.     }
  95.  
  96.     cout << n - nr;
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement