#include <iostream> #include <map> #include <set> #include <vector> using namespace std; int MAX = 1000000; int main() { int n, a1, a2, a3; std::cin >> n; map<int, int> m1, m2; map<int, int> *m; for(int i = 0; i < n; i++) { cin >> a1 >> a2 >> a3; if(a1 == 1) m = &m1; else m = &m2; int tmp = a2 + (MAX - a3); auto it = m->find(tmp); if(it == m->end()) m->insert({tmp, 1}); else it->second++; } int ret = 0; auto it1 = m1.begin(); auto it2 = m2.begin(); while(it1 != m1.end() && it2 != m2.end()) { if(it1->first < it2->first) { it1++; continue; } if(it1->first > it2->first) { it2++; continue; } ret += min(it2->second, it2->second); it1++; it2++; } cout << ret << endl; return 0; }
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 | #include <iostream> #include <map> #include <set> #include <vector> using namespace std; int MAX = 1000000; int main() { int n, a1, a2, a3; std::cin >> n; map<int, int> m1, m2; map<int, int> *m; for(int i = 0; i < n; i++) { cin >> a1 >> a2 >> a3; if(a1 == 1) m = &m1; else m = &m2; int tmp = a2 + (MAX - a3); auto it = m->find(tmp); if(it == m->end()) m->insert({tmp, 1}); else it->second++; } int ret = 0; auto it1 = m1.begin(); auto it2 = m2.begin(); while(it1 != m1.end() && it2 != m2.end()) { if(it1->first < it2->first) { it1++; continue; } if(it1->first > it2->first) { it2++; continue; } ret += min(it2->second, it2->second); it1++; it2++; } cout << ret << endl; return 0; } |