Cleaning Robot

시간 제한1초메모리 제한1024 MB

요약
축에 평행한 직사각형 도로들을 정해진 경로 규칙으로 청소하는 로봇의 위치를 다섯 시각에 대해 구한다.
난이도

보통10점 중 7점

유형
시뮬레이션, 구현, 기하
정답자
아직 제출이 없습니다

문제

The road network of a city consists of a set of axis-parallel rectangles. Each rectangle road may overlap with others as shown in the figure below. The city operates an autonomous cleaning robot that is responsible to clean the entire roads every day. During cleaning, each rectangle is classified into one of three types as follows.

  1. Uncleared (UC): A rectangle that the cleaning robot has never visited.
  2. Partially cleared (PC): A rectangle that has been cleaned partially.
  3. All cleared (AC): A rectangle that has been completely cleaned.

The cleaning robot works according to the following routing algorithm.

  • The robot moves in a clockwise direction while cleaning each rectangle.
  • If the robot encounters a road of a new UC rectangle during the cleaning of a rectangle, it will turn at the crossing point and move towards the UC rectangle.
  • When a rectangle is completely cleaned as the robot reaches a point (x,y)(x, y) and another PC rectangle is encountered at (x,y)(x, y), the robot resumes cleaning the PC rectangle at that same point (x,y)(x, y).
  • If the robot returns to the starting point, it will stay at that point afterwards.
  • It takes the robot one second to move a unit distance along edges, and takes two seconds in changing direction at a crossing point or corner.

Let us explain the routing algorithm with the following example. The example road network consists of four rectangles R_1,R_2,R_3,R_4\\{R\_1, R\_2, R\_3, R\_4\\} where the starting point is ss of R_1R\_1.

The orange lines in the following figure depict the trajectory of the cleaning robot starting from ss of R_1R\_1.

Given information about nn rectangles, we want to know the exact locations of the robot for the five query points t_it\_i (1≤i≤51 ≤ i ≤ 5) in time. Note that the starting point is designated to the upper left corner of the rectangle R_1R\_1.

입력

Your program is to read from standard input. The input starts 1≤i≤51 ≤ i ≤ 5 with a line containing one integer, nn (1≤n≤501 ≤ n ≤ 50), where nn is the number of rectangles R_iR\_i. The second line gives the five query points t_it\_i (1≤i≤51 ≤ i ≤5) in time where 1≤t_i≤100,0001 ≤ t\_i ≤ 100\\,000. The ii-th line of following nn lines gives four integers x_lx\_l, y_ly\_l, x_ux\_u, y_uy\_u for R_iR\_i where (x_l,y_l)(x\_l , y\_l) is the lower left corner and (x_u,y_u)(x\_u, y\_u) is the upper right corner where 1≤x_l<x_u≤1,0001 ≤ x\_l < x\_u ≤1\\,000, and 1≤y_l<y_u≤1,0001 ≤ y\_l < y\_u ≤ 1\\,000. Note that the intersection points between rectangles are all in the middle of edges, not at corner points, and there are no edge overlaps among rectangles, so the configurations below are not given in this problem. Also note that rectangles are not necessarily all connected into one component.

출력

Your program is to write to standard output. Print exactly five lines. The line should contain two integers x_ix\_i, y_iy\_i where (x_i,y_i)(x\_i, y\_i) is the location of the cleaning robot at time t_it\_i (1≤i≤51 ≤ i ≤ 5).

The following shows sample input and output for three test cases. Note that at time t=0t = 0, the robot is ready to start at the starting point.

예제3

  1. 예제 1

    입력
    4
    1234 10000 700 3000 5000
    100 500 300 800
    100 100 900 400
    150 30 190 550
    230 350 700 700
    
    예상 출력
    900 376
    100 800
    696 700
    190 452
    230 476
    
  2. 예제 2

    입력
    7
    9001 8002 7003 6004 5005
    200 100 300 800
    350 100 500 800
    600 100 700 800
    100 600 800 700
    100 400 800 500
    100 200 800 300
    900 200 1000 700
    
    예상 출력
    263 100
    154 600
    551 700
    500 142
    235 400
    
  3. 예제 3

    입력
    5
    1298 5574 3332 1794 7141
    400 150 650 700
    100 100 750 500
    200 400 850 600
    500 300 1000 650
    150 150 350 350
    
    예상 출력
    750 262
    500 540
    812 600
    418 100
    400 699