#include <cstdio> #include <vector> #include <map> using namespace std; #define FOR(i,a,b) for(int (i)=(int)(a); (i)!=(int)(b); ++(i)) map<int, int> M[2]; int n, r, w, t; int main() { scanf("%d", &n); FOR(i,0,n) { scanf("%d %d %d", &r, &w, &t); M[r-1][w - t] += 1; } int result = 0; for (map<int, int>::iterator it0 = M[0].begin(); it0 != M[0].end(); ++it0) { map<int, int>::iterator it1 = M[1].find(it0->first); if (it1 == M[1].end()) continue; result += min(it0->second, it1->second); } printf("%d\n", result); }
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 | #include <cstdio> #include <vector> #include <map> using namespace std; #define FOR(i,a,b) for(int (i)=(int)(a); (i)!=(int)(b); ++(i)) map<int, int> M[2]; int n, r, w, t; int main() { scanf("%d", &n); FOR(i,0,n) { scanf("%d %d %d", &r, &w, &t); M[r-1][w - t] += 1; } int result = 0; for (map<int, int>::iterator it0 = M[0].begin(); it0 != M[0].end(); ++it0) { map<int, int>::iterator it1 = M[1].find(it0->first); if (it1 == M[1].end()) continue; result += min(it0->second, it1->second); } printf("%d\n", result); } |