import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ int n = sc.nextInt(); if(n==0 || Math.abs(n)==1){ System.out.println(n); return; } int location1 = -1, location2 = 1; int step = 2; n = Math.abs(n); System.out.println(Math.min(get(n,location1,step),get(n,location2,step))); } } static int get(int x, int location , int step){ while (location<x){ if(location+step>x){ location -= step; step++; }else if(location+step<x){ location += step; step++; }else { break; } } return step; } }
点赞 评论

相关推荐

10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
牛客网
牛客企业服务