Amsterdam Distance
Time limit2sMemory limit512 MB
In a half-disc street grid with M radial streets and N circular canals of radius R*y/N, find the shortest path length between two corners using only those streets and canals.
- Level
Medium5 of 10
- Topics
- Geometry, Graph, Shortest path
- Solved
- No attempts yet
Problem
Your friend from Manhattan is visiting you in Amsterdam. She can only stay for a short while, so she wants to see as many tourist attractions as possible in as little time as possible. To plan that, she needs to know how long it takes to walk from one landmark to another. In her hometown that is easy: Manhattan is a rectangular grid of city blocks, so walking from point to point covers a distance of
Amsterdam is not well approximated by a rectangular grid. With its canals, Amsterdam looks much more like a half disc, with streets radiating at regular angles from the center and with canals running the arc of a circle at equally spaced intervals. A street corner is the intersection of a circular canal and a street which radiates from the city center.

Figure 1: the city model with , and , and the shortest walk from corner to corner .
Depending on how accurately you want to model the street plan of Amsterdam, you can split the city into more or fewer half rings and into more or fewer segments. To avoid conversion problems, the radius of the half circle is part of the input, so your program works with any unit. Write a program which computes the distance between two street corners in Amsterdam for a particular approximation.
The model is split into segments (pie slices), so streets radiate from the center and the angle between two neighbouring streets is . It is split into half rings, so canal has radius . Corner is the intersection of street and canal , and street 0 and street are the two ends of the straight diameter. Canal 0 has radius 0, so every corner of the form is the same point at the city center. You walk only along the streets and the canals.
Input
The input consists of:
-
One line with two integers , and a floating point number .
- is the number of segments (or pie slices) the model of the city is split into.
- is the number of half rings the model of the city is split into.
- is the radius of the city.
-
One line with four integers , , , , with and , the coordinates of two corners and in the model of Amsterdam.
Output
Output a single line with the least distance needed to travel from corner to corner following only the streets and the canals. Round the value to nine digits after the decimal point and print all nine of them. For example, print 2.000000000 for a distance of .