#P8035. Equivalent Resistance Calculation in Resistor Networks

    ID: 21219 Type: Default 1000ms 256MiB

Equivalent Resistance Calculation in Resistor Networks

Equivalent Resistance Calculation in Resistor Networks

In electrical circuits, resistors can be connected either in series or in parallel. For a given circuit, the overall (equivalent) resistance, \( R_{ekv} \), can be computed.

Series Connection:

The resistors in series are denoted as (R1-R2-R3-...-RK) and evaluated as:

\[ R_{ekv} = \sum_{i=1}^K R_i \]

Parallel Connection:

The resistors in parallel are denoted as (R1|R2|R3|...|RK) and evaluated as:

\[ R_{ekv} = \frac{1}{\sum_{i=1}^K \frac{1}{R_i}} \]</p>

You are given N types of resistors. The second input line contains the resistor values \( R_1, R_2, \dots, R_N \). The third line is a string that expresses the connection scheme using the above notations. The resistor identifiers are in the format Rk where \(1 \leq k \leq N\). Note that the connection expression may be nested arbitrarily.

Your task is to output the overall equivalent resistance value of the circuit. The output should be a floating point number rounded to 2 decimal places.

inputFormat

The input consists of three lines:

  1. The first line contains an integer \( N \) denoting the number of resistor types.
  2. The second line contains \( N \) space-separated floating point numbers representing the resistor values \( R_1, R_2, \dots, R_N \).
  3. The third line contains a string that represents the resistor connection scheme using series (-) and parallel (|) connectors. The identifiers are of the form Rk where \(k\) is a positive integer.

outputFormat

Output a single line containing the equivalent resistance of the circuit, rounded to 2 decimal places.

sample

3
10 20 30
(R1-R2-R3)
60.00