Connection Status:
Competition Arena > Connection
Rookie SRM 15 · 2022-07-04 · by lars2520 · Math
Class Name: Connection
Return Type: double
Method Name: signalStrength
Arg Types: (vector<int>, vector<int>, int)
Problem Statement

Problem Statement

An important aspect of many wireless connections is signal strength. The signal strength can affect the speed of the connection, as well as the chance that errors are introduced into the transmitted data.

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.

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
0)
{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

1)
{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.

2)
{-1,20}
{1,0}
25
Returns: -5.0

This example shows that some inputs lead to bogus results such as negative signal strength.

3)
{-7,40,-10,1}
{-4,-2,-1,0}
160
Returns: 0.9390624893188476
4)
{100}
{10}
1000000
Returns: 9.999999999999999E61

Submissions are judged against all 67 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Connection with a public method double signalStrength(vector<int> coeff, vector<int> exp, int dist) · 67 test cases · 2 s / 256 MB per case

Submitting as anonymous