Statistics

Problem Statement for "Curvy"

Problem Statement

A road consists of a sequence of circular arcs and straight sections. We want to know the straight line distance between the two ends of the road, treating the road as a curvy line with negligible width.

The path of the road is specified by a sequence of sections. Each section has a length (when travelling along the road) and a radius of curvature (telling the radius of a circle that this section follows). A positive radius is a curve to the right, a negative radius indicates that the curve is to the left, and a radius of 0 is a special value indicating that this section is straight.

Each circular arc section of the road is on the circle that is tangential to the path of the road at both its ends. So, for example, if the road is heading northeast when a section with radius of curvature equal to -3 begins, the center of that section's circle is 3 units to the northwest of that point on the road.

Create a class Curvy that contains a method distance that is given int[]s length and radius and that returns the straight line distance between the two ends of the road. The i-th elements of length and radius indicate the information for the i-th section as we travel from start to end.

Definition

Class:
Curvy
Method:
distance
Parameters:
int[], int[]
Returns:
double
Method signature:
double distance(int[] length, int[] radius)
(be sure your method is public)

Notes

  • A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.

Constraints

  • length will contain between 1 and 50 elements, inclusive.
  • radius will contain the same number of elements as length.
  • Each element of length will be between 1 and 10,000, inclusive.
  • Each element of radius will be between -100 and 100, inclusive.

Examples

  1. {100}

    {0}

    Returns: 100.0

    This road is a single section which is straight and has a length of 100.

  2. {628}

    {-1}

    Returns: 0.3171858120571965

    This road is a single section which curves to the left with a radius of curvature of 1. It goes around in a circle on top of itself almost exactly 100 times, so its two ends are pretty close to each other.

  3. {628,50,20,10}

    {1,0,0,0}

    Returns: 79.68684435034164

    This road is composed of 4 sections. The first section behaves as in the previous example except it curves to the right. Then, in 3 separate straight sections, the road continues in a straight line for 50+20+10 = 80 units. 628 is a bit smaller than (2*PI) * 100. This means that after going 628 units along the circle, the road will be headed nearly toward the starting point. The final 3 sections continue on 50+20+10 = 80 units in that direction, so the final distance from the start to the end is a little less than 80.

  4. {1,1,1,1,1}

    {-9,-9,-9,-9,-9}

    Returns: 4.935947205793079

  5. {5}

    {-9}

    Returns: 4.935947205793079

  6. {560, 635, 6051}

    {32, -76, -94}

    Returns: 197.60490410408119

  7. {4, 5}

    {-4, 7}

    Returns: 8.707855202859301

  8. {6, 6}

    {-2, 2}

    Returns: 7.979959892832435

  9. {6502,1561,4076,5051,1824,2848,3969,728,9740,7300,7808,7306,1037,5083,9749,5069,6373,9999,9522,5350,1240,703,2744,8626,2427,1104,6462,6794,975,3360,3985,6824,916,219,4536,5795,1339,7510,3811,3686,5196,9385,9712,6368,3216,3050,7913,1476,4316,5492}

    {-60,67,0,0,0,-87,76,71,-21,-55,8,-21,-32,0,0,0,6,57,0,0,64,-52,-46,3,-82,-89,0,22,0,-81,26,-67,88,-44,2,0,75,38,98,-71,0,53,58,0,0,-64,-24,0,0,0}

    Returns: 47661.36049355737

  10. {357, 6163, 1578, 6035, 6706, 8080, 1310, 8523, 8064, 7253, 7084, 775, 2700, 1696, 7149, 2094, 1727, 781, 6079, 4054, 9176, 1976, 2500, 7644, 1244, 7548, 5191, 9360}

    {-54, -34, 53, 30, 74, -94, -57, 58, -58, 10, -30, 12, -72, -65, -45, -70, 45, -2, 40, -87, -79, 27, 50, -38, 93, 28, 24, 31}

    Returns: 491.38732304535534

  11. {906, 6364, 5613, 7857, 5065, 9825, 6863, 4827, 2578, 2337, 7690, 2624, 1907, 6544, 918, 4865, 6769, 5556, 4202, 2052}

    {20, -9, -14, 60, 30, 99, 27, -16, 99, -36, -100, 88, -11, 87, 32, -68, 54, -1, 76, -63}

    Returns: 489.02429357888343

  12. {9488, 518}

    {26, 15}

    Returns: 29.725670193201434

  13. {9201, 91, 5540, 6382, 6921, 7772, 160, 5239, 4032, 1557, 6162, 1583, 6294, 4423, 4775, 4219, 6500, 547, 3472}

    {-39, 50, 11, -81, -55, -1, -81, -37, -95, -57, -9, 21, 67, 98, 36, -95, -22, -9, -30}

    Returns: 367.3237003013401

  14. {1577, 5759, 6227, 6128, 2012}

    {-62, -76, 40, 95, 1}

    Returns: 127.21489665243121

  15. {1248, 4546, 5399, 1703, 8012, 6440, 8768, 4801, 5130, 8935, 9987, 3787, 3130, 9836, 9046, 309, 1429, 8964, 2808, 6885, 446, 9032, 6158, 4187, 5974, 1801, 5771, 9107, 4479, 7673, 7529, 5255, 1656, 4084, 3908, 8302, 5143}

    {13, 100, 34, -39, 94, 16, 29, -56, -78, -56, 83, 15, -57, -39, 49, -85, -40, 95, 45, -42, -11, -80, -57, 6, 100, -86, -54, -55, -61, 80, 18, -50, 73, -6, -50, -77, -88}

    Returns: 506.3113107804792

  16. {8453, 2160, 9600, 4248, 5027, 4353, 1847, 7031, 1131, 5129, 255, 5519, 2217, 4906, 1237, 8885, 2112, 8136, 6675}

    {52, 97, -36, -67, -17, 57, -29, 9, 66, 54, -27, -96, 10, 30, 13, 100, -98, 54, 48}

    Returns: 196.16844522372

  17. {3459, 5279, 871, 5152, 3256, 8055, 3968, 5531, 2747}

    {68, 76, -51, -42, 86, -53, 97, 35, -67}

    Returns: 434.6592787279561

  18. {9828, 9676, 2594, 6859, 6993, 3138}

    {58, 3, 75, -10, -74, 32}

    Returns: 153.17485609361538

  19. {3063, 8911, 4273, 7213, 6066, 222, 6701, 9473, 34, 9311}

    {91, 63, 26, 67, 34, 72, 15, 68, 43, 25}

    Returns: 80.32569363674898

  20. {1006, 2918, 7939, 5695, 4984, 1577, 447, 3344, 8953, 3266, 5615, 3318, 6862, 5737, 9885, 944, 132, 8070, 5052, 1102, 2620, 3869, 2173, 9112, 4282, 6180, 8414, 4744, 1456, 5253}

    {-26, 44, 6, 8, 86, -33, -83, 3, 99, -71, 99, -30, -16, -89, 22, 23, 64, -81, 64, 72, -71, 32, -36, -16, -75, 42, 20, -29, 99, -67}

    Returns: 691.7070982231266

  21. {324, 9171, 6362, 2018, 8360, 8277, 3971, 5798, 3865, 9101, 9586, 4492, 454, 7573, 5690, 1787, 8041, 8817, 7386, 7592, 6556, 9693, 6982, 3857, 3988, 8549, 9398, 2355, 8747, 1808, 2824, 41, 6045, 5706, 2657, 1506, 9433, 3277, 961, 1692, 295, 331, 2597, 9539}

    {81, -34, 30, 51, 44, 84, -11, -14, 82, 6, 100, -70, 44, -50, -78, 26, 59, -90, 19, -34, 6, -37, -85, 69, -65, -6, 25, -38, -51, 7, 51, 28, 46, 13, -17, -40, -90, 32, -47, 94, 39, 45, 83, -76}

    Returns: 1077.2567771095614

  22. {88, 6507, 9368, 438, 391, 8177, 3591}

    {37, 61, 45, -71, 90, 84, 17}

    Returns: 32.56904501632885

  23. {8086, 4, 4381, 6423, 2203, 9449, 897, 1121, 8356, 5168, 7649, 4228, 7486, 8226, 2290, 3809, 9728, 5034, 8605, 2008, 5851, 5254, 4739, 7471, 749, 7930, 7981, 5650, 2736, 2289, 9473, 2167, 7951, 5826, 8064, 7724, 2489, 6955, 413, 4160, 3070}

    {-10, 0, 76, 19, -48, -39, -33, -86, 45, 68, 31, -91, -31, 77, -3, 0, -55, 38, 86, 0, 9, -35, -4, -26, 43, -37, -27, 98, -57, -66, 81, -83, 0, 63, 65, 0, 4, 0, -29, -27, 3}

    Returns: 8313.101334721532

  24. {2913, 444, 8014, 879, 9637, 7017, 9869, 5096, 4179, 6217, 8972, 3798, 2713, 5202, 3197, 9420, 2051, 4251, 6786, 9332, 7921, 6147, 6000, 5940, 1379, 2494, 7522, 8508, 4676, 9625, 5831, 2364, 7776, 4991, 1817, 1939, 626, 6948, 843, 1186, 9855, 1502, 3294, 3278, 2489, 9956, 912, 1493, 5521}

    {44, 0, 0, 0, -19, 0, 70, -91, -37, 0, 51, 0, 0, 34, -50, 43, 0, 0, -1, 22, 0, -74, 0, 0, 0, 0, 0, -99, 40, -7, 0, 24, -13, 68, 0, 91, 0, 0, -70, 0, 90, -60, 0, 0, 58, 0, 0, 90, -35}

    Returns: 45317.648145647574

  25. {2534, 411, 4813, 8279, 877, 1423, 5636, 315, 5250, 9998, 7561, 9236, 225, 2374, 2751, 3841, 3252, 2060, 6859, 8841, 8612, 7799, 4119, 1540, 5469, 6743, 5587, 3254, 3082, 3075, 6151, 2649, 9903, 9647, 19, 8310, 9845, 9846, 8375, 511, 4687, 8266, 478, 892, 1660, 6933}

    {0, -28, 71, 19, 10, 62, 39, 66, 17, 0, 0, -51, 0, -26, -14, 30, -84, 4, 0, -55, -77, 26, -33, 18, 82, 0, 53, -36, -20, -64, 60, 22, 0, 3, -100, 0, 0, 0, 0, 45, -36, 10, -16, -57, 33, -66}

    Returns: 38642.86550676426

  26. {3336, 6237, 2675, 9583, 721, 4751}

    {0, -99, -40, 26, 98, 0}

    Returns: 7104.437377160725

  27. {2701, 8684, 6817, 6290, 5162, 9657, 2350, 2081, 8680, 2008, 6068, 9885, 3512, 698, 3700, 1021, 1369, 1446, 8352, 4770, 5771, 8227, 1055, 4748, 8555, 4099, 2718, 1129, 3228, 4844, 6480, 5835, 3415, 4819, 4870, 1461, 5161, 8039, 3274, 8594, 9563, 8, 8725, 2962, 4063, 2850, 5521, 3041, 1382}

    {0, 0, 64, 61, 0, 0, 0, 0, 73, 0, 49, 0, 0, -34, 0, 0, 24, -32, 0, 53, 0, 54, 0, 0, 37, -85, 0, 0, -30, -62, 91, -75, 0, -70, -92, -58, -31, 0, -76, -46, -68, 0, 0, 90, 82, 0, -89, -74, 82}

    Returns: 22229.872537864485

  28. {7555, 2023, 3560, 1575, 2316, 6926, 9577, 4653, 8937, 2083, 5613, 9537, 452, 8585, 521, 6516, 3823, 863, 3982, 9395, 2989, 4355, 2047, 3301, 65, 3858, 9517, 1389, 4945, 9019, 8320, 7216, 8422, 1089, 3140, 5136, 179, 655, 5311, 5367, 3440, 1477, 7835}

    {-52, 64, 0, 15, 0, 19, -51, -64, 91, 0, 65, -96, 64, 71, 92, -81, -50, 89, 42, -84, -93, -31, 0, 0, -58, 40, 0, 11, -81, 66, -39, -37, 92, -89, -54, 0, -14, -29, -20, -65, 0, -56, 43}

    Returns: 3896.7205731701015

  29. {1216, 4888, 2862, 8016, 4387, 9313, 8509, 7229, 5607, 6759, 6828, 2691, 899, 7873, 3165, 6792, 1176, 3541, 6002, 8802, 9167, 4218, 3340}

    {0, 0, 73, 0, 67, -38, 35, -47, 65, -28, 0, -42, 0, -56, 0, 0, 0, 0, 0, 0, -45, -84, 9}

    Returns: 13241.687607520964

  30. {2908, 6109, 318, 9368, 1287, 1289, 6574, 537, 2635, 6771, 2420, 657, 456, 6024, 5504, 2980, 575, 8738, 8488, 9046, 3909, 6986}

    {5, 45, -52, 6, -37, 0, -96, 89, 86, 96, 0, -83, 11, 55, 0, 13, 39, 8, -18, -50, -32, -25}

    Returns: 7584.062308850983

  31. {3061, 215, 1453, 7523, 8737, 3689, 8816}

    {-66, 79, -48, 0, 29, 0, 49}

    Returns: 10796.718673850799

  32. {6977, 6142, 4737, 455, 2136, 7449}

    {17, 0, 0, 61, 87, 90}

    Returns: 10958.368031661834

  33. {7594, 7003, 3563, 436, 8031, 2795, 2219, 3662, 8903, 7746, 2045, 4436, 3772, 7588, 5506, 6835, 9825, 4586, 5054, 6405, 9059, 4444, 2415, 9824, 9819, 4491, 8490, 2168, 5473, 9421, 5648, 641, 9098, 6758, 6000, 2102, 2450}

    {-60, 0, 0, -80, 0, 0, 0, 0, 79, 79, 0, -16, 0, -88, 66, 0, 30, -52, 0, 65, 36, 0, -16, 21, 41, 0, 94, 0, -90, 0, -24, 0, -23, 0, 0, -48, 14}

    Returns: 31679.967639878094

  34. {6445, 2517, 5093, 2232, 1740, 2733, 7630}

    {66, 7, 74, -95, 0, 45, 75}

    Returns: 1592.2765177942213

  35. {4501, 8353, 7286, 5646, 4174, 8211, 8890, 3997, 8449, 9750, 2219, 6863, 8720}

    {0, 5, 0, -3, 86, -80, 57, 0, 0, 3, -3, 0, -71}

    Returns: 7563.284891040431

  36. {6295}

    {-66}

    Returns: 70.73108263195583

  37. {2408, 4323, 1310, 8067, 6734, 2902, 5079, 6531, 3367, 5588, 1884, 5689, 2392, 4632, 6102, 3465, 4753, 5565, 5213, 7770, 2790}

    {0, 8, 90, -21, -33, 56, -76, 69, 31, 62, 94, -26, 74, 39, 5, -17, -89, 66, 36, 0, 0}

    Returns: 11852.760651689741

  38. {8426, 5308, 1678, 6122, 6950, 4131, 5248, 5780, 8051, 6092, 9319, 1951, 917, 7760, 1809, 9616, 274, 7707, 6942, 3098, 5306}

    {0, -54, -58, -54, -12, -40, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -88, 0, -63, 0, 0}

    Returns: 48941.539963286574

  39. {7704, 7724, 321, 147, 9631, 4026, 382, 3257, 3022, 2765, 4166, 2019, 9711, 3323, 5104, 5458, 6400, 5870, 7265, 3696, 245, 332, 4438, 1434, 4205, 3246, 5597, 2462}

    {29, -12, -67, 0, 1, 0, -97, -75, -63, 0, 54, 0, 0, 77, 0, 0, 0, 0, 0, -78, 0, -15, 0, -41, 0, 0, 0, 0}

    Returns: 40505.05844777266

  40. {234, 2257, 6346, 890, 1772, 266, 5290, 3391, 7244, 5700, 1254, 9474, 2155, 722, 9522, 6372, 5686, 8835, 9537, 9188, 7751, 9325, 9704, 104, 3848, 6486}

    {0, 84, 0, 29, 0, 0, 100, 18, -44, 0, 7, 0, 20, -27, 50, 89, -88, -24, 81, 0, 2, -79, -27, 0, 4, 15}

    Returns: 13888.449865353221

  41. {9269, 6934, 2252, 8033, 1024, 417, 6165, 826, 4423, 8020, 8137, 9843, 8037, 9227, 8602, 330, 3978, 5780, 8402, 5970, 1756}

    {0, -68, -94, 0, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, -82, 0, 0, 88, 92}

    Returns: 31946.181716903444

  42. {8286, 8521, 8677, 3464, 4725, 5014, 5982, 4118, 4941, 6039, 1752, 9627, 7708, 6688, 9517, 1559, 4620, 6669, 6938, 7056, 5316, 675, 3803, 1158, 1638, 7780, 8761, 7726, 7141, 9153, 7630, 4266, 8417, 5803, 5729, 2761, 3521, 5282, 3186, 8235, 6747, 3182, 9187, 8477, 2898}

    {97, -74, 65, 0, 0, 0, 91, -22, 95, 15, 20, -3, -21, -42, -91, 0, 77, -66, -85, 11, -57, 0, 89, -31, -86, 28, 45, 0, 100, 0, -21, 0, 70, -30, 15, -28, 5, 0, -31, 29, 83, 29, 88, 3, -45}

    Returns: 18769.910182671203


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: