백준 1057번 토너먼트 JAVA

YB·2025년 2월 9일

링크텍스트

설명

프로그래머스 Lv. 2 예상 대진표와 똑같은 문제이다. 링크텍스트
시간복잡도: O(LogN), 공간복잡도: O(1)

설명

import java.util.*;
import java.io.*;

class Main {
	public static void main (String[] args) throws IOException {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    
	    int n = Integer.parseInt(st.nextToken());
	    int kim = Integer.parseInt(st.nextToken());
	    int im = Integer.parseInt(st.nextToken());
	    
	    System.out.println(find(kim,im));
	}
	
	public static int find(int a, int b){
		int answer = 0;
	        
	    while(a!=b){
	        a = (a+1)/2;
	        b = (b+1)/2;
	        answer++;
	    }
	     return answer;   
	}
}

profile
안녕하세요

0개의 댓글