今天在健身房看到的怪事# Joke - 肚皮舞运动
s*e
1 楼
有机会再上其他题目.
题目大意如下,请注意输入输出的格式,这里有309 digits 的要求:
https://en.wikipedia.org/wiki/Power_of_two
309 digits,相当于 2^1024
The fuel control mechanisms have three operations:
1) Add one fuel pellet
2) Remove one fuel pellet
3) Divide the entire group of fuel pellets by 2 (due to the destructive
energy released when a quantum antimatter pellet is cut in half, the safety
controls will only allow this to happen if there is an even number of
pellets)
Write a function called answer(n) which takes a positive integer as a string
and returns the minimum number of operations needed to transform the number
of pellets to 1. The fuel intake control panel can only display a number up
to 309 digits long, so there won't ever be more pellets than you can
express in that many digits.
For example:
answer(4) returns 2: 4 -> 2 -> 1
answer(15) returns 5: 15 -> 16 -> 8 -> 4 -> 2 -> 1
Test cases
==========
Inputs:
(string) n = "4"
Output:
(int) 2
Inputs:
(string) n = "15"
Output:
(int) 5
题目大意如下,请注意输入输出的格式,这里有309 digits 的要求:
https://en.wikipedia.org/wiki/Power_of_two
309 digits,相当于 2^1024
The fuel control mechanisms have three operations:
1) Add one fuel pellet
2) Remove one fuel pellet
3) Divide the entire group of fuel pellets by 2 (due to the destructive
energy released when a quantum antimatter pellet is cut in half, the safety
controls will only allow this to happen if there is an even number of
pellets)
Write a function called answer(n) which takes a positive integer as a string
and returns the minimum number of operations needed to transform the number
of pellets to 1. The fuel intake control panel can only display a number up
to 309 digits long, so there won't ever be more pellets than you can
express in that many digits.
For example:
answer(4) returns 2: 4 -> 2 -> 1
answer(15) returns 5: 15 -> 16 -> 8 -> 4 -> 2 -> 1
Test cases
==========
Inputs:
(string) n = "4"
Output:
(int) 2
Inputs:
(string) n = "15"
Output:
(int) 5