Ezcho

[1011] Fly me to the Alpha Centauri(코드) 본문

Algorithm/BOJ

[1011] Fly me to the Alpha Centauri(코드)

Ezcho 2022. 11. 6. 23:41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

        public static int l;

        public static void main(String[] args) throws IOException {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int t = Integer.parseInt(br.readLine());

            StringBuilder sb = new StringBuilder();

            for(int j = 0;j<t;j++) {
                StringTokenizer st = new StringTokenizer(br.readLine());

                int x = Integer.parseInt(st.nextToken());
                int y = Integer.parseInt(st.nextToken());

                l = y-x;

                int cnt = 0;

                for(int i=1; i<l ; i++){
                    if(l<i)
                        break;
                    else{
                        l = l-i;
                        cnt++;
                        if(l<i){
                            break;
                        }
                        else{
                            l = l-i;
                            cnt++;
                        }
                    }
                }
                if(l==0)
                    sb.append(cnt).append("\n");
                else
                    sb.append(cnt+1).append("\n");
            }
            System.out.print(sb);
        }
 }

'Algorithm > BOJ' 카테고리의 다른 글

[1016] 제곱 ㄴㄴ 수(코드)  (0) 2022.11.13
[17387] 선분 교차 판별 II(코드)  (0) 2022.10.09
[17386] 선분 교차 판별 1(코드)  (0) 2022.10.02
[13270]피보나치킨(코드+풀이)  (1) 2022.09.14
[1316] 그룹 단어 체커(java)  (0) 2022.08.08
Comments