luogu#P6916. [ICPC2015 WF] Window Manager
[ICPC2015 WF] Window Manager
题目描述
The past few years have seen a revolution in user interface technology. For many years, keyboards and mice were the tools used to interact with computers. But with the introduction of smart phones and tablets, people are increasingly using their computers by tapping and moving their fingers on the screen. Naturally this has led to new paradigms in user interface design. One important principle is that objects on the display obey “physical” laws. In this problem, you will see an example of this.
You have been hired to build a simulator for the window manager to be used in the next generation of smart phones from Advanced Cellular Manufacturers (ACM). Each phone they produce will have a rectangular screen that fully displays zero or more rectangular windows. That is, no window exceeds the boundaries of the screen or overlaps any other window. The simulator must support the following commands.
OPEN — open a new window with top-left corner coordinates , width pixels and height pixels.
CLOSE — close an open window that includes the pixel at . This allows a user to tap anywhere on a window to close it.
RESIZE — set the dimensions of the window that includes the pixel at to width and height . The top-left corner of the window does not move.
MOVE — move the window that includes the pixel at . The movement is either pixels in the horizontal direction or pixels in the vertical direction. At most one of and will be non-zero.
The OPEN and RESIZE commands succeed only if the resulting window does not overlap any other windows and does not extend beyond the screen boundaries. The MOVE command will move the window by as many of the requested pixels as possible. For example, if is 30 but the window can move only 15 pixels to the right, then it will move 15 pixels.
Figure 1: MOVE example
ACM is particularly proud of the MOVE command. A window being moved might “bump into” another window. In this case, the first window will push the second window in the same direction as far as appropriate, exactly as if the windows were physical objects. This behavior can cascade – a moving window might encounter additional windows which are also pushed along as necessary. Figure 1 shows an example with three windows, where window A is moved to the right, pushing the other two along.
输入格式
The first line of input contains two positive integers and , the horizontal and vertical dimensions of the screen, measured in pixels. Each is at most (ACM is planning on building displays with very high resolution). The top-left pixel of the screen has coordinates . Each of the following lines contains a command as described above. One or more spaces separate the command name and the parameters from each other. The command parameters are integers that satisfy these conditions: , , , and . There will be at most 256 commands.
输出格式
The output must follow the format illustrated in the sample output below.
Simulate the commands in the order they appear in the input. If any errors are detected during a command’s simulation, display the command number, command name, and the first appropriate message from the following list, and ignore the results of simulating that command (except as noted).
no window at given position — for the CLOSE, RESIZE, and MOVE commands — if there is no window that includes the pixel at the specified position.
window does not fit — for the OPEN and RESIZE commands — if the resulting window would overlap another window or extend beyond the screen boundaries.
moved instead of — for the MOVE command — if the command asked to move a window pixels, but it could only move pixels before requiring a window to move beyond the screen boundaries. The values and are the absolute number of pixels requested and moved, respectively. The window is still moved in this case, but only for the smaller distance.
After all commands have been simulated and any error messages have been displayed, indicate the number of windows that are still open. Then for each open window, in the same order that they were opened, display the coordinates of the top-left corner , the width, and the height.
题目大意
过去几年,用户界面技术发生了一场革命。多年来,键盘和鼠标一直是与计算机交互的工具。但随着智能手机和平板电脑的推出,人们越来越多地通过在屏幕上敲击和移动手指来使用电脑。这自然导致了用户界面设计的新范式。一个重要的原则是显示器上的对象遵守“物理”定律。在这个问题中,您将看到一个例子。
您已被聘请为window manager构建一个模拟器,用于高级手机制造商(ACM)的下一代智能手机。他们生产的每款手机都有一个矩形屏幕,可以完全显示零个或多个矩形窗口。也就是说,没有窗口超出屏幕边界或与任何其他窗口重叠。模拟器必须支持以下命令。
OPEN x y w h——打开一个具有左上角坐标(x,y)、宽度w像素和高度h像素的新窗口
CLOSE x y——关闭一个打开的窗口,其中包括(x,y)处的像素。这允许用户点击窗口上的任意位置以关闭窗口。
RESIZE x y w h——将包含(x,y)处像素的窗口尺寸设置为宽度w和高度h。窗口的左上角不移动。
MOVE x y dx dy——移动包含(x,y)处像素的窗口。移动是水平方向上的dx像素或垂直方向上的dy像素。dx和dy中最多有一个为非零。
图1:移动示例
ACM对MOVE命令特别自豪。正在移动的窗口可能会“撞上”另一个窗口。在这种情况下,第一个窗口将以相同的方向尽可能远地推动第二个窗口,就像这些窗口是物理对象一样。此行为可能会层叠–移动的窗口可能会遇到其他窗口,这些窗口也会根据需要被推送。图1显示了一个有三个窗口的示例,其中窗口A向右移动,推动其他两个窗口。
输入格式
第一行输入包含两个正整数x_max和y_max,即屏幕的水平和垂直尺寸,以像素为单位。每个显示器的最大分辨率为10^9(ACM正计划建造具有极高分辨率的显示器)。屏幕左上角的像素具有坐标(0,0)。下面的每一行都包含一个如上所述的命令。命令名和参数之间用一个或多个空格分隔。命令参数是满足这些条件的整数:0≤x<x_max,0≤y<y_max,1≤w,h≤10^9,|d_x|、|d_y|≤10^9。最多有256条命令。
输出格式
输出必须遵循以下示例输出中所示的格式。
按照命令在输入中出现的顺序模拟命令。如果在命令模拟过程中检测到任何错误,请显示命令编号、命令名称和下表中的第一条适当消息,并忽略模拟该命令的结果(除非另有说明)。
如果在指定位置没有包含像素的窗口,则在给定位置没有窗口(用于关闭、调整大小和移动命令)。
如果生成的窗口与另一个窗口重叠或超出屏幕边界,则窗口不适用于“打开”和“调整大小”命令。
如果命令要求移动窗口d个像素,则移动d'而不是d-对于MOVE命令,但在要求窗口移动到屏幕边界之外之前,它只能移动d'个像素。值d和d’分别是请求和移动的像素的绝对数量。在这种情况下,窗口仍会移动,但仅移动较小的距离。
模拟所有命令并显示任何错误消息后,指示仍打开的窗口数。然后,对于每个打开的窗口,按照打开的顺序显示左上角(x,y)的坐标、宽度和高度。
输入输出样例
输入 #1
320 200
OPEN 50 50 10 10
OPEN 70 55 10 10
OPEN 90 50 10 10
RESIZE 55 55 40 40
RESIZE 55 55 15 15
MOVE 55 55 40 0
CLOSE 55 55
CLOSE 110 60
MOVE 95 55 0 -100
输出 #1
Command 4: RESIZE - window does not fit
Command 7: CLOSE - no window at given position
Command 9: MOVE - moved 50 instead of 100
2 window(s):
90 0 15 15
115 50 10 10
说明/提示
时间限制:1000毫秒,内存限制:1048576 kB。
该题出自:2015年国际大学生编程大赛(ACM-ICPC)世界总决赛
320 200
OPEN 50 50 10 10
OPEN 70 55 10 10
OPEN 90 50 10 10
RESIZE 55 55 40 40
RESIZE 55 55 15 15
MOVE 55 55 40 0
CLOSE 55 55
CLOSE 110 60
MOVE 95 55 0 -100
Command 4: RESIZE - window does not fit
Command 7: CLOSE - no window at given position
Command 9: MOVE - moved 50 instead of 100
2 window(s):
90 0 15 15
115 50 10 10
提示
Time limit: 1000 ms, Memory limit: 1048576 kB.
International Collegiate Programming Contest (ACM-ICPC) World Finals 2015