[백준, BOJ 1011] Fly to the Alpha Centauri (java)
Problem Solving/BOJ

[백준, BOJ 1011] Fly to the Alpha Centauri (java)

728x90

출처-https://www.acmicpc.net/problem/1011

 

1011번: Fly me to the Alpha Centauri

우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들이 살아갈 수 있는 미래가 오리라 믿었다. 그리고 그가 지구라는 세상에 발을 내려 놓은 지 23년이 지난 지금, 세계 최연소 ASNA 우주 비행��

www.acmicpc.net


728x90

 

참고

https://st-lab.tistory.com/79

https://zorba91.tistory.com/116 

 

 

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int ans[] = new int[t];
		
		for (int i=0; i<t; i++) {
			int x = scan.nextInt();
			int y = scan.nextInt();
			int movingDis = 1;
			int xCount = 0;
			int yCount = 0;
			
			while (x < y) {
				x += movingDis;
				xCount++;
				
				if (x >= y)
					break;
				
				y -= movingDis;
				yCount++;
				movingDis++;
			}
			ans[i] = xCount+yCount;
		}
		
		for (int i=0; i<t; i++)
			System.out.println(ans[i]);
	}

}
728x90