2068. Mud Puddles

单点时限: 2.0 sec

内存限制: 256 MB

Farmer John is leaving his house promptly at 6 AM for his daily milking of Bessie. However, the previous evening saw a heavy rain,and the fields are quite muddy. FJ starts at the point (0, 0) in the coordinate plane and heads toward Bessie who is located at (X,

Y) (-500 <= X <= 500; -500 <= Y <= 500). He can see all N (1 <= N <= 10,000) puddles of mud, located at points (A_i, B_i) (-500 <= A_i <= 500; -500 <= B_i <= 500) on the field. Each puddle occupies only the point it is on.

Having just bought new boots, Farmer John absolutely does not want to dirty them by stepping in a puddle, but he also wants to get to Bessie as quickly as possible. He’s already late because he had to count all the puddles. If Farmer John can only travel parallel to

the axes and turn at points with integer coordinates, what is the shortest distance he must travel to reach Bessie and keep his boots clean? There will always be a path without mud that Farmer John can take to reach Bessie.

输入格式

  • Line 1: Three space-separate integers: X, Y, and N.

  • Lines 2..N+1: Line i+1 contains two space-separated integers: A_i and B_i

输出格式

  • Line 1: The minimum distance that Farmer John has to travel to reach Bessie without stepping in mud.

样例

Input
1 2 7
0 2
-1 3
3 1
1 1
4 2
-1 1
2 2
NPUT DETAILS:
Bessie is at (1, 2). Farmer John sees 7 mud puddles, located at (0, 2); (-1, 3); (3, 1); (1, 1); (4, 2); (-1, 1) and (2, 2). Pictorially:
4 . . . . . . . .
3 . M . . . . . .
Y 2 . . M B M . M .
1 . M . M . M . .
0 . . * . . . . .
-1 . . . . . . . .
-2-1 0 1 2 3 4 5
X
Output
11
OUTPUT DETAILS:
The best path for Farmer John is (0, 0); (-1, 0); (-2, 0); (-2, 1);(-2, 2); (-2, 3); (-2, 4); (-1, 4); (0, 4); (0, 3); (1, 3); and (1, 2), finally reaching Bessie.
4 ******* . . . .
3 * M . * . . . .
Y 2 * . M B M . M .
1 * M . M . M . .
0 ***** . . . . .
-1 . . . . . . . .
-2-1 0 1 2 3 4 5
X

19 人解决,28 人已尝试。

22 份提交通过,共有 59 份提交。

5.1 EMB 奖励。

创建: 16 年,10 月前.

修改: 7 年,2 月前.

最后提交: 1 年,4 月前.

来源: USACO

题目标签