Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help solve this in Python! Suppose you are flying a drone that can fly exactly 100 km before needing a battery recharge. Recharging is

Please help solve this in Python!

Suppose you are flying a drone that can fly exactly 100 km before needing a battery recharge. Recharging is only possible at towns for which you are given locations. Your aim is to find the length of the shortest possible path to get the drone from an origin town to a destination town given the range restriction.

Assume that the landscape is a n n two dimensional square (units are km) with coordinates for towns described by (x, y) where 0 <= x, y <= n. Use Euclidean distance to calculate the distance between towns.

Input format:

You are given multiple lines of input. Each line has 2k + 1 comma separated numbers where k 2. The first number in each line is the size of the landscape, n. The following 2k numbers locations of k towns so that that the ith town is located at (2i, 2i + 1). In each line the first town listed is the origin, the final town listed in the destination.

For example:

100,0,0,0,100,100,100

1000,20.892,986,602,138.97,206.2,10.44

200,25,25,10,1,50,25,140,30

Output format:

For each line of input, output a single number which is the length of the shortest path from the origin town to the destination town. Use str.format to give this value to 2 decimal places. Precisely, format x using '{:.2f}'.format(x). Do not use any other rounding throughout your algorithm. If the destination town is unreachable from the origin, output -1.

For the example input aboves, output would be:

200.00

-1

115.14

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions