模拟;
没看到这句话:在 x 轴和 y 轴方向的长度
导致写了个错误代码,WA了一整子:
WA 5/10:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1;
int n, x, y;
int a[N], b[N], c[N], d[N];
int main() {
cin >> n;
for (int e = 1; e <= n; cin >> a[e] >> b[e]>> c[e] >> d[e], e ++ );
cin >> x >> y;
for (int e = n; e >= 1; e -- )
if (x >= min(a[e], c[e]) and
x <= max(a[e], c[e]) and
y >= min(b[e], d[e]) and
y <= max(b[e], d[e]))
return cout << e, 0; cout << -1;
}
AC:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 1;
int n, x, y;
int a[N], b[N], c[N], d[N];
int main() {
cin >> n;
for (int e = 1; e <= n; cin >> a[e] >> b[e]>> c[e] >> d[e], e ++ );
cin >> x >> y;
for (int e = n; e >= 1; e -- )
if (x >= a[e] and
x <= a[e] + c[e] and
y >= b[e] and
y <= b[e] + d[e])
return cout << e, 0; cout << -1;
}