??? 这道题目,其实不用怎么想,数据有大,不过一次遍历搜索就可以完成。
??? 首先读入数据,储存在数组中,然后从数组的尾部向前面搜索判断,就可以了。。
?
class="cpp" name="code">#include <iostream> #include <stdio.h> using namespace std; int main() { int t; int n, m; int r, c, w, h, cr, cc; int left[109]; int right[109]; int top[109]; int buttom[109]; int count = 1; while (scanf("%d", &n) && n != 0) { for (int i = 1; i <= n ; ++ i) { scanf("%d%d%d%d", &r, &c, &w, &h); left[i] = c; right[i] = c + w - 1; top[i] = r; buttom[i] = r + h - 1; } scanf("%d", &m); printf("Desktop %d:\n", count); for (int i = 0; i < m; ++ i) { scanf("%d%d", &cr, &cc); bool ch = 0; for (int j = n; j >= 1; -- j) { if (cc >= left[j] && cc<= right[j] && cr >= top[j] && cr <= buttom[j]) { printf("window %d\n", j); ch = 1; break; } } if (!ch) { printf("background\n"); } } ++ count; } }
?