#include <bits/stdc++.h>
using namespace std;
set <int> kursy;
set <pair <pair <int, int>, pair <int, int> > > jakie;
set <pair <pair <int, int>, pair <int, int> > > :: iterator it, itr;
set <int> :: iterator iti;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, a, b, c;
long long wyn = 0;
pair <pair <int, int>, pair <int, int> > o;
pair <pair <int, int>, pair <int, int> > p;
pair <int, int> s;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a >> b >> c;
if(a == 1){
jakie.insert(make_pair(make_pair(c, i), make_pair(b, 0)));
}
else{
jakie.insert(make_pair(make_pair(c, i), make_pair(0, b)));
}
kursy.insert(i);
}
for(it = jakie.begin(); it != jakie.end(); it++){
for(itr = jakie.begin(); itr != it; itr++){
o = *it;
p = *itr;
if(kursy.find(p.first.second) != kursy.end() && kursy.find(o.first.second) != kursy.end() ){
if(o.first.first == p.first.first && o.second.first == p.first.second && o.second.second == p.second.second){
kursy.erase(o.first.second);
kursy.erase(p.first.second);
wyn++;
break;
}
if(o.second.second == 0 && p.second.first == 0){
s = make_pair(o.second.first, p.second.second);
if(p.first.first + s.first == o.first.first+ s.second){
kursy.erase(p.first.second);
kursy.erase(o.first.second);
wyn++;
break;
}
}
if(p.second.second == 0 && o.second.first == 0){
s = make_pair(p.second.first, o.second.second);
if(o.first.first + s.first == p.first.first+ s.second){
kursy.erase(p.first.second);
kursy.erase(o.first.second);
wyn++;
break;
}
}
}
}
}
cout << wyn << '\n';
return 0;
}
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <bits/stdc++.h> using namespace std; set <int> kursy; set <pair <pair <int, int>, pair <int, int> > > jakie; set <pair <pair <int, int>, pair <int, int> > > :: iterator it, itr; set <int> :: iterator iti; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a, b, c; long long wyn = 0; pair <pair <int, int>, pair <int, int> > o; pair <pair <int, int>, pair <int, int> > p; pair <int, int> s; cin >> n; for(int i = 1; i <= n; i++){ cin >> a >> b >> c; if(a == 1){ jakie.insert(make_pair(make_pair(c, i), make_pair(b, 0))); } else{ jakie.insert(make_pair(make_pair(c, i), make_pair(0, b))); } kursy.insert(i); } for(it = jakie.begin(); it != jakie.end(); it++){ for(itr = jakie.begin(); itr != it; itr++){ o = *it; p = *itr; if(kursy.find(p.first.second) != kursy.end() && kursy.find(o.first.second) != kursy.end() ){ if(o.first.first == p.first.first && o.second.first == p.first.second && o.second.second == p.second.second){ kursy.erase(o.first.second); kursy.erase(p.first.second); wyn++; break; } if(o.second.second == 0 && p.second.first == 0){ s = make_pair(o.second.first, p.second.second); if(p.first.first + s.first == o.first.first+ s.second){ kursy.erase(p.first.second); kursy.erase(o.first.second); wyn++; break; } } if(p.second.second == 0 && o.second.first == 0){ s = make_pair(p.second.first, o.second.second); if(o.first.first + s.first == p.first.first+ s.second){ kursy.erase(p.first.second); kursy.erase(o.first.second); wyn++; break; } } } } } cout << wyn << '\n'; return 0; } |
English