#include<cstdio>
#include<vector>
#include<algorithm>
int main() {
// ri, wi i ti
int n;
scanf("%d", &n);
int OFFSET = 2e6;
std::vector<int> X(4e6, 0), Y(4e6, 0);
int max_x = 0, max_y = 0;
int min_x = 4e6, min_y = 4e6;
for (int i = 0; i < n; ++i) {
int r, w, t;
scanf("%d %d %d", &r, &w, &t);
w += OFFSET;
if (r == 1) {
X[w-t] += 1;
max_x = std::max(max_x, w-t);
min_x = std::min(min_x, w-t);
} else {
Y[w-t] += 1;
min_y = std::min(min_y, w-t);
max_y = std::max(max_y, w-t);
}
}
int ret = 0;
for (int i = std::max(min_x, min_y); i <= std::min(max_x, max_y); ++i) {
if (X[i] && Y[i]) {
ret += std::min(X[i], Y[i]);
//printf("[%d] X= %d Y= %d\n", i, X[i], Y[i]);
}
}
printf("%d\n", ret);
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 | #include<cstdio> #include<vector> #include<algorithm> int main() { // ri, wi i ti int n; scanf("%d", &n); int OFFSET = 2e6; std::vector<int> X(4e6, 0), Y(4e6, 0); int max_x = 0, max_y = 0; int min_x = 4e6, min_y = 4e6; for (int i = 0; i < n; ++i) { int r, w, t; scanf("%d %d %d", &r, &w, &t); w += OFFSET; if (r == 1) { X[w-t] += 1; max_x = std::max(max_x, w-t); min_x = std::min(min_x, w-t); } else { Y[w-t] += 1; min_y = std::min(min_y, w-t); max_y = std::max(max_y, w-t); } } int ret = 0; for (int i = std::max(min_x, min_y); i <= std::min(max_x, max_y); ++i) { if (X[i] && Y[i]) { ret += std::min(X[i], Y[i]); //printf("[%d] X= %d Y= %d\n", i, X[i], Y[i]); } } printf("%d\n", ret); return 0; } |
English