直接从后面向前面找就可以了。
#include<iostream> using namespace std; const int maxn = 1e4 + 10; struct node{ int x1, y1, x2, y2; }num[maxn]; int n, x, y, a, b, ans=-1; int main(){ cin >> n; for (int i = 1; i <= n; ++i) { cin >> x >> y>>a>>b; num[i].x1 = x; num[i].y1 = y; num[i].x2 = x + a; num[i].y2 = y + b; } cin >> x >> y; for (int i = n; i >= 1; --i) if (num[i].x1 <= x&&num[i].y1 <= y&&num[i].x2 >= x&&num[i].y2 >= y){ ans = i; break; } cout << ans << endl; }