当前位置:网站首页>Divide candy Huawei od JS
Divide candy Huawei od JS
2022-07-25 03:57:00 【Big chicken legs are best】
Xiao Ming grabs a handful of candy at random from the candy box , Every time Xiao Ming takes out half of the candy and gives it to the students .
When candy is not evenly distributed , Xiao Ming can choose from the candy box ( Suppose there are enough candy in the box ) Take out a candy or put back a candy .
How many times does Xiao Ming need at least ( Take out 、 Put it back and distribute it evenly once ), Can divide the candy in your hand to only one .
Input description :
Number of sweets grabbed (<10000000000):
15
Output description :
The number of times to get at least one candy :
5
Input
15
Output
5
remarks :
explain :(1)15+1=16;(2)16/2=8;(3)8/2=4;(4)4/2=2;(5)2/2=1;
let a=Number(readline())
let res=[]
function f(n,m){
if(n==1){
res.push(m)
return 1
}
if(n%2==0){
m++
f(n/2,m)
}else{
m++
f(n-1,m)
f(n+1,m)
}
return 0
}
f(a,0)
res.sort((a,b)=>a-b)
console.log(res[0])边栏推荐
- Secondary vocational network security skills competition P100 web penetration test
- word怎么取消退出修订模式
- Top101 [linked list] must be applied for interview
- [Flink] submit the jar package to the Flink cluster and run it
- MIM command
- C language_ Structure introduction
- 10. 509 Certificate (structure + principle)
- DNS resolution experiment
- Force the resumption of game 302 of the week
- 292. Nim game
猜你喜欢

2022-07-19 study notes of group 5 self-cultivation class (every day)

基于SSM实现后勤报修系统

原创|记一次高校漏洞挖掘

A 20 yuan facial cleanser sold tens of thousands in seven days. How did they do it?

Installation and tutorial of MATLAB curling simulation game

Original | ueditor1.4.3-asmx bypasses WAF

Lombok detailed introduction

Force deduction brush question 26. Delete duplicates in the ordered array

Detailed explanation of three factory modes

Memory leak due to improper handling of custom view
随机推荐
Interview question 05.06. integer conversion
Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
Postgraduate entrance examination experience
Database transactions (often asked)
Machine learning notes - building a recommendation system (4) matrix decomposition for collaborative filtering
[template engine] microservice Learning Notes 6: freemaker
Implementation of online number or fan query of the scene
DNS domain name resolution service
Deeply understand the connection state and reliable mechanism of TCP protocol
The latest Matlab download and installation tutorial (with files)
Use of CCleaner
[Flink] transform operator flatmap
Niuke interview high frequency list (group 1) difficulty: simple & medium
Which securities company is better to open an account? Is it safe to open an account on your mobile phone
Emergency response stack
Moveit2 - 7. Scenario planning ROS API
"Introduction to interface testing" punch in to learn day04: how to abstract the procedural test script into a test framework?
基于ABP实现DDD--领域逻辑和应用逻辑
MIM command
Execution flow control of shell