B- B
Time limit:1000MSMemory limit:32768KB64bit Io format:% I64d & % i64u
Submit Status Practice HDU 3332
Description
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,999 999 ).)
Input
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
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
M Lines, each describing a query. Each of
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
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.
Output
Using the format shown in the sample, for each test case, print the desktop number, beginning with 1, followed
M Lines, one per query.
I -Th line shoshould 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.
Sample Input
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
Sample output
Desktop 1:
Window 3
Window 1
Background
Window 2
Desktop 2:
Background
Window 2
1 # Include <iostream> 2 Using Namespace STD; 3 Const Int Maxn = 101 ; 4 Int N; 5 Struct Rect { 6 Int X1, Y1, X2, Y2; 7 }; 8 Rect rec [maxn]; 9 Int Myfind ( Int A,Int B ){ 10 For ( Int I = N- 1 ; I> = 0 ; I -- ) 11 If (REC [I]. x1 <= A & rec [I]. x2> = A & rec [I]. y1 <= B & rec [I]. y2> = B) 12 Return I; 13 Return - 1 ; 14 } 15 16 Int Main (){ 17 // Freopen ("in.txt", "r", stdin ); 18 For ( Int M, cases = 1 ; CIN> N & N; cases ++){ 19 For ( Int I = 0 ; I <n; I ++ ){ 20 Int T1, T2; 21 Cin> rec [I]. x1> rec [I]. Y1> T1> T2; 22 REC [I]. X2 = rec [I]. X1 + T2- 1 ; 23 REC [I]. y2 = rec [I]. Y1 + T1- 1 ; 24 } 25 Cout < " Desktop " <Cases < " : \ N " ; 26 Cin> M; 27 Int A, B; 28 While (M -- ){ 29 Cin> A> B; 30 Int Ans = Myfind (A, B ); 31 If (ANS =- 1 ) 32 Cout <" Background \ n " ; 33 Else 34 Cout < " Window " <Ans + 1 < ' \ N ' ; 35 } 36 } 37 }
Pay attention to the matching of R and h, C and w when doing the question, but also minus 1 (as a grid ).
You can just simulate it by question.