// Twindows,cc // 2009 ecna // problem H - Windows // // simple stack search #include using namespace std; const int MAX = 1001; struct win{ int ULrow, ULcol, LRrow, LRcol; }; win Stack[MAX]; int tos; void PUSH(win A){ tos++; Stack[tos] = A; } // for debugging void PrintStack(){ for(int i=0;i<=tos;i++) cout<< Stack[i].ULrow<<','<>n; //get # of windows while(n>0){ tos = -1; for(int i=0;i>X.ULrow>>X.ULcol>>R>>C; X.LRrow = X.ULrow + C - 1; X.LRcol = X.ULcol + R - 1; PUSH(X); } cout<<"Desktop "<>n; // get n querries for(int i=0;i>R>>C; Done = false; top = tos; while(top>-1 && !Done){ if(RStack[top].LRrow || CStack[top].LRcol) top--; else Done = true; // found window } if(Done) //Stack[top] is the window cout<<"window "<< top+1<>n; } return 0; }