Statistics

Problem Statement for "JohnnysCannon"

Problem Statement

Johnny has recently constructed a cannon, and he wants to a hit a ground target that is distance units away. The cannon shoots bullets at velocity units per second. When a bullet is in the air, its flight follows the standard laws of physics. This means that if he shoots a bullet at angle alpha from the ground, it will travel a distance of

     ( 2 * velocity^2 * sin(alpha) * cos(alpha) ) / g ,

where g is the acceleration of gravity on Earth. In this problem, we will use 10 as the value of g.


The cannon can only be set at the angles given in the int[] angles (all angles are given in degrees). Johnny must pick the angle that will land the bullet as close as possible to the target. Return this closest possible distance between the landing point and the target as a double.

Definition

Class:
JohnnysCannon
Method:
getDistance
Parameters:
int, int, int[]
Returns:
double
Method signature:
double getDistance(int velocity, int distance, int[] angles)
(be sure your method is public)

Notes

  • The returned value must be accurate to within a relative or absolute value of 1e-9.

Constraints

  • velocity will be between 1 and 1000, inclusive.
  • distance will be between 0 and 100000, inclusive.
  • angles will contain between 1 and 50 elements, inclusive.
  • Each element of angles will be between 0 and 90, inclusive.

Examples

  1. 5

    40

    { 0, 45, 90 }

    Returns: 37.5

    Here we can choose 0, 45 or 90 degrees. The first and the last options are not very clever as we will shoot ourselves rather than hitting any target. So, the best possibility is 45 degrees.

  2. 10

    5

    { 23, 76, 33, 12, 45 }

    Returns: 0.30528437214108894

    Here are the distances the bullet will travel using the given angles:      23 degrees: 7.193...      76 degrees: 4.694...      33 degrees: 9.135...      12 degrees: 4.067...      45 degrees: 10.0 We will be closest to hitting the target if we choose 76 degrees.

  3. 100

    15

    { 4, 55, 22, 13, 7, 88, 90 }

    Returns: 14.999999999999877

  4. 120

    20367

    { 4, 55, 22, 13, 7, 88, 90 }

    Returns: 19013.842626068294

  5. 10

    5

    {90,89,1,2}

    Returns: 4.302435262558747

  6. 473

    45791

    {71,74,38,47,70,79,51,38,71,62,78,2,20,40,65,43,56,31,73,47,8,36,84,35,10,89,81,37,13,22,20,45,57,20,1,88,60,52,35,40,23,75,41,4,76,68,46,41}

    Returns: 23418.1

  7. 30

    2610

    {67,26,4,64,87,55,54,33,67,38,15,74,4,86,74,2,55,87,88,56,71,34,59,74,20,36,30,22,5,20,33,71,7,36,6,4,52,60,88,81,7,64,64,62,59,9,25,75,6,23}

    Returns: 2522.6733846351603

  8. 991

    52480

    {9,60,75,6,51,59,62,32,1,4,38,36,10,3,88,69,53,78,37,26,13,60,47,21,85,31,78,17,71,64,34,41,85,71,46,7,39,69,38,39,73}

    Returns: 2437.2725833454533

  9. 435

    94356

    {40,85,22,2,34,20,79,46,79,35,29,73,66,16,89,8,41,33,11,35,13,18,41,13,87,40,13,69,25,48,60,26,5,43,27,38,62,67,46,50,12,74}

    Returns: 75445.02707573117

  10. 143

    33614

    {31,8,2,25,18,88,89,88,1,11,84,40,23,24,26,33,45,51,37,87,39,36,58,16,81,17,79,26,49,27,77,42,34,78,28,14,75,27,11,75,89}

    Returns: 31569.1

  11. 846

    62185

    {79,50,16,33,63,14,29,11,49,48,78,40,64,66,65,75,2,51,26,88,90,53,63,37,41,73,73,40,38,59,23,78,71,90,72,43,13,10,15,61,57,3,62,82,68,89,66,32}

    Returns: 1008.971937061986

  12. 811

    15087

    {11,16,53,47,18,87,81,57,86,50,41,73,30,40,54,72,14,25,86,37,43,50,60,34,28,58,62,21,69,24,11,41,1,25,49,19,21,39,37,16}

    Returns: 5237.69665572849

  13. 258

    6812

    {27,79,13,60,55,37,18,53,41,67,22,36,56,80,7,76,20,83,48,60,45,72,18,25,2,18,62,69,16,11,28,4,51,40,64,15,38,81,67,78,19,89,76,75}

    Returns: 155.60000000000036

  14. 800

    78428

    {59,36,70,80,43,13,7,67,67,76,90,45,1,10,73,5,61,74,30,37,22,72,66,61,90,26,46,36,65,90,58,85,87,89,74,39,63,42,68,39}

    Returns: 14428.0

  15. 939

    19384

    {80,77,80,46,9,25,37,45,8,18,72,69,69,7,76,67,33,37,86,79,34,46,24,34,18,27,11,19,16,78,64,5,26,15,12,34,39,48,40,47,27,22,77,57,80,62}

    Returns: 1946.7615710034624

  16. 213

    61466

    {80,11,4,35,35,89,53,61,10,71,76,49,6,42,74,72,53,17,72,62,18,80,88,1,66,55,81,90,49,13,60,1,75,25,35,71,75,87,42,84,29,79,4,86,83,77,67,45,55}

    Returns: 56929.1

  17. 291

    72744

    {90,66,73,28,82,25,79,3,89,10,3,74,86,37,54,70,86,57,26,76,8,29,72,90,16,10,6,32,20,22,14,72,50,49,9,41,73,87,43,72,58,45,17,53,82,32,32,39,51,57}

    Returns: 64275.9

  18. 744

    1086

    {57,19,63,67,24,4,48,8,70,29,57,80,89,7,62,47,12,5,14,56,21,28,9,53,60,47,13,78,33,32,35,89,50,59,27,35,63,37,42,4,27,60,83}

    Returns: 845.8127806715427

  19. 828

    75033

    {34,40,21,10,5,41,37,66,3,58,74,67,46,16,8,80,67,19,49,55,54,73,1,57,76,80,79,30,67,17,45,62,56,65,71,22,68,70,87,32,37,33,9,82,48,68,72,76,87,82}

    Returns: 6474.600000000006

  20. 371

    96012

    {3,30,11,82,18,2,20,86,8,82,13,35,62,87,12,3,83,43,40,77,13,83,35,43,26,72,1,17,22,64,42,77,3,14,30,73,15,50,68,23,41,81,57,64,39,30,67,31,34}

    Returns: 82281.42865581876

  21. 748

    34055

    {60,14,51,86,85,51,12,69,24,16,17,78,29,46,60,6,57,90,28,7,42,46,33,80,37,61,72,70,38,51,40,7,26,90,54,73,12,28,13,87,43,29}

    Returns: 1168.180020135209

  22. 205

    34514

    {6,76,3,57,65,61,8,72,3,49,18,25,31,50,62,43,89,31,69,51,84,51,62,73,63,59,25,53,5,58,88,62,5,52,29,32,23,36,13,77,85,83,64,77}

    Returns: 30321.737078783088

  23. 794

    71828

    {54,27,7,14,73,19,38,55,43,58,42,5,62,9,55,33,13,68,61,44,52,59,19,1,15,63,64,1,66,60,29,29,87,88,5,31,68,42,85,21,9,36,77,32,6,3,26,19,71,87}

    Returns: 8822.804457738937

  24. 744

    81094

    {4,84,31,66,57,83,3,27,21,32,23,70,88,53,10,39,9,82,9,7,68,40,12,33,65,82,65,23,16,58,39,71,52,31,47,18,23,49,44,6,42}

    Returns: 25774.11991751578

  25. 308

    96670

    {42,46,39,51,37,47,57,67,86,68,9,23,60,73,45,37,40,46,17,1,76,25,19,9,36,24,14,77,52,50,78,3,6,26,15,4,35,33,70,30,11,78}

    Returns: 87183.6

  26. 302

    54130

    {62,51,59,38,85,86,85,75,74,87,16,60,88,36,17,8,73,37,41,41,56,5,65,81,72,79,29,33,74,50,5,45,62,26,82,56,21,39,2,56,35,18,26,32,15,4,2,49,40,42}

    Returns: 45009.6

  27. 189

    87726

    {46,25,48,79,13,76,22,86,87,78,40,58,65,84,75,86,84,76,13,80,55,38,22,32,3,23,80,43,26,41,9,33,65,56,21,40,3,4,35,89,44,37,18,18,82,2,65,75,40,78}

    Returns: 84156.0760268051

  28. 884

    51624

    {77,47,49,80,31,1,84,56,41,2,88,67,58,71,16,60,74,13,21,27,11,38,7,54,2,71,38,3,58,63,20,7,20,31,86,12,31,79,68,33,80,27,9,9,7,77,69,81,51,51}

    Returns: 665.6127122767939

  29. 529

    93600

    {50,75,76,51,56,75,15,75,47,35,81,66,65,38,78,57,78,17,89,30,43,59,38,12,45,68,2,57,28,32,79,78,17,26,90,34,10,15,70,57,11,23,84,37,60,33,3,10,11,1}

    Returns: 65615.9

  30. 319

    53261

    {21,76,27,28,16,80,84,43,21,35,82,37,60,82,32,32,58,12,88,30,34,43,66,55,76,68,26,86,30,64,63,50,50,89,77,65,78,33,69,9,29,23,7,88,66,39,81,33,12,78}

    Returns: 43109.688468151006

  31. 522

    68864

    {83,89,23,68,28,49,25,57,22,88,68,33,48,17,59,36,49,90,44,77,22,12,36,87,12,79,81,23,66,14,29,20,12,14,87,1,62,74,57,83,33,86,78,42,12,46,77,22,45,82}

    Returns: 41615.6

  32. 880

    94735

    {4,58,24,15,46,66,90,73,79,80,3,52,3,51,52,64,86,70,19,80,66,6,32,39,51,18,23,6,10,82,33,65,11,19,41,56,84,40,1,35,30,3,48,84,53,62,58,49,41,76}

    Returns: 17342.174355641226

  33. 910

    78495

    {81,31,69,3,49,1,60,20,44,3,46,55,73,86,72,28,88,72,62,79,74,72,72,89,43,1,9,83,76,8,23,28,39,1,31,49,1,90,68,44,54,75,60,36,70,42,26,29,23,49}

    Returns: 261.99011440166214

  34. 837

    51297

    {30,51,57,72,51,65,27,37,34,49,64,72,11,56,30,11,56,59,16,19,43,38,17,75,79,42,13,63,52,82,31,82,42,49,25,2,23,51,38,57,61,64,90,71,29,82,43,46,50,59}

    Returns: 902.2835416551607

  35. 577

    62570

    {58,43,39,46,46,51,70,59,42,11,50,83,59,75,85,44,35,84,62,58,19,61,38,48,52,81,55,64,11,81,28,68,85,66,23,2,78,2,61,82,64,20,36,85,56,82,38,53,76,9}

    Returns: 29297.381135135947

  36. 480

    58424

    {31,57,13,45,47,68,18,19,58,45,86,15,72,70,16,59,34,76,50,7,6,48,53,23,39,90,75,24,60,4,80,1,23,54,45,69,31,24,50,51,68,45,65,49,25,80,69,58,28,29}

    Returns: 35384.0

  37. 576

    94220

    {38,79,17,76,40,2,62,62,5,13,62,27,66,68,58,59,1,17,71,30,23,7,40,47,86,18,66,75,8,54,69,45,4,86,31,5,87,2,66,53,14,89,42,41,28,61,9,80,39,79}

    Returns: 61042.4

  38. 749

    84578

    {85,58,70,43,76,7,79,83,22,58,38,25,15,30,82,11,83,57,25,6,56,28,8,45,88,17,35,36,57,15,59,14,73,38,18,20,6,6,64,28,25,63,14,39,2,5,11,84,24,36}

    Returns: 28477.9

  39. 871

    61347

    {63,59,85,23,37,29,20,55,44,78,68,78,77,47,59,83,53,32,20,77,57,33,26,20,38,88,14,23,33,26,63,58,46,57,42,44,86,61,9,1,49,38,40,35,85,8,27,9,1,8}

    Returns: 28.346162960442598

  40. 507

    76810

    {41,34,77,40,32,52,62,26,39,34,45,85,90,86,38,47,57,8,9,67,8,48,63,2,55,52,62,18,59,70,74,61,66,22,10,7,73,33,84,22,28,39,68,80,34,15,36,90,75,7}

    Returns: 51105.1

  41. 128

    63167

    {54,1,45,71,52,68,88,20,47,33,81,22,55,52,80,37,47,74,58,74,22,35,63,55,12,61,17,48,67,44,39,30,44,83,62,57,22,59,39,68,2,81,52,56,42,41,54,50,24,74}

    Returns: 61528.6

  42. 854

    61123

    {70,6,62,43,66,78,90,42,83,38,34,37,82,5,55,13,64,3,43,27,83,4,44,87,44,7,46,30,80,79,74,60,47,7,64,22,84,64,26,77,63,21,75,55,25,39,29,50,42,33}

    Returns: 659.9633734447198

  43. 446

    57510

    {36,81,82,42,88,38,71,39,78,16,60,34,23,34,18,68,7,5,16,31,25,52,47,49,53,76,61,56,70,8,51,16,89,5,19,48,42,51,86,81,66,18,77,50,51,4,80,19,60,57}

    Returns: 37666.854937851684

  44. 329

    58564

    {19,6,4,71,43,64,36,22,72,86,89,32,90,69,79,3,29,36,46,57,53,32,16,65,87,57,45,56,24,56,11,42,23,14,74,27,40,19,10,21,66,61,14,28,39,2,82,30,89,37}

    Returns: 47739.9

  45. 546

    94659

    {30,63,78,26,30,85,43,15,12,53,18,34,67,1,22,16,71,31,88,8,1,11,35,2,64,79,31,62,25,78,75,55,50,25,42,41,71,85,55,82,47,72,77,75,34,8,52,66,90,49}

    Returns: 64920.019559274224

  46. 804

    57770

    {21,70,54,46,58,46,18,45,33,54,9,82,40,50,85,20,6,49,63,53,83,49,37,78,18,51,54,18,9,89,70,82,68,33,37,88,40,16,42,72,70,50,25,71,61,19,1,67,30,25}

    Returns: 329.48522325223166

  47. 271

    99126

    {74,79,61,53,39,76,70,10,74,49,1,14,43,37,11,82,53,52,25,84,63,50,64,85,30,26,23,59,51,13,42,86,2,65,48,2,12,80,11,86,38,63,61,43,10,33,86,24,84,21}

    Returns: 91799.78985848682

  48. 619

    80905

    {32,4,12,61,30,35,82,42,9,33,89,62,59,46,64,71,87,36,28,35,9,88,39,18,30,34,3,75,54,71,54,85,74,65,56,65,61,47,68,70,41,66,3,62,74,66,42,70,12,31}

    Returns: 42612.241132853625

  49. 166

    95884

    {28,14,51,19,48,53,55,11,85,18,58,30,44,75,5,15,83,72,46,33,10,48,56,83,76,7,62,49,89,38,30,26,51,80,6,60,4,22,71,88,39,90,27,83,74,83,59,66,27,66}

    Returns: 93130.07863706618

  50. 610

    83179

    {75,26,28,22,84,51,70,83,88,9,70,11,50,38,70,53,59,12,50,8,11,39,52,84,83,72,21,19,9,43,54,45,30,43,67,23,4,46,67,1,17,9,11,66,46,43,29,14,54,40}

    Returns: 45969.0

  51. 263

    78999

    {78,86,20,71,29,3,51,37,45,67,82,74,19,20,58,22,65,87,75,81,5,47,57,50,89,47,25,53,86,60,27,36,55,8,68,46,10,28,82,16,4,35,89,23,16,19,6,81,15,80}

    Returns: 72082.1

  52. 403

    63204

    {89,51,82,87,7,16,49,3,37,37,90,54,45,67,9,16,56,52,32,60,49,82,44,64,10,11,54,76,1,87,56,89,9,47,47,16,25,6,70,61,4,69,24,10,7,32,78,62,84,19}

    Returns: 46963.1

  53. 273

    87547

    {10,36,15,72,47,31,57,9,79,75,59,87,31,15,64,17,72,43,78,38,73,63,47,79,5,34,51,50,14,5,53,76,41,29,57,49,21,75,57,9,59,77,58,52,1,31,68,35,36,17}

    Returns: 80112.25488981855

  54. 172

    84190

    {80,28,59,84,24,71,5,37,75,57,22,25,47,40,35,68,25,53,76,45,39,5,58,2,88,36,36,33,14,17,12,3,6,70,48,29,50,52,28,35,70,11,21,27,51,56,4,37,18,41}

    Returns: 81231.6

  55. 451

    53566

    {46,49,20,43,46,55,37,59,33,48,62,38,28,71,29,39,33,56,73,64,66,4,90,78,21,3,24,38,6,67,56,13,25,75,17,32,39,53,52,33,62,75,71,51,56,9,90,50,26,34}

    Returns: 33238.29063934889

  56. 1000

    10000

    { 45 }

    Returns: 90000.0

  57. 1000

    0

    { 45 }

    Returns: 100000.0

  58. 1000

    100000

    { 45 }

    Returns: 0.0

  59. 1000

    0

    { 45, 0 }

    Returns: 0.0

  60. 1000

    0

    { 90, 45 }

    Returns: 1.2246467991473533E-11

  61. 1000

    0

    { 89, 2 }

    Returns: 3489.94967025007

  62. 1000

    100000

    { 46, 43 }

    Returns: 60.9172980904259

  63. 1000

    100000

    { 44, 47 }

    Returns: 60.917298090440454

  64. 1

    0

    { 45 }

    Returns: 0.09999999999999999

  65. 1

    0

    { 1 }

    Returns: 0.0034899496702500967

  66. 1000

    10

    {30, 45, 90}

    Returns: 9.999999999987754

  67. 100

    15

    {4, 55, 22, 13, 7, 88, 90 }

    Returns: 14.999999999999877

  68. 10

    5

    {23, 76, 33, 12, 45, 67, 87, 90, 1, 9, 54 }

    Returns: 0.30528437214108894

  69. 100

    0

    {45 }

    Returns: 1000.0

  70. 1000

    10000

    {45 }

    Returns: 90000.0

  71. 10

    5

    {23, 76, 33, 12, 45 }

    Returns: 0.30528437214108894

  72. 5

    40

    {0, 45, 90 }

    Returns: 37.5

  73. 1000

    1

    {90 }

    Returns: 0.9999999999877536

  74. 120

    20367

    {4, 55, 22, 13, 7, 88, 90 }

    Returns: 19013.842626068294

  75. 10

    10

    {45 }

    Returns: 0.0

  76. 36

    12345

    {0, 1, 2, 3, 4, 5, 6, 32, 22, 24 }

    Returns: 12228.516291599628

  77. 77

    55

    {5, 6, 7, 8, 9, 77, 66, 55, 44, 33 }

    Returns: 47.95600453872301

  78. 1000

    1

    {45 }

    Returns: 99999.0

  79. 1000

    0

    {45 }

    Returns: 100000.0

  80. 5

    40

    {0, 90 }

    Returns: 40.0

  81. 5

    40

    {0 }

    Returns: 40.0

  82. 10

    0

    {23, 76, 33, 12, 45 }

    Returns: 4.0673664307580015

  83. 1000

    100

    {0 }

    Returns: 100.0

  84. 1000

    10000

    {90, 89, 88, 87 }

    Returns: 452.8463267653733

  85. 100

    1

    {45 }

    Returns: 999.0

  86. 1000

    40

    {0, 1, 2, 3, 4, 46, 47, 48, 49, 50, 51, 52, 53, 90 }

    Returns: 39.99999999998775

  87. 1000

    40

    {54, 1, 2, 3, 4, 46, 47, 48, 49, 50, 51, 52, 53, 90, 55, 56, 57 }

    Returns: 39.99999999998775


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: