Problem Statement
In this problem, you are to write a method that models the signal strength of a connection, given the distance between two wireless components and a function that models the signal strength. The function given to you will be the sum of a number of terms of the form coeff*distexp. Each of these terms will be represented by an element of coeffs and a corresponding element of exp with the same index. Thus, the function 4*dist-1 + 3*dist2 would be represented by coeff = {4,3} and exp = {-1,2}. Your task is to evaluate the function represented by coeff and exp for the given dist and return the result.
Definition
- Class:
- Connection
- Method:
- signalStrength
- Parameters:
- int[], int[], int
- Returns:
- double
- Method signature:
- double signalStrength(int[] coeff, int[] exp, int dist)
- (be sure your method is public)
Constraints
- coeff and exp will each contain between 1 and 50 elements, inclusive.
- coeff and exp will contain the same number of elements.
- Each element of coeff will be between -100 and 100, inclusive.
- Each element of exp will be between -10 and 10, inclusive.
- dist will be between 1 and 1,000,000, inclusive.
- Each element of exp will be distinct.
Examples
{5,4}
{-1,0}
10
Returns: 4.5
Here, the signal strength is evaluated as: 5 * 10-1 + 4 * 100 = 5 * 0.1 + 4 * 1 = 4.5
{100}
{-2}
13
Returns: 0.591715976331361
This is fairly realistic model of a wireless signal in empty space. The surface area of a sphere is proportional to the radius of the sphere squared. Thus, if the strength of a signal at a given distance is evenly distributed over the surface of a sphere, the strength at any one point is proportional to one over the radius squared.
{-1,20}
{1,0}
25
Returns: -5.0
This example shows that some inputs lead to bogus results such as negative signal strength.
{-7,40,-10,1}
{-4,-2,-1,0}
160
Returns: 0.9390624893188476
{100}
{10}
1000000
Returns: 9.999999999999999E61
{1}
{-10}
1000000
Returns: 1.0E-60
{9,-88,95,86,-49,97,58,76,11}
{-2,8,6,3,1,5,10,-3,9}
461291
Returns: 2.5303347867871016E58
{92,-16,9,62,31,-64,-23,63,46,91,55,-36,-8,69,30}
{7,-5,5,9,-9,10,2,8,1,4,-7,-6,-1,-4,-8}
612313
Returns: -4.7414817921128495E59
{50,-95,-63,76,19,61,70,-40,95,-65,20,85,-64,-28,61}
{6,8,5,-10,9,7,4,-1,-4,3,-7,-5,0,10,-8}
823196
Returns: -4.0011993363278854E60
{-34}
{0}
848507
Returns: -34.0
{82,98,-11,-43,-89,23,-6,16,3,90,-87,39,-74,-87,-31,-17}
{3,-3,-2,6,-6,-10,-7,0,1,10,7,-1,9,-4,2,4}
624735
Returns: 8.150801415579656E59
{-84,40,-57,56,-6,24,77,-40,-66}
{1,5,8,0,4,-8,-7,-6,-4}
193466
Returns: -1.1186959755687171E44
{-87,-88,9,92,82,-47}
{-4,9,8,2,1,6}
117958
Returns: -3.8907103402220025E47
{57,58,-63,0,51,72,54,-89,92}
{6,-6,-8,-10,-3,2,-7,5,7}
393849
Returns: 1.3523737747451952E41
{-65,-60,-99,-71,91,-62,58,58,45,-98,-90,-27}
{9,6,-7,2,-3,-10,3,-1,7,-8,4,1}
203031
Returns: -3.8104348431727925E49
{8,7,-43,92,47,-94,-27,46,-35,5,89,54,-61}
{7,-10,4,-5,-3,1,5,-2,6,-8,3,-7,9}
377652
Returns: -9.531383327838629E51
{-47,38,-90,61,-42,16}
{-7,7,-3,-10,1,4}
854959
Returns: 1.2688217524341418E43
{94,-59,-16,1,-59,77,20,-46,15,84}
{-7,1,2,-8,10,7,8,4,0,5}
175466
Returns: -1.6322315563155113E54
{80,71,-97,-83,-21,-55,-79,83,-19}
{3,9,6,-7,-2,-9,-10,-4,-5}
523034
Returns: 2.079829049936733E53
{-87,5,-10,-45,32,-34,-100,20,14,2,69,-61,-26,2,70,46,-62,10,23}
{7,4,-9,-10,-5,-7,-2,9,8,-4,-3,6,2,-8,0,5,3,1,10}
405393
Returns: 2.7573457157340942E57
{-28,97,-70,5,37,-40,-14,-52,82}
{8,-10,10,-1,-6,-2,2,0,6}
275459
Returns: -1.7606284094103215E56
{86,29,67,94,7,50}
{-9,3,7,-10,0,-7}
840372
Returns: 1.983242497295197E43
{15,-31,-77,-4,22,-41,69,-80,-95,10,-53,-44,93,-50}
{7,2,10,5,-4,-8,-3,-2,-1,0,-7,6,8,9}
251507
Returns: -7.798168515068407E55
{87,19,9,-1,-29,67,56,29,35,86,-86,19,64,-23,93,-14,-68}
{10,-8,-7,-1,3,7,1,-2,-5,-9,-3,0,-10,5,9,2,4}
67046
Returns: 1.5968161047538277E50
{12,-86,-51,63,21,-12,-55}
{-4,-1,2,9,-10,7,1}
783845
Returns: 7.037400719808777E54
{64,-6,21,70,79}
{10,7,-2,1,-8}
205635
Returns: 8.652673748573099E54
{-1,61,88,-20,-29,-3,-64,-6,-43,16,-77}
{2,-1,8,4,10,6,1,-6,0,-5,-7}
38740
Returns: -2.2079750462952473E47
{-67,-11,-36,-88,59,-95,70,36,-7,51,32,86,27,25,-51,-47}
{-9,9,8,-7,0,-5,6,2,-3,5,3,1,-1,-2,7,-8}
919908
Returns: -5.189120929110706E54
{-29,60,72,-89,-77,43}
{0,6,7,-8,3,-2}
772403
Returns: 1.18097479374735E43
{-57,-47,49,-19,21}
{-6,-4,2,8,-2}
112120
Returns: -4.744804398896554E41
{-44,-63,-24,79,70,1,69,-15,-53,-81,-11,-4,70,64,77}
{-1,1,-4,4,-7,5,3,9,-6,7,-3,8,2,-5,-10}
261337
Returns: -8.529033383711312E49
{-57,64,-2,-95,21,-73,-51,-33,99,-85,25,82,-50,-80,81}
{-4,-6,10,-1,1,-7,-8,-9,-3,2,9,-5,3,5,0}
900023
Returns: -6.9752542638076E59
{5,-84,-100,-35,-56,-75,88,-66,35,14,-81,-16,-48,45,-56,26}
{5,-4,-6,8,-3,-10,1,-7,-5,-8,3,-2,0,-9,9,7}
629720
Returns: -8.719987031537303E53
{54,93,-22,62}
{9,10,1,6}
779205
Returns: 7.67362511997115E60
{27,-87,8,-42,-37,-16,51,-27,55,-11,68,81}
{5,-4,-7,1,-6,8,4,9,-5,-3,-2,7}
44002
Returns: -1.6696343172378647E43
{35,29,57,86,70,-19,75,83,8,-92,-20,5,-7,38,-24,45,76,81,-100,-25}
{5,-2,-4,-5,9,-8,-9,10,-1,6,-6,-3,0,7,8,4,1,-10,-7,3}
3192
Returns: 9.116363606400812E36
{65,-79,-43,-11,-11,-87,-99,-72,20,7,-86,84,-64,94,59,74,93}
{-1,0,4,-3,7,10,-2,3,-7,1,-10,-5,-8,-6,8,6,-9}
708786
Returns: -2.784008520132413E60
{-36}
{1}
817727
Returns: -2.9438172E7
{-41,-13,47,-7,-96,45,-11,-11,53,0,10,-3,54,85,-7}
{2,4,-4,-3,9,8,-9,1,-10,-5,-1,-7,-8,3,5}
649187
Returns: -1.966071237323582E54
{72,-59}
{2,-2}
287344
Returns: 5.944793352192E12
{-91,-7,-23,-47,23,1,-7,-52}
{3,1,9,8,-8,-10,7,-5}
244975
Returns: -7.308484929588386E49
{-64,80,62,50,-80,-26,-21,12,36,20,-88,72,45,6,64,36,-71,16,95,92,8}
{-6,4,2,-10,6,8,9,10,-2,-4,-9,-8,-3,1,0,3,5,-1,-5,-7,7}
987941
Returns: 1.0628955015045036E61
{22,-96,74,-43,6,10,50,67,41,20,-5,24}
{3,0,-5,10,7,-10,8,-7,-9,9,-4,5}
166976
Returns: -7.244489322492785E53
{28,21,-30,32,57,85,58,-42,8,90,-30,6,95,5,31,66,-35,31,-57}
{9,-8,4,10,-9,6,-7,8,1,2,-6,-1,3,-3,-2,5,-10,-4,0}
835471
Returns: 5.302299196095304E60
{88,0,-20,90,17,46,-23}
{4,-2,2,8,9,1,-8}
748739
Returns: 1.2572628634459434E54
{-77,16,80,38,83,-70,-10,73,8,6,-29,-100,-21,42,-1}
{1,-3,3,7,0,10,6,-10,-9,-7,-4,-5,2,4,8}
999448
Returns: -6.961455840611339E61
{29,-64,-42,46,3,100,12,-53,-86,-58,31}
{-7,-10,0,1,-1,8,6,7,-4,-6,-2}
756441
Returns: 1.0720133072042169E49
{55}
{6}
770402
Returns: 1.1499186003353288E37
{-69,11,72,-96,-20,42,-34,-55,-97,-67,27,-56,-5}
{4,6,8,-6,-7,-5,-10,1,0,-8,3,7,5}
205713
Returns: 2.3090043774826188E44
{59,-96,-73,93,-67,-19,-3,-24,53,59,80,84}
{4,10,-4,-10,-8,-7,3,9,-3,-9,0,1}
809105
Returns: -1.1543040435228476E61
{73,92,-49,6,-39,14,10}
{-6,0,-2,-1,9,-7,6}
300784
Returns: -7.858817106906519E50
{-47,21,68,-59,-19,84,24,66,-66,-27,-33,-81,-43,27,78,-91,-59}
{-2,-8,2,-5,3,-3,5,-1,-9,1,10,-10,7,-7,6,0,-6}
826365
Returns: -4.9004175560835495E60
{-48,76,-84,-25,-36,-82,-15}
{8,-1,2,10,-9,-5,0}
958812
Returns: -1.641627492639277E61
{56,-80,66,5,79,7,46,56,-71,80,-24}
{4,-3,-4,6,5,7,-9,8,-7,1,9}
328757
Returns: -1.0766715513252542E51
{62,81,-66,-36}
{10,-10,5,0}
162226
Returns: 7.827017211762239E53
{-53,-16,87,-59,-49,-77,-55,73,1,-96}
{-7,-1,-8,10,6,-3,9,-4,4,8}
528852
Returns: -1.009704491481508E59
{-7, 40, -10, 1 }
{-4, -2, -1, 0 }
160
Returns: 0.9390624893188476
{5, 4, 3 }
{1, 2, 3 }
10
Returns: 3450.0
{100 }
{-2 }
13
Returns: 0.591715976331361
{1, 1 }
{9, 10 }
1000000
Returns: 1.0000009999999999E60
{5, 4 }
{-1, 0 }
10
Returns: 4.5
{2, 23, 22, 2, 2 }
{-5, -4, 4, 3, -2 }
19
Returns: 2880780.005717461
{4, 5, 6 }
{-1, 4, 8 }
90
Returns: 2.582803292805E16
{10, 20, 30, 40 }
{2, 3, 4, 5 }
3
Returns: 12780.0
{24 }
{5 }
100
Returns: 2.4E11
{1, 8, 7 }
{8, 7, 9 }
10
Returns: 7.18E9
{-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100 }
{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
1000000
Returns: -1.0000010000009999E62