CCF CSP 201403-2 window (100)

201403-2
questions Name: Window
Time limit: 1.0s
Memory Limit: 256.0MB

Problem description
  In a graphical operating system, there are N windows, are respectively a coordinate axis parallel to two sides of a rectangular area of each window. Points on the boundary of the window belong to the window. A difference between the level of the window, more than one window at a region overlapping, the top window will display the contents.
  When you click on a point on the screen when you click on the choice of the location in the topmost window, and the window will be moved to the topmost of all windows, while the rest of the hierarchical order of the same window. If you click on a location does not belong to any window, the system will ignore you click on this.
  Now we want you to write a program to simulate click on the window of the process.
Input format
  first line of input has two positive integers, i.e., N and M. (1 ≤ N ≤ 10,1 ≤ M ≤ 10)
  next row gives the position N of the N windows in order from the topmost to the lowermost order. Each row contains four non-negative integers x1, y1, x2, y2, represent a pair of coordinates of the vertices of the window are (x1, y1) and (x2, y2). Ensure that x1 <x2, y1 2.
  Next M lines contains two non-negative integers x, y, a graph of a mouse click.
  Title involved in all points and vertex x of the rectangle, y coordinates of not more than 2559 and 1439, respectively.
Output format
  output includes M rows, each row represents the results of a mouse click. If the mouse click to select a window, the output window number (in order of the input window is numbered from 1 to N); if not, outputs "IGNORED" (without quotation marks).
Sample input
. 3. 4
0 0. 4. 4
. 1. 5. 1. 5
2 2. 6. 6
. 1. 1
0 0
. 4. 4
0. 5
sample output
2
1
1
IGNORED
sample shows
  the position of the first click belongs to the first and second windows, but since the second window above, which is selected and placed in the top layer.
  Only the second click position of a window belonging to the first, so that the views of the selected window and to the front. Hierarchical relationship with the initial state of the current three windows of the contrary.
  Third click position while within the scope of the three windows, but now since the first window at the top level, it is selected.
  Finally, click the (0, 5) does not belong to any window.

Thinking:
ck window structure represents the number of flag added to the input window, the first layers are in Layer indicates (e.g., the top layer is 1); a coordinate input each time, according to the flag array ck ascending sequentially and ensure that each start start at the top, if the point does not exist in the window, sequentially traversing down layer.
When the coordinates are entered if the statement when the window of a point, if the window is not the top level, it is itself located in front of the window or go back one, and that window becomes the top; on the contrary do not change the order.

#include <iostream>
#include <algorithm>
using namespace std;

struct point{
    int x,y;
}po[11];

struct ck{
    struct point p1,p2;
    int flag,layer; //flag表示第几个窗口 layer表示从上往下第几层
}ck[11];

bool cmp(struct ck a ,struct ck b)
{
    return a.flag < b.flag; //从顶层开始查看 点是否包含于当前窗口
}

int main()
{
    int n,m,ans[11];
    
    cin >> n >> m;
    
    //n个窗口
    for(int i = 0;i < n;i++)
    {
        cin >> ck[i].p1.x >> ck[i].p1.y;
        cin >> ck[i].p2.x >> ck[i].p2.y;
        ck[i].layer = i+1; //第i个窗口
        ck[i].flag = n-i; //越先输入越底层  最后输入的为顶层 1
    }
    //m次点击
    for(int i = 0;i < m;i++)
    {
        int have = 0;
        sort(ck,ck+n,cmp); //按flag从小到大排序
        
        cin >> po[i].x >> po[i].y;
        for(int j = 0;j < n;j++)
        {
            if(po[i].x >= ck[j].p1.x && po[i].y>= ck[j].p1.y && po[i].x <= ck[j].p2.x && po[i].y <= ck[j].p2.y)
            {
                have = 1;
                //cout << endl << ck[j].layer;
                ans[i] = ck[j].layer;
                if(ck[j].flag != 1) //如果本身就是顶层则不用改变名次
                {
                    ck[j].flag = 1;
                    for(int k = 0;k < j;k++)
                    {
                       ck[k].flag++; //往后退一名
                    }
                }
                break;
            }
        }
        if(have == 0)
        {
            ans[i] = 0;//没找到
        }
    }
    
    for(int i = 0;i < m;i++)
    {
        if(ans[i] != 0)
        {
            cout << ans[i] << endl;
        }
        else{
            cout << "IGNORED" << endl;
        }
    }
    
    return 0;
}

Released six original articles · won praise 0 · Views 41

Guess you like

Origin blog.csdn.net/weixin_41809467/article/details/104801947