import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s = sc.nextLine(); String[]ss = s.split(","); dfs(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]),0 );System.out.println(ans);} } static int ans = Integer.MAX_VALUE; static void dfs(int a,int b,int curstep) { if(ans <= curstep)return; if(a == b) { ans = Math.min(ans,curstep); return; } if(a > b) dfs(a-1,b,curstep+1); else if(a < b) { if(a > 0) { dfs(2*a,b,curstep+1); } dfs(a+1,b,curstep+1); } }}
点赞 2

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务