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("NMSCSNP.in");
- ofstream fout("NMSCSNP.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 && b.st <= a.dr && a.sus >= b.jos && b.jos >= a.sus));
- }
- int main()
- {
- int n;
- cin >> n;
- l.resize(n);
- for(int i = 0; i < n; i++)
- {
- Panou aux;
- cin >> aux.sus >> aux.st >> aux.jos >> aux.dr;
- 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]++;
- maxime[i]++;
- maxime[j]++;
- }
- }
- }
- sort(maxime, maxime + n, greater < int >());
- for(int i = 0; i < n; i++)
- {
- if(g[i] == maxime[0])
- {
- q.push(i);
- break;
- }
- }
- int nr = 0;
- int posMax = 1;
- while(!q.empty())
- {
- int k = q.front();
- nr++;
- for(auto elem : l[k])
- {
- g[elem]--;
- if(g[elem] == maxime[posMax] && maxime[posMax])
- {
- cout << elem << ' ' << g[elem] << ' ' << maxime[posMax] << '\n';
- q.push(elem);
- }
- }
- posMax++;
- q.pop();
- }
- cout << n - nr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement