#include <iostream> #include <map> #include <algorithm> using namespace std; struct counter{ int x[2]; }; int main(int argc, char* argv[]) { ios_base::sync_with_stdio (false); int n, i, r, w, t; cin >> n; map<int, counter> m; map<int, counter>::iterator mit, git; for (i = 0; i < n; ++i) { cin >> r >> w >> t; m[w-t].x[r-1]++; } int s = 0; for (mit = m.begin(); mit != m.end(); ++mit) { s += (mit->second.x[0] < mit->second.x[1]) ? mit->second.x[0] : mit->second.x[1]; } cout << s << "\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 | #include <iostream> #include <map> #include <algorithm> using namespace std; struct counter{ int x[2]; }; int main(int argc, char* argv[]) { ios_base::sync_with_stdio (false); int n, i, r, w, t; cin >> n; map<int, counter> m; map<int, counter>::iterator mit, git; for (i = 0; i < n; ++i) { cin >> r >> w >> t; m[w-t].x[r-1]++; } int s = 0; for (mit = m.begin(); mit != m.end(); ++mit) { s += (mit->second.x[0] < mit->second.x[1]) ? mit->second.x[0] : mit->second.x[1]; } cout << s << "\n"; } |