2680. Equilibrium Mobile

单点时限: 2.0 sec

内存限制: 256 MB

A mobile is a type of kinetic sculpture constructed to take advantage of the principle of equilibrium. It consists of a number of rods, from which weighted objects or further rods hang. The objects hanging from the rods balance each other, so that the rods remain more or less horizontal. Each rod hangs from only one string, which gives it freedom to rotate about the string. We consider mobiles where each rod is attached to its string exactly in the middle, as in the figure underneath. You are given such a configuration, but the weights on the ends are chosen incorrectly, so that the mobile is not in equilib-rium. Since that’s not aesthetically pleasing, you decide to change some of the weights. What is the minimum number of weights that you must change in order to bring the mobile to equilibrium? You may substitute any weight by any (possibly non-integer) weight. For the mobile shown in the figure, equilibrium can be reached by changing the middle weight from 7 to 3, so only 1 weight needs to changed.


On the first line one positive number: the number of testcases, at most 100. After that per testcase:

One line with the structure of the mobile, which is a recursively defined expression of

the form:

::= | “[” “,” “]”

with a positive integer smaller than 109 indicating a weight and [ , ]

indicating a rod with the two expressions at the ends of the rod. The total number of

rods in the chain from a weight to the top of the mobile will be at most 16.


Per testcase:

One line with the minimum number of weights that have to be changed.



2 人解决,7 人已尝试。

2 份提交通过,共有 9 份提交。

9.4 EMB 奖励。

创建: 14 年,2 月前.

修改: 6 年,3 月前.

最后提交: 6 年,3 月前.

来源: NWERC 2008