Advertisement
PedalaVasile

Reclame

Jan 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 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("reclame.in");
  10. ofstream fout("reclame.out");
  11.  
  12. struct Panou {
  13.     int sus, st;
  14.     int jos, dr;
  15. };
  16.  
  17.  
  18. int g[1001];
  19. int maxime[1001];
  20.  
  21. queue < int > q;
  22.  
  23. vector < vector < int > > l;
  24. vector < Panou > v;
  25.  
  26. bool SeIntersecteaza(Panou a, Panou b)
  27. {
  28.     return !(a.st > b.dr || a.dr < b.st || a.sus < b.jos || a.jos > b.sus);
  29. }
  30.  
  31. int main()
  32. {
  33.     int n;
  34.  
  35.     fin >> n;
  36.  
  37.     l.resize(n + 1);
  38.  
  39.     for(int i = 0; i < n; i++)
  40.     {
  41.         Panou aux;
  42.  
  43.         fin >> aux.st >> aux.jos >> aux.dr >> aux.sus;
  44.  
  45.         v.push_back(aux);
  46.     }
  47.  
  48.     for(int i = 0; i < n - 1; i++)
  49.     {
  50.         for(int j = i + 1; j < n; j++)
  51.         {
  52.             if(SeIntersecteaza(v[i], v[j]))
  53.             {
  54.                 g[i]++;
  55.                 g[j]++;
  56.  
  57.                 l[i].push_back(j);
  58.                 l[j].push_back(i);
  59.             }
  60.         }
  61.  
  62.     }
  63.  
  64.     int maxim = 0;
  65.  
  66.     for(int i = 0; i < n; i++)
  67.     {
  68.         maxim = max(maxim, g[i]);
  69.     }
  70.  
  71.     for(int i = 0; i < n; i++)
  72.     {
  73.         if(g[i] == maxim)
  74.         {
  75.             q.push(i);
  76.             break;
  77.         }
  78.     }
  79.  
  80.     int nr = 0;
  81.     bool oke = true;
  82.  
  83.     while(!q.empty() && oke)
  84.     {
  85.         int k = q.front();
  86.         nr++;
  87.  
  88.         g[k] = -1;
  89.  
  90.         maxim = 0;
  91.  
  92.         for(auto elem : l[k])
  93.         {
  94.             g[elem]--;
  95.         }
  96.  
  97.         for(int i = 0; i < n; i++)
  98.         {
  99.             maxim = max(maxim, g[i]);
  100.         }
  101.  
  102.         for(auto elem : l[k])
  103.         {
  104.             if(g[elem] == maxim && maxim)
  105.             {
  106.                 q.push(elem);
  107.             }
  108.  
  109.         }
  110.  
  111.         bool continua = false;
  112.  
  113.         for(int i = 0; i < n; i++)
  114.         {
  115.             if(g[i] > 0)
  116.             {
  117.                 continua = true;
  118.                 break;
  119.             }
  120.         }
  121.  
  122.         if(continua == false)
  123.         {
  124.             oke = false;
  125.         }
  126.  
  127.  
  128.  
  129.         q.pop();
  130.     }
  131.  
  132.     fout << n - nr;
  133.  
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement