编程介的小学生 2017-08-24 02:45 采纳率: 20.5%
浏览 759
已采纳

Hiking

You have gone on a hiking trip, but now you are getting tired and would like to return home. As a precaution, you always take your mobile phone with you, so you can call for help in case of an emergency. However, it only works as long as you stay in range of (one of) the phone towers in the area. Fortunately, you know precisely where you are and where you are going, and you brought a map of the area showing the locations of the mobile phone towers. You want to take the shortest route home, while staying in range of at least one of those towers.

Input

On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with two integers d (1 <= d <= 1 000) and t (1 <= t <= 100): the maximum distance to the nearest tower and the number of towers on the map, respectively.

One line containing the starting location.

One line containing the goal location.

t lines each containing the location of a tower.

All locations consist of two space-separated integer coordinates x and y (1 <= x, y <= 1 000).

All locations in the input for a single test case will be distinct. The starting locating will not be more than d units away from the nearest tower.

Output

For each test case:

One line containing the distance to the goal location, or -1 if the goal location is unreachable.

Your answer should have either an absolute or a relative error of at most 10-6.

Notes:

It's OK to be exactly d units away from the nearest tower.

The size of the towers is negligible; if you move straight through a tower location, the tower won��t block your path.

Sample Input

1
2 3
1 1
8 2
2 2
4 4
7 3
Sample Output

7.23224071072994

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-08-26 15:50
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题