A1325 | [COCI-2015_2016-contest7]#2 OTPOR
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko has been a very good boy, so he got exactly what he wanted for his birthday, a "Young physicist"
kit! In the kit, there are N types of resistors, connecting wires and an ohmmeter. If a resistor is of type i, it provides a resistance of precisely Ri ohms.
As we all know, resistors can be connected in two different ways, in series and parallel. Also, we know that the complete circuit of resistors can be replaced with one resistor of the resistance equal to the equivalent resistance of the circuit. When the circuit is series, it is written in the following way:
(R1-R2-R3-...-RK)
and the following formula holds:
Rekv = R1 + R2 + R3 + ... + RK When the circuit is parallel, it is written in the following way:
(R1|R2|R3|...|RK)
and the following formula holds:
Rekv =
1 1 R1 + 1 R2 + 1 R3 +...+ 1 RK Mirko was excited to bring his new toy to school, where he showed it to all his friends. Unfortunately for him, the teacher also noticed the toy. She quickly connected a circuit and is now asking Mirko to tell her the equivalent resistance of the circuit. Help Mirko and answer the teacher’s question!
kit! In the kit, there are N types of resistors, connecting wires and an ohmmeter. If a resistor is of type i, it provides a resistance of precisely Ri ohms.
As we all know, resistors can be connected in two different ways, in series and parallel. Also, we know that the complete circuit of resistors can be replaced with one resistor of the resistance equal to the equivalent resistance of the circuit. When the circuit is series, it is written in the following way:
(R1-R2-R3-...-RK)
and the following formula holds:
Rekv = R1 + R2 + R3 + ... + RK When the circuit is parallel, it is written in the following way:
(R1|R2|R3|...|RK)
and the following formula holds:
Rekv =
1 1 R1 + 1 R2 + 1 R3 +...+ 1 RK Mirko was excited to bring his new toy to school, where he showed it to all his friends. Unfortunately for him, the teacher also noticed the toy. She quickly connected a circuit and is now asking Mirko to tell her the equivalent resistance of the circuit. Help Mirko and answer the teacher’s question!
输入格式
The first line of input contains the integer N (1 6 N 6 9) from the task.
The following line contains N real numbers Ri (0 < Ri < 100) from the task.
The last line contains the circuit S, that will not be longer than 100 000 characters. S will only consist of the following characters: ’R’, ’1’ – ’9’, ’(’, ’)’, ’-’ and ’|’. The number of pairs of brackets will be minimal, and the brackets will be paired properly. Inside of a pair of brackets, there will not be the character ’-’ and the character ’|’ at the same time. The circuit will only consist of the resistors from the kit and it is possible that not all types of resistors are used, or that one type of resistor is used several times.
The following line contains N real numbers Ri (0 < Ri < 100) from the task.
The last line contains the circuit S, that will not be longer than 100 000 characters. S will only consist of the following characters: ’R’, ’1’ – ’9’, ’(’, ’)’, ’-’ and ’|’. The number of pairs of brackets will be minimal, and the brackets will be paired properly. Inside of a pair of brackets, there will not be the character ’-’ and the character ’|’ at the same time. The circuit will only consist of the resistors from the kit and it is possible that not all types of resistors are used, or that one type of resistor is used several times.
输出格式
The first and only line of output must contain the number from the task. A deviation from the official solution of ±
0.00001 is tolerated.
0.00001 is tolerated.
输入输出样例
输入 #1
3 2 3 6 (R1-R2-R3)
输出 #1
11.00000
输入 #2
3 2 3 6 (R1|R2|R3)
输出 #2
1.00000
输入 #3
5 5.0 5.0 5.0 5.0 5.0 ((R1-(R2|R3)-(R4|R5))| (R1-(R2|R3)-(R4|R5)))
输出 #3
5.00000
In test cases worth 20% of total points, it will hold:
• N = 3
• S is going to consist of exactly three resistors, R1, R2 and R3, not necessarily in that order
In test cases worth 40% of total points, S is going to have exactly one pair of brackets.
Clarification of the third example: The circuit from the input is broken in two rows in order to maximize
readibility.
• N = 3
• S is going to consist of exactly three resistors, R1, R2 and R3, not necessarily in that order
In test cases worth 40% of total points, S is going to have exactly one pair of brackets.
Clarification of the third example: The circuit from the input is broken in two rows in order to maximize
readibility.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted