ZJUT Practice 3.3 B Windows( hdu 3332 )

來源:互聯網
上載者:User
B - B

Time Limit:1000MS     Memory Limit:32768KB     64bit 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, 999999).) 

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 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. 

Output

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. 

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

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             else34                 cout<<"window "<<ans+1<<'\n';35         }36     }37 }

做題時要注意r和h,c和w互相匹配,還要減1(當做格子來看)。

按題目類比就可以了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.