#include<bits/stdc++.h> using namespace std; struct truck{ int type, pos, time, super; void read(){ cin >> type >> pos >> time; super = time - pos; } }; int t[2000007][2]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, res = 0; cin >> n; for(int i = 0;i < n;i++){ truck a; a.read(); t[a.super + 1000000][a.type - 1]++; } for(int i = 0;i < 2000007;i++) res += min(t[i][0], t[i][1]); cout << res; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<bits/stdc++.h> using namespace std; struct truck{ int type, pos, time, super; void read(){ cin >> type >> pos >> time; super = time - pos; } }; int t[2000007][2]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, res = 0; cin >> n; for(int i = 0;i < n;i++){ truck a; a.read(); t[a.super + 1000000][a.type - 1]++; } for(int i = 0;i < 2000007;i++) res += min(t[i][0], t[i][1]); cout << res; } |