#P8035. Equivalent Resistance Calculation in Resistor Networks
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:
Parallel Connection:
The resistors in parallel are denoted as (R1|R2|R3|...|RK)
and evaluated as:
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:
- The first line contains an integer \( N \) denoting the number of resistor types.
- The second line contains \( N \) space-separated floating point numbers representing the resistor values \( R_1, R_2, \dots, R_N \).
- The third line contains a string that represents the resistor connection scheme using series (
-
) and parallel (|
) connectors. The identifiers are of the formRk
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