#PU995. USACO 2020 January Contest, Gold — Problem 3. Springboards
USACO 2020 January Contest, Gold — Problem 3. Springboards
USACO 2020 January Contest, Gold — Problem 3. Springboards
题目描述
Bessie is in a 2D grid where walking is permitted only in directions parallel to one of the coordinate axes. She starts at the point and wishes to reach (). To help her out, there are () springboards on the grid. Each springboard is at a fixed point and if Bessie uses it, she will land at a point . Bessie is a progress-oriented cow, so she only permits herself to walk up or right, never left nor down. Likewise, each springboard is configured to never go left nor down. What is the minimum distance Bessie needs to walk?
输入格式
The fist line contains two space-separated integers and . The next lines each contains four integers, , , , , where and All springboard and target locations are distinct.
输出格式
(见题面原文)
数据范围
Test cases 2-5 satisfy . Test cases 6-15 satisfy no additional constraints.
样例
样例 1
3 2
0 1 0 2
1 2 2 3
3
Bessie's best path is:
Bessie walks from (0,0) to (0,1) (1 unit).
Bessie springs to (0,2).
Bessie walks from (0,2) to (1,2) (1 unit).
Bessie springs to (2,3).
Bessie walks from (2,3) to (3,3) (1 unit).
The total walking length of Bessie's path is 3 units.
Problem credits: Pedro Paredes