CodeForces - 344C
Description Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals Mike needs to assemble an element with a resistance equal to the fraction Input The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction Output Print a single number — the answer to the problem. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64dspecifier. Sample Input
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200 Hint In the first sample, one resistor is enough. In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance 通过题目可以了解到:提供一个R = 1的电阻,让你组成一个满足条件电阻。 如果是199 / 200的例子 1 / (1 / 199 + 1) 如此接着是求解1 / 199的值,而求解这个的值则是直接199个电阻并联既可以得到,如此总共有200个电阻 如此可以发现如果我们先将199 / 200翻转变为了 200 /199 = 1 / 199 + 1,有没有发现,他的结果就是将199 / 200分离为一个R = 1的电阻和其他电阻,如此可以不断翻转,将大的数据放在分子,小的放在分母,不断递归
|
CodeForces - 344C Rational Resistance (模拟题 +递归求解)
最新推荐文章于 2019-09-27 19:59:46 发布