This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#define N 200000
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int xx1[N], xx2[N], yy1[N], yy2[N], xx[N], yy[N], n;
int pierced(int i, int k) {
int h;
for (h = 0; h < k; h++)
if (xx1[i] <= xx[h] && xx[h] <= xx2[i] && yy1[i] <= yy[h] && yy[h] <= yy2[i])
return 1;
return 0;
}
void solve(int k_, int k) {
int h, i, x1, x2, y1, y2;
x1 = INF, x2 = -1, y1 = INF, y2 = -1;
for (i = 0; i < n; i++)
if (!pierced(i, k_)) {
x1 = min(x1, xx2[i]), x2 = max(x2, xx1[i]);
y1 = min(y1, yy2[i]), y2 = max(y2, yy1[i]);
}
if (x1 == INF) {
for (h = k_; h < k; h++)
xx[h] = 1, yy[h] = 1;
for (h = 0; h < k; h++)
printf("%d %d\n", xx[h], yy[h]);
exit(0);
} else if (k_ < k) {
xx[k_] = x1, yy[k_] = y1, solve(k_ + 1, k);
xx[k_] = x1, yy[k_] = y2, solve(k_ + 1, k);
xx[k_] = x2, yy[k_] = y1, solve(k_ + 1, k);
xx[k_] = x2, yy[k_] = y2, solve(k_ + 1, k);
}
}
int main() {
int k, i;
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++)
scanf("%d%d%d%d", &xx1[i], &yy1[i], &xx2[i], &yy2[i]);
solve(0, k);
return 0;
}
Compilation message (stderr)
hamburg.c: In function 'main':
hamburg.c:47:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
hamburg.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d%d%d%d", &xx1[i], &yy1[i], &xx2[i], &yy2[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |