CCF-CSP 201403-2 Window (Python)

Problem Description

  In a graphics operating system, there are N windows, and each window is a rectangular area with two sides parallel to the coordinate axis. The point on the boundary of the window also belongs to the window. There is a hierarchical difference between windows. In an area where more than one window overlaps, only the content of the window at the top level will be displayed.
  When you click 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, while the hierarchy of the remaining windows remains unchanged. If the location you click does not belong to any window, the system will ignore your click.
  Now we want you to write a program to simulate the process of clicking on the window.

Input format

  The first line of input has two positive integers, namely N and M. (1 ≤ N ≤ 10, 1 ≤ M ≤ 10) The
  next N rows give the positions of N windows in order from the bottom to the top. Each row contains four non-negative integers x1, y1, x2, y2, indicating that the coordinates of a pair of vertices of the window are (x1, y1) and (x2, y2) respectively. Ensure that x1 <x2, y1 2.
  Each of the next M lines contains two non-negative integers x, y, which represent the coordinates of a mouse click.
  The x and y coordinates of all the points and the vertices of the rectangle involved in the question do not exceed 2559 and 1439, respectively.

Output format

  The output includes M lines, each line represents the result of a mouse click. If this 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 first clicked position belongs to both the first and second windows, but since the second window is on top, it is selected and placed on the top.
  The position of the second click only belongs to the first window, so this click selects this window and puts it on top. The hierarchical relationship of the current three windows is exactly the opposite of the initial state.
  The position of the third click belongs to the range of the three windows at the same time, but because the first window is now at the top level, it is selected.
  The last clicked (0, 5) does not belong to any window.

solution

N, M = input().split()
N = int(N)
M = int(M)
# 存放N个窗口的坐标
w = []
# 鼠标点击坐标
m = []
for i in range(N):
    w.append([i + 1, list(map(int, input().split()))])
# 使顶层窗口排在第一位
w.reverse()
for i in range(M):
    a, b = input().split()
    a = int(a)
    b = int(b)
    m.append((a, b))
for i in m:
    flag = False
    a = i[0]
    b = i[1]
    for index, j in enumerate(w):
        x1 = j[1][0]
        y1 = j[1][1]
        x2 = j[1][2]
        y2 = j[1][3]
        if x1 <= a <= x2 and y1 <= b <= y2:
            flag = True
            print(j[0])
            # 点击到了窗口就把此窗口置于顶层,即放在w的第一位
            tmp = w.pop(index)
            w.insert(0, tmp)
            break
    if not flag:
        print("IGNORED")

Guess you like

Origin blog.csdn.net/qq_43503670/article/details/115035065