#P8035. [COCI 2015/2016 #7] Otpor
[COCI 2015/2016 #7] Otpor
Problem Description
As is well known, resistors can be connected in two ways: series and parallel. All resistors in a circuit can be regarded as the equivalent resistance of the circuit. A series connection can be written as:
and it satisfies:
A parallel connection can be written as:
and it satisfies:
Now you are given types of resistors with resistance values , and enough wires. Given the connection pattern of these resistors, find the equivalent resistance of the whole circuit.
Input Format
The first line contains an integer .
The second line contains real numbers .
The third line contains a string that represents the circuit. The string contains only , , , , , and . The data guarantees that there will be no mismatched parentheses or illegal situations, and the number of parentheses is minimized. Inside any pair of parentheses, and will not appear at the same time. The circuit contains only the given types of resistors, and each type may appear any number of times (including times).
Output Format
Output the equivalent resistance of the whole circuit. Your answer is considered correct if its absolute or relative error does not exceed .
3
2 3 6
(R1-R2-R3)
11.00000
3
2 3 6
(R1|R2|R3)
1.00000
5
5.0 5.0 5.0 5.0 5.0
((R1-(R2|R3)-(R4|R5))|(R1-(R2|R3)-(R4|R5)))
5.00000
Hint
Constraints
- For of the testdata, and the circuit contains exactly these three types of resistors.
- For of the testdata, contains only one pair of parentheses.
- For of the testdata, , , .
Hints and Notes
Translated from COCI 2015-2016 #7 Task 4 Otpor.
The score for this problem follows the original COCI settings, with a full score of .
Translated by ChatGPT 5