아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Flappy Bird

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

요약
s에서 t까지 x가 증가하는 순서로 각 수직 구간을 지나며, 정수 좌표를 가진 최단 꺾은선의 꼭짓점을 출력합니다.
난이도

보통10점 중 7점

유형
기하, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Help the bird Faby to navigate through a sequence of nn pairs of pipes, by finding the shortest line he can fly on to reach his destination. For simplicity, we represent Faby as a single point in the plane and assume every pipe has width zero. This way, the gap between every pair of pipes can be represented as an interval on the yy axis. The bird starts out at s=(x_s,y_s)s = (x\_s, y\_s) and his goal is to reach t=(x_t,y_t)t = (x\_t, y\_t). Find the shortest line from ss to tt, passing through all intervals in between in increasing order of their xx coordinates.

Figure F.1: Visualisation of the second sample input. The red lines represent the intervals and the black line the shortest possible path. Faby and the black dots are the points in the output. Note that (2,1)(2, 1) can optionally be included in the output too.

입력

The input consists of:

  • One line with four integers x_s,y_s,x_tx\_s, y\_s, x\_t and y_ty\_t (−109≤x_s,y_s,x_t,y_t≤109-10^9 \le x\_s, y\_s, x\_t, y\_t \le 10^9), the start and end points.
  • One line with an integer n (0≤n≤106)n\ (0 \le n \le 10^6), the number of intervals.
  • nn lines, the iith of which contains three integer x_i,y_i,1x\_i, y\_{i,1} and y_i,2y\_{i,2} (−109≤x_i,y_i,1,y_i,2≤109-10^9 \le x\_i, y\_{i, 1}, y\_{i, 2} \le 10^9, y_i,1<y_i,2y\_{i, 1} < y\_{i, 2}), the intervals.

It can be assumed that x_s<x_1<⋯<x_n<x_tx\_s < x\_1 < \dots < x\_n < x\_t.

출력

Output a sequence of kk (2≤k≤n+2(2 \le k \le n+2) points p_1,…,p_kp\_1, \dots, p\_k, one per line, such that:

  • All points have integer coordinates.

  • p_1=sp\_1 = s and p_k=tp\_k = t.

  • Let PP be the path obtained by connecting p_ip_i+1‾\overline{p\_i p\_{i+1}} for all 1≤i<k1 \le i < k. Then:

    • PP passes through all intervals in increasing order of their xx coordinates.
    • The length of PP is minimal.

If there are multiple valid solutions, you may output any one of them.

예제2

  1. 예제 1

    입력
    0 0 10 0
    1
    5 -10 10
    
    예상 출력
    0 0
    10 0
    
  2. 예제 2

    입력
    0 0 10 0
    4
    2 1 3
    4 2 3
    7 0 2
    9 -2 -1
    
    예상 출력
    0 0
    4 2
    9 -1
    10 0