#include <iostream> #include <set> #include <map> int main() { int n; std::cin >> n; std::map<std::pair<int, int>, std::set<std::pair<int, int>>> dol; std::map<std::pair<int, int>, std::set<std::pair<int, int>>> lewo; //std::priority_queue<std::pair<int, std::pair<int, int>>> kolizje; for(int i = 0 ; i < n; ++i) { int kierunek, x, t; std::cin >> kierunek >> x >> t; if(kierunek == 1) { std::set<std::pair<int, int>> aktkolizje; for(auto it = lewo.begin(); it != lewo.end(); ++it) { if(t + it->first.first == x + it->first.second) { aktkolizje.insert(it->first); it->second.insert({x, t}); } } dol.insert({{x, t}, aktkolizje}); } else { std::set<std::pair<int, int>> aktkolizje; for(auto it = dol.begin(); it != dol.end(); ++it) { if(t + it->first.first == x + it->first.second) { aktkolizje.insert(it->first); it->second.insert({x, t}); } } lewo.insert({{x, t}, aktkolizje}); } } int usunac = 0; int dir = 1; while(dir != 0) { std::pair<int, int> maxi = {0, 0}; int maxn = 0; dir = 0; for (auto it : dol) { if (it.second.size() > maxn) { maxn = it.second.size(); maxi = it.first; dir = 1; } } for (auto it : lewo) { if (it.second.size() > maxn) { maxn = it.second.size(); maxi = it.first; dir = 2; } } if (dir == 1) { std::set<std::pair<int, int>> usunietekolizje = dol[maxi]; dol.erase(maxi); for (auto it : usunietekolizje) { lewo[it].erase(maxi); } usunac++; } else if (dir == 2) { std::set<std::pair<int,int>> usunietekolizje = lewo[maxi]; lewo.erase(maxi); for(auto it : usunietekolizje) { dol[it].erase(maxi); } usunac++; } } std::cout << usunac << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <iostream> #include <set> #include <map> int main() { int n; std::cin >> n; std::map<std::pair<int, int>, std::set<std::pair<int, int>>> dol; std::map<std::pair<int, int>, std::set<std::pair<int, int>>> lewo; //std::priority_queue<std::pair<int, std::pair<int, int>>> kolizje; for(int i = 0 ; i < n; ++i) { int kierunek, x, t; std::cin >> kierunek >> x >> t; if(kierunek == 1) { std::set<std::pair<int, int>> aktkolizje; for(auto it = lewo.begin(); it != lewo.end(); ++it) { if(t + it->first.first == x + it->first.second) { aktkolizje.insert(it->first); it->second.insert({x, t}); } } dol.insert({{x, t}, aktkolizje}); } else { std::set<std::pair<int, int>> aktkolizje; for(auto it = dol.begin(); it != dol.end(); ++it) { if(t + it->first.first == x + it->first.second) { aktkolizje.insert(it->first); it->second.insert({x, t}); } } lewo.insert({{x, t}, aktkolizje}); } } int usunac = 0; int dir = 1; while(dir != 0) { std::pair<int, int> maxi = {0, 0}; int maxn = 0; dir = 0; for (auto it : dol) { if (it.second.size() > maxn) { maxn = it.second.size(); maxi = it.first; dir = 1; } } for (auto it : lewo) { if (it.second.size() > maxn) { maxn = it.second.size(); maxi = it.first; dir = 2; } } if (dir == 1) { std::set<std::pair<int, int>> usunietekolizje = dol[maxi]; dol.erase(maxi); for (auto it : usunietekolizje) { lewo[it].erase(maxi); } usunac++; } else if (dir == 2) { std::set<std::pair<int,int>> usunietekolizje = lewo[maxi]; lewo.erase(maxi); for(auto it : usunietekolizje) { dol[it].erase(maxi); } usunac++; } } std::cout << usunac << "\n"; } |