#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pii> cars(2e6+8, {0,0});
const int p = 1e6;
for(int i = 0; i < n; i++){
int r, w, t;
cin >> r >> w >> t;
if(r==1){
// coordinates = (w, -t)
cars[w-t+p].first++;
}
else{
// coordinates = (-t, w)
cars[w-t+p].second++;
}
}
int res = 0;
for(auto x : cars){
res += min(x.first, x.second);
}
cout << res << "\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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vii; typedef vector<ll> vll; typedef vector<vector<int> > vvi; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<pii> cars(2e6+8, {0,0}); const int p = 1e6; for(int i = 0; i < n; i++){ int r, w, t; cin >> r >> w >> t; if(r==1){ // coordinates = (w, -t) cars[w-t+p].first++; } else{ // coordinates = (-t, w) cars[w-t+p].second++; } } int res = 0; for(auto x : cars){ res += min(x.first, x.second); } cout << res << "\n"; } |
English