Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- using namespace std;
- ifstream fin("reclame.in");
- ofstream fout("reclame.out");
- struct Panou {
- int sus, st;
- int jos, dr;
- };
- int g[1001];
- int maxime[1001];
- queue < int > q;
- vector < vector < int > > l;
- vector < Panou > v;
- bool SeIntersecteaza(Panou a, Panou b)
- {
- return !(a.st > b.dr || a.dr < b.st || a.sus < b.jos || a.jos > b.sus);
- }
- int main()
- {
- int n;
- fin >> n;
- l.resize(n + 1);
- for(int i = 0; i < n; i++)
- {
- Panou aux;
- fin >> aux.st >> aux.jos >> aux.dr >> aux.sus;
- v.push_back(aux);
- }
- for(int i = 0; i < n - 1; i++)
- {
- for(int j = i + 1; j < n; j++)
- {
- if(SeIntersecteaza(v[i], v[j]))
- {
- g[i]++;
- g[j]++;
- l[i].push_back(j);
- l[j].push_back(i);
- }
- }
- }
- int maxim = 0;
- for(int i = 0; i < n; i++)
- {
- maxim = max(maxim, g[i]);
- }
- for(int i = 0; i < n; i++)
- {
- if(g[i] == maxim)
- {
- q.push(i);
- break;
- }
- }
- int nr = 0;
- bool oke = true;
- while(!q.empty() && oke)
- {
- int k = q.front();
- nr++;
- g[k] = -1;
- maxim = 0;
- for(auto elem : l[k])
- {
- g[elem]--;
- }
- for(int i = 0; i < n; i++)
- {
- maxim = max(maxim, g[i]);
- }
- for(auto elem : l[k])
- {
- if(g[elem] == maxim && maxim)
- {
- q.push(elem);
- }
- }
- bool continua = false;
- for(int i = 0; i < n; i++)
- {
- if(g[i] > 0)
- {
- continua = true;
- break;
- }
- }
- if(continua == false)
- {
- oke = false;
- }
- q.pop();
- }
- fout << n - nr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement