hdu 3332 暴力枚举
2012-05-11 05:29
363 查看
[align=left]Problem Description[/align]
Emma is not very tidy with the desktop of her computer. She has the habit of opening windows on the screen and then not closing the application that created them. The result, of course, is a very cluttered desktop with some windows
just peeking out from behind others and some completely hidden. Given that Emma doesn’t log off for days, this is a formidable mess. Your job is to determine which window (if any) gets selected when Emma clicks on a certain position of the screen.
Emma’s screen has a resolution of 106 by 106. When each window opens its position is given by the upper-left-hand corner, its width, and its height. (Assume position (0,0) is the location of the pixel in the upper-left-hand corner of her
desktop. So, the lower-right-hand pixel has location (999999, 999999).)
[align=left]Input[/align]
Input for each test case is a sequence of desktop descriptions. Each description consists of a line containing a positive integer
n, the number of windows, followed by n lines, n ≤ 100, describing windows in the order in which Emma opened them, followed by a line containing a positive integer
m, the number of queries, followed by m lines, each describing a query. Each of the
n window description lines contains four integers r, c, w, and
h, where (r, c) is the row and column of the upper left pixel of the window, 0 ≤
r, c ≤ 999999, and w and h are the width and height of the window, in pixels, 1 ≤
w, h. All windows will lie entirely on the desktop (i.e., no cropping). Each of the
m query description lines contains two integers cr and cc, the row and column number of the location (which will be on the desktop). The last test case is followed by a line containing 0.
[align=left]Output[/align]
Using the format shown in the sample, for each test case, print the desktop number, beginning with 1, followed by
m lines, one per query. The i-th line should say either “window
k”, where k is the number of the window clicked on, or “background” if the query hit none of the windows. We assume that windows are numbered consecutively in the order in which Emma opened them, beginning with 1. Note that querying a window
does not bring that window to the foreground on the screen.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
Emma is not very tidy with the desktop of her computer. She has the habit of opening windows on the screen and then not closing the application that created them. The result, of course, is a very cluttered desktop with some windows
just peeking out from behind others and some completely hidden. Given that Emma doesn’t log off for days, this is a formidable mess. Your job is to determine which window (if any) gets selected when Emma clicks on a certain position of the screen.
Emma’s screen has a resolution of 106 by 106. When each window opens its position is given by the upper-left-hand corner, its width, and its height. (Assume position (0,0) is the location of the pixel in the upper-left-hand corner of her
desktop. So, the lower-right-hand pixel has location (999999, 999999).)
[align=left]Input[/align]
Input for each test case is a sequence of desktop descriptions. Each description consists of a line containing a positive integer
n, the number of windows, followed by n lines, n ≤ 100, describing windows in the order in which Emma opened them, followed by a line containing a positive integer
m, the number of queries, followed by m lines, each describing a query. Each of the
n window description lines contains four integers r, c, w, and
h, where (r, c) is the row and column of the upper left pixel of the window, 0 ≤
r, c ≤ 999999, and w and h are the width and height of the window, in pixels, 1 ≤
w, h. All windows will lie entirely on the desktop (i.e., no cropping). Each of the
m query description lines contains two integers cr and cc, the row and column number of the location (which will be on the desktop). The last test case is followed by a line containing 0.
[align=left]Output[/align]
Using the format shown in the sample, for each test case, print the desktop number, beginning with 1, followed by
m lines, one per query. The i-th line should say either “window
k”, where k is the number of the window clicked on, or “background” if the query hit none of the windows. We assume that windows are numbered consecutively in the order in which Emma opened them, beginning with 1. Note that querying a window
does not bring that window to the foreground on the screen.
[align=left]Sample Input[/align]
3 1 2 3 3 2 3 2 2 3 4 2 2 4 3 5 1 2 4 2 3 3 2 5 10 2 10 100 100 100 100 2 5 13 100 101 0
[align=left]Sample Output[/align]
Desktop 1: window 3 window 1 background window 2 Desktop 2: background window 2
/** 由数据揣测,矩形的左上边属于窗口,右下不属于 */ #include <stdio.h> #define N 101 struct node { int r,c,w,h; void input() { scanf("%d%d%d%d",&r,&c,&w,&h); } bool corner(int x,int y) { return x==r&&y==c || x==r&&y==c+w || x==r+h&&y==c ||x==r+h&&y==c+w; } }p ; int n,m; int solve(int x,int y) { int i = n; for(;i;--i) { if(x >= p[i].r && y >= p[i].c && x < p[i].r+p[i].h && y < p[i].c+p[i].w) { return i; } } return -1; } int main() { int cnt = 0,x,y; while(scanf("%d",&n) != EOF && n) { int i,j; for(i = 1;i <= n; ++i) p[i].input(); scanf("%d",&m); printf("Desktop %d:\n", ++cnt); while(m--) { scanf("%d%d",&x,&y); int k = solve(x,y); printf(k == -1? "background\n":"window %d\n",k); } } return 0; }
相关文章推荐
- hdu 1557暴力枚举
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- HDU 2489 Minimal Ratio Tree (暴力枚举+最小生成树)
- hdu 4932 Miaomiao's Geometry 暴力枚举
- HDU 2098 分拆素数和(筛法求素数+暴力枚举)
- hdu 5128 The E-pang Palace (计算几何+暴力枚举)
- 暴力枚举,dfs(三角形篱笆,HDU 4277)
- hdu 1077 Catching Fish 计算几何+暴力枚举
- HDU 4151 The Special Number【二分+暴力枚举】
- HDU 1015 Safecracker (暴力枚举)
- hdu 4968 Improving the GPA (水 暴力枚举)
- hdu 5247 找连续数【暴力枚举】
- hdu 5339 暴力枚举
- hdu 2328 暴力枚举+find()
- hdu 4995 Revenge of kNN(暴力枚举)
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- HDU 1172 猜数字(暴力枚举)
- hdu 1598(并查集(krustra)+暴力枚举)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)