Scott's world.

# Saving-James-Bond-Hard-Version

Word count: 1.2kReading time: 6 min
2019/08/20 Share

# Saving James Bond - Hard Version

This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape — he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head… Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).

Assume that the lake is a 100 by 100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him a shortest path to reach one of the banks. The length of a path is the number of jumps that James has to make.

### Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x,y) location of a crocodile. Note that no two crocodiles are staying at the same position.

### Output Specification:

For each test case, if James can escape, output in one line the minimum number of jumps he must make. Then starting from the next line, output the position (x,y) of each crocodile on the path, each pair in one line, from the island to the bank. If it is impossible for James to escape that way, simply give him 0 as the number of jumps. If there are many shortest paths, just output the one with the minimum first jump, which is guaranteed to be unique.

## 题目分析

• 这道题与上次我们做的简易版007其实没有多大的差别,只不过这道题中多加了一些计数和记录步数的操作

其中使用的是Dijkstra算法来计算最短路径.而其中Dijkstra算法对第一跳做处理。每一个第一跳Dijkstra，如果跳的步少，更新存储鳄鱼下标。如果相同则加入。。然后找到第一步跳的最少的。题目保证唯一。从第一步跳的最少的，再一次Dijkstra来保存步数

还有就是注意到其中上岸的跳跃也算一步距离