这道题一打眼,本来打算用二维前缀和,直接暴力,没想到数组开不了那么大
所以只能去腆着个B脸去看题解(基本上每次都这样)。
思路:从后往后找,找到第一个覆盖(x, y)地毯,直接输出就行了。
(PS:不能从前往后找,会超时)
#include<iostream>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn][5];
int main() {
int n;cin >> n;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= 4;j++)
cin >> a[i][j];
int x, y;
cin >> x >> y;
int ans = 0;
for (int i = n;i > 0;i--) {
if (a[i][1] <= x && a[i][2] <= y && a[i][1] + a[i][3] >= x && a[i][2] + a[i][4] >= y) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
}