Dev.baelanche

[백준 1057] 토너먼트 본문

Data Structure & Algorithm/PS - JAVA

[백준 1057] 토너먼트

baelanche 2019. 6. 29. 17:46
반응형

 

토너머트 참가 인원, 김지민의 번호, 임한수의 번호를 매 반복마다 반으로 줄여준다.

홀수 일때는 +1을 해줘야한다.

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int i;
        boolean m = false;
        for(i=1; n>=2; i++) {
            int arr[] = new int[n+1];
            arr[a] = 1;
            arr[b] = 1;
            for(int start=1; start<n; start+=2) {
                if(arr[start] == 1 && arr[start+1] == 1) {
                    m = true;
                    break;
                }
            }
            if(m) break;
            if(n % 2 == 0) n /= 2;
            else n = n/2 + 1;
            
            if(a % 2 == 0) a /= 2;
            else a = a/2 + 1;
            
            if(b % 2 == 0) b /= 2;
            else b = b/2 + 1;
        }
        
        if(m) System.out.println(i);
        else System.out.println(-1);
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 1915] 가장 큰 정사각형  (0) 2019.07.02
[백준 2903] 중앙 이동 알고리즘  (0) 2019.06.29
[백준 10815] 숫자 카드  (0) 2019.06.29
[백준 1009] 분산처리  (0) 2019.06.29
[백준 2979] 트럭 주차  (0) 2019.06.29
Comments