#include <iostream>
#define LIMIT 2000000
using namespace std;
int main(){
static int tab[2][LIMIT];
for (int i = 0; i<2;i++)
for(int j=0;j<LIMIT;j++)
tab[i][j]=0;
int n;
scanf("%d",&n);
for(int i =0;i<n;i++){
int type, pos, time;
scanf("%d %d %d",&type,&pos,&time);
tab[type-1][time-pos+LIMIT/2]+=1;
}
/*for(int i =0;i<10;i++)
printf("[%d]=%d\n",i,tab[0][i]);
cout<<"-------\n";
for(int i =0;i<10;i++)
printf("[%d]=%d\n",i,tab[1][i]);
*/
int counter=0;
for(int i = 0; i<LIMIT;i++){
if(tab[0][i]!=0 && tab[1][i]!=0){//kolizja
counter+=min(tab[0][i],tab[1][i]);
}
}
printf("%d", 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 | #include <iostream> #define LIMIT 2000000 using namespace std; int main(){ static int tab[2][LIMIT]; for (int i = 0; i<2;i++) for(int j=0;j<LIMIT;j++) tab[i][j]=0; int n; scanf("%d",&n); for(int i =0;i<n;i++){ int type, pos, time; scanf("%d %d %d",&type,&pos,&time); tab[type-1][time-pos+LIMIT/2]+=1; } /*for(int i =0;i<10;i++) printf("[%d]=%d\n",i,tab[0][i]); cout<<"-------\n"; for(int i =0;i<10;i++) printf("[%d]=%d\n",i,tab[1][i]); */ int counter=0; for(int i = 0; i<LIMIT;i++){ if(tab[0][i]!=0 && tab[1][i]!=0){//kolizja counter+=min(tab[0][i],tab[1][i]); } } printf("%d", counter); return 0; } |
English