Flappy Bird
문제
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.
예제
예제 1
0 0 10 0 1 5 -10 10
0 0 10 0
예제 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