【CCF CSP】 201403-2 window (100 points)

Question number: 201403-2
Question name: window
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:
Problem Description
  In a graphics operating system, there are N windows, each of which is a rectangular area with two sides parallel to the coordinate axis. Points on the boundaries of a window also belong to that window. There are hierarchical differences between windows. In an area where more than one window overlaps, only the contents of the top-level window will be displayed.
  When you click on a point on the screen, you select the topmost window at the clicked position, and this window will be moved to the topmost level of all windows, and the hierarchical order of the remaining windows will remain unchanged. If you click on a location that does not belong to any window, the system ignores your click.
  Now we want you to write a program that simulates the process of clicking on a window.
input format
  The first line of input has two positive integers, N and M. (1 ≤ N ≤ 10, 1 ≤ M ≤ 10)
  The next N lines give the positions of N windows in order from the bottom to the top. Each line contains four non-negative integers x 1 , y 1 , x 2 , y 2 , representing a pair of vertex coordinates of the window, respectively (x 1 , y 1 ) and (x 2 , y 2 ). It is guaranteed that x 1 < x 2 , y 1 2.
  Each of the next M lines contains two non-negative integers x, y, which represent the coordinates of a mouse click.
  The x, y coordinates of all the points and vertices of the rectangle mentioned in the question should not exceed 2559 and 1439, respectively.
output format
  The output consists of M lines, each line representing the result of a mouse click. If the mouse click selects a window, output the number of this window (windows are numbered from 1 to N according to the order in the input); if not, output "IGNORED" (without double quotation marks).
sample input
3 4
0 0 4 4
1 1 5 5
2 2 6 6
1 1
0 0
4 4
0 5
Sample output
2
1
1
IGNORED
Sample description
  The location of the first click belongs to both windows 1 and 2, but since window 2 is on top, it is selected and brought to the front.
  The position of the second click belongs only to the 1st window, so the click selects this window and brings it to the front. The hierarchical relationship of the three windows is now the opposite of the initial state.
  The location of the third click falls within the bounds of all three windows at the same time, but since window 1 is now on top, it is selected.
  The last clicked (0, 5) does not belong to any window.

code

C++

#include <iostream>
#include <vector>
#include <algorithm>
#define MAX_LENGTH 2560
#define MAX_M 11 
using namespace std;

//区域类 
class Area
{
    public:
        int id;
        int star_x,star_y;
        int end_x,end_y;

};

//点击事件 
class Click
{
    public:
        int click_x,click_y;
};

//比较规则 
bool compare(Area a,Area b)
{
    if(a.id>b.id)
        return true;
    else 
        return false;
}

int main(int argc, char** argv) {
    int n,m;
    Click click[MAX_M];
    Area area,area_temp;
    vector<Area> vec_area;
    cin>>n>>m;
    //输入区域 
    for(int i=1;i<=n;i++)
    {
        area.id=i;
        cin>>area.star_x>>area.star_y>>area.end_x>>area.end_y;
        vec_area.push_back(area);
    }

    //输入点击事件 
    for(int i=1;i<=m;i++)
    {
        cin>>click[i].click_x>>click[i].click_y;
    }

    //按层级排序 
    sort(vec_area.begin(),vec_area.end(),compare);


    //处理点击事件 
    for(int i=1;i<=m;i++)
    {
        for(vector<Area>::iterator it=vec_area.begin();it!=vec_area.end();it++)
        {
            //在区域范围内 
            if(click[i].click_x>=it->star_x&&click[i].click_x<=it->end_x&&click[i].click_y>=it->star_y&&click[i].click_y<=it->end_y)
            {
                //拷贝区域 
                area_temp=*it;
                //输出区域编号 
                cout<<it->id<<endl; 
                //从列表中移除该区域 
                vec_area.erase(it);
                break;
            }
            //如果没有找到对应的区域 
            if((it+1)==vec_area.end()) 
                cout<<"IGNORED"<<endl;
        }
        //讲移除的区域置顶 
        vec_area.insert(vec_area.begin(),area_temp);
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325919361&siteId=291194637