#include <iostream> #include <vector> using namespace std; const int offset = 1000010; int main(){ std::ios::sync_with_stdio(false); cin.tie(0); vector<int> X,Y; int n; cin>>n; X.resize(offset*2+1); Y.resize(offset*2+1); while (n-->0){ int r,w,t; cin>>r>>w>>t; if (r==1) X[t-w+offset]++; else Y[t-w+offset]++; } int counter=0; for (size_t i=0; i<X.size(); i++ ){ counter += min( X[i],Y[i] ); } cout<<counter<<endl; }
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 | #include <iostream> #include <vector> using namespace std; const int offset = 1000010; int main(){ std::ios::sync_with_stdio(false); cin.tie(0); vector<int> X,Y; int n; cin>>n; X.resize(offset*2+1); Y.resize(offset*2+1); while (n-->0){ int r,w,t; cin>>r>>w>>t; if (r==1) X[t-w+offset]++; else Y[t-w+offset]++; } int counter=0; for (size_t i=0; i<X.size(); i++ ){ counter += min( X[i],Y[i] ); } cout<<counter<<endl; } |