All submissions for this problem are available.
Traffic Jam is becoming a major problem in the city of 'Faka' these days. Every day, you need to go to work from home through a one-way road that can be modeled as a series of straight line segments (aka piece-wise linear) of positive length. To be more explicit, suppose there are one way straight line paths named P, Q and R in your way. P starts at your home & ends at the starting point of Q. Q starts from the ending point of P & ends at starting point of R. Similarly, R starts at ending point of Q & ends at your destination. Two non-adjacent line segments in a road will never intersect with each other.
Now, you start from home for work and immediately get irritated by the heavy and annoying traffic jam. So you wish you could fly to your destination in order to avoid spending the whole day on road. Your new vehicle Aerocar comes as the solution to you. With this car, you can leave the road & start to fly from any point (The aerocar has a vertical take-off & landing similar to that of a helicopter) and land back to the road any time. Now, though you would have liked to fly all the way and thus avoiding the traffic, you need to resist the temptation due to the fact that flying requires more fuel than driving. You need 1 unit of fuel to travel every unit distance along the path while F units per unit distance while flying. Now you need to write a program that, given the description of the road, can calculate the minimum possible fuel amount needed to complete your journey.
Each test case starts with a couple of integers "cmmi-10x-x-109">N(1 ≤ "cmmi-10x-x-109">N ≤ 25) & F(2 ≤ F ≤ 5). N is the number of line segments in the road. F is the amount of fuel required for every unit distance traveled while flying. Next (N + 1) lines each has two integers, "cmmi-10x-x-109">x(−1000 ≤ x ≤ 1000) & "cmmi-10x-x-109">y(−1000 ≤ y ≤ 1000).
Assuming the road is placed on a planar 2d grid, the integers in the i "cmsy-10x-x-109">′th line denotes the x and y co-ordinates of the starting point of the i "cmsy-10x-x-109">′th line segment while the the end point co-ordinates by the i "cmsy-10x-x-109">′th line segment are given at the ( "cmmi-10x-x-109">i + 1)′th line. The last test case will be followed by a case with N = F = 0 indicating the end of input. This case should not be processed.
For each test case except the last one, print one line of the form “Case X : "cmmi-10x-x-109">Y ”, where X is the serial number of output & Y is the minimal possible units of fuel required. Print 3 digits after decimal point for "cmmi-10x-x-109">Y . The output will be tested by a special judge program and outputs with precision error smaller than 10 "cmsy-8">−3 shall be considered as correct.
Sample input and output
Case "cmtt-10x-x-109">1: 10.000
Case "cmtt-10x-x-109">2: 5.464
Case "cmtt-10x-x-109">3: 22.283
|Time Limit:||1.06383 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, GO, NODEJS|
Fetching successful submissions
If you are still having problems, see a sample solution here.