#include <bits/stdc++.h>
using namespace std;
const int N = 200009;
const long long H1 = 1e13, H2 =1e6+7;
unordered_map<long long, int> m;
unordered_map<int, int> count_cars[2];
void solve() {
int n;
cin >> n;
int res = 0;
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
if (m.find(H1*a + H2*b + c) != m.end()) {
res++;
continue;
}
m[H1*a + H2*b + c]++;
count_cars[a - 1][b - c]++;
}
for (int i = 0; i < 2; i++) {
int j = i ^ 1;
for (auto it : count_cars[i]) {
if (it.second < count_cars[j][it.first] || (it.second == count_cars[j][it.first] && i == 0))
res += it.second;
}
}
cout << res;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while(t--)
solve();
}
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 | #include <bits/stdc++.h> using namespace std; const int N = 200009; const long long H1 = 1e13, H2 =1e6+7; unordered_map<long long, int> m; unordered_map<int, int> count_cars[2]; void solve() { int n; cin >> n; int res = 0; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; if (m.find(H1*a + H2*b + c) != m.end()) { res++; continue; } m[H1*a + H2*b + c]++; count_cars[a - 1][b - c]++; } for (int i = 0; i < 2; i++) { int j = i ^ 1; for (auto it : count_cars[i]) { if (it.second < count_cars[j][it.first] || (it.second == count_cars[j][it.first] && i == 0)) res += it.second; } } cout << res; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //cout << fixed << setprecision(15); int t = 1; //cin >> t; while(t--) solve(); } |
English