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.

Firstly, we must notice that each circuit S is either in the form of (S1|S2|...|Sn) or in the form (S1-S2-...-Sn), where each of S_1, S_2, \dots, S_n is either in one of the forms of S or equivalent to some form of R_1, R_2, \dots, R_m.

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

There are no comments at the moment.