Flappy Bird
시간 제한1.75초메모리 제한1024 MB
s에서 t까지 x가 증가하는 순서로 각 수직 구간을 지나며, 정수 좌표를 가진 최단 꺾은선의 꼭짓점을 출력합니다.
문제
Help the bird Faby to navigate through a sequence of 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 axis. The bird starts out at and his goal is to reach . Find the shortest line from to , passing through all intervals in between in increasing order of their 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 can optionally be included in the output too.
입력
The input consists of:
- One line with four integers and (), the start and end points.
- One line with an integer , the number of intervals.
- lines, the th of which contains three integer and (, ), the intervals.
It can be assumed that .
출력
Output a sequence of ) points , one per line, such that:
-
All points have integer coordinates.
-
and .
-
Let be the path obtained by connecting for all . Then:
- passes through all intervals in increasing order of their coordinates.
- The length of is minimal.
If there are multiple valid solutions, you may output any one of them.