//10.12.20 23:05 start
#include <iostream>
#include <vector>
using namespace std;
class patata
{
public:
int start;
int time;
int num_of_col = 0;
patata(int start, int time){
this->start = start;
this->time = time;
}//data
};
void check_if_collide(patata &a, patata &b)
{
static int time_first;
static int time_second;
time_first = a.time + b.start;
time_second = b.time + a.start;
if(time_first == time_second){
++a.num_of_col;
++b.num_of_col;
//cout<<"kolizja!\n";
}//if
return;
}//check if collide
int main()
{
vector<patata> tab1;
vector<patata> tab2;
int g_type;
int g_ind;
int num_of_col = 0;
int score = 0;
int i,j;
int n;
cin>>n;
int start;
int type;
int time;
for(i=0;i<n;++i){
cin>>type;
cin>>start;
cin>>time;
if(type == 1) tab1.push_back(patata(start,time));
else tab2.push_back(patata(start,time));
}//for
while(true){
num_of_col = 0;
for(i=0;i<tab1.size();++i){
for(j=0;j<tab2.size();++j){
check_if_collide(tab1[i],tab2[j]);
}//for2
}//for
for(i=0;i<tab1.size();++i) {
if(tab1[i].num_of_col > num_of_col){
num_of_col = tab1[i].num_of_col;
g_type = 1;
g_ind = i;
}//if
}//for
for(i=0;i<tab2.size();++i) {
if(tab2[i].num_of_col > num_of_col){
num_of_col = tab2[i].num_of_col;
g_type = 2;
g_ind = i;
}//if
}//for
if(!num_of_col) break;
++score;
//cout<<"Usuwamy typ o danych "<<g_type<<endl;
if(g_type == 1) tab1.erase(tab1.begin() + g_ind);
else tab2.erase(tab2.begin() + g_ind);
for(i=0;i<tab1.size();++i) tab1[i].num_of_col = 0;
for(i=0;i<tab2.size();++i) tab2[i].num_of_col = 0;
//cout<<"koniec lajla\n";
}//while
cout<<score;
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 | //10.12.20 23:05 start #include <iostream> #include <vector> using namespace std; class patata { public: int start; int time; int num_of_col = 0; patata(int start, int time){ this->start = start; this->time = time; }//data }; void check_if_collide(patata &a, patata &b) { static int time_first; static int time_second; time_first = a.time + b.start; time_second = b.time + a.start; if(time_first == time_second){ ++a.num_of_col; ++b.num_of_col; //cout<<"kolizja!\n"; }//if return; }//check if collide int main() { vector<patata> tab1; vector<patata> tab2; int g_type; int g_ind; int num_of_col = 0; int score = 0; int i,j; int n; cin>>n; int start; int type; int time; for(i=0;i<n;++i){ cin>>type; cin>>start; cin>>time; if(type == 1) tab1.push_back(patata(start,time)); else tab2.push_back(patata(start,time)); }//for while(true){ num_of_col = 0; for(i=0;i<tab1.size();++i){ for(j=0;j<tab2.size();++j){ check_if_collide(tab1[i],tab2[j]); }//for2 }//for for(i=0;i<tab1.size();++i) { if(tab1[i].num_of_col > num_of_col){ num_of_col = tab1[i].num_of_col; g_type = 1; g_ind = i; }//if }//for for(i=0;i<tab2.size();++i) { if(tab2[i].num_of_col > num_of_col){ num_of_col = tab2[i].num_of_col; g_type = 2; g_ind = i; }//if }//for if(!num_of_col) break; ++score; //cout<<"Usuwamy typ o danych "<<g_type<<endl; if(g_type == 1) tab1.erase(tab1.begin() + g_ind); else tab2.erase(tab2.begin() + g_ind); for(i=0;i<tab1.size();++i) tab1[i].num_of_col = 0; for(i=0;i<tab2.size();++i) tab2[i].num_of_col = 0; //cout<<"koniec lajla\n"; }//while cout<<score; return 0; } |
English