#include <bits/stdc++.h> using namespace std; struct Data{ int r,w,t; }; auto max_in_vector(vector<pair<int,int>>v,int n){ vector<int>vec(n,0); for(int i=0; i<n; ++i) vec[i] = 0; for(auto &a:v){ vec[a.first]++; vec[a.second]++; } auto max_e = *max_element(vec.begin(),vec.end()); int max_num; for(int i=0; i<n; ++i){ if(vec[i]==max_e) max_num = i; } return max_num; } auto set_num(vector<pair<int,int>>&v,int n,int max_num){ for(int i=0; i<n; ++i){ if(v[i].first == max_num || v[i].second == max_num){ v.erase(v.begin()+i); } } return v.size(); } int main() { vector<pair<int,int>>v; int n; cin >> n; Data data [n]; for(int i=0; i<n; ++i){ int r,w,t; cin >> r >> w >> t; data[i].r = r; data[i].w = w; data[i].t = t; } for(int i=0; i<n; ++i){ for(int j=i+1; j<n; ++j){ int wx,wy,wx1,wy1; if(data[i].r == data[j].r){ continue; } if(data[i].r==1){ wx = data[i].w; wy = 0; } else { wx = 0; wy = data[i].w; } if(data[j].r==1){ wx1 = data[j].w; wy1 = 0; } else { wx1 = 0; wy1 = data[j].w; } if(wx==wx1 && wy==wy1){ v.push_back(make_pair(i,j)); } ////DODANIE ROZNICY CZASU int diff; if(data[i].r ==1){ wy -= (data[i].t-data[j].t); }else{ wx -= (data[i].t-data[j].t); } ///// //cout << wx << " " << wy << " " << wx1 << " " << wy1 << endl; int roznica,roznica1; //m1,m2 wieksze liczby roznica = wx - wx1; roznica1 = wy1 - wy; //cout << roznica << " / " << roznica1 << endl; if(roznica == roznica1){ v.push_back(make_pair(i,j)); } } } //SZUKANIE NAJCZESTSZEJ LICZBY W WEKTORZE //int * tab = new int[n]; int size_ = v.size(); int counter = 0; while(size_>0){ int max_num = max_in_vector(v,n); size_ = set_num(v,n,max_num); counter++; } cout <<counter; 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #include <bits/stdc++.h> using namespace std; struct Data{ int r,w,t; }; auto max_in_vector(vector<pair<int,int>>v,int n){ vector<int>vec(n,0); for(int i=0; i<n; ++i) vec[i] = 0; for(auto &a:v){ vec[a.first]++; vec[a.second]++; } auto max_e = *max_element(vec.begin(),vec.end()); int max_num; for(int i=0; i<n; ++i){ if(vec[i]==max_e) max_num = i; } return max_num; } auto set_num(vector<pair<int,int>>&v,int n,int max_num){ for(int i=0; i<n; ++i){ if(v[i].first == max_num || v[i].second == max_num){ v.erase(v.begin()+i); } } return v.size(); } int main() { vector<pair<int,int>>v; int n; cin >> n; Data data [n]; for(int i=0; i<n; ++i){ int r,w,t; cin >> r >> w >> t; data[i].r = r; data[i].w = w; data[i].t = t; } for(int i=0; i<n; ++i){ for(int j=i+1; j<n; ++j){ int wx,wy,wx1,wy1; if(data[i].r == data[j].r){ continue; } if(data[i].r==1){ wx = data[i].w; wy = 0; } else { wx = 0; wy = data[i].w; } if(data[j].r==1){ wx1 = data[j].w; wy1 = 0; } else { wx1 = 0; wy1 = data[j].w; } if(wx==wx1 && wy==wy1){ v.push_back(make_pair(i,j)); } ////DODANIE ROZNICY CZASU int diff; if(data[i].r ==1){ wy -= (data[i].t-data[j].t); }else{ wx -= (data[i].t-data[j].t); } ///// //cout << wx << " " << wy << " " << wx1 << " " << wy1 << endl; int roznica,roznica1; //m1,m2 wieksze liczby roznica = wx - wx1; roznica1 = wy1 - wy; //cout << roznica << " / " << roznica1 << endl; if(roznica == roznica1){ v.push_back(make_pair(i,j)); } } } //SZUKANIE NAJCZESTSZEJ LICZBY W WEKTORZE //int * tab = new int[n]; int size_ = v.size(); int counter = 0; while(size_>0){ int max_num = max_in_vector(v,n); size_ = set_num(v,n,max_num); counter++; } cout <<counter; return 0; } |