Editorial for COCI '15 Contest 7 #4 Otpor
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Firstly, we must notice that each circuit is either in the form of (S1|S2|...|Sn)
or in the form (S1-S2-...-Sn)
, where each of is either in one of the forms of or equivalent to some form of .
Therefore, we can write the following pseudocode for the recursive function that solves the task:
res(S):
if S = R_i then return R_i
else if S = (S1-S2-...-Sn) then return sum(res(S_i))
else return 1/(sum(1/res(S_i)))
Comments