- 생각
1. 단순 수학 문제인 것 같다.
- 코드
정답 코드 : 토너먼트는 한번 이루어질 때마다 사람이 반토막나고, 김지민과 임한수가 번호가 같아질 때 경기가 이루어 진다는 것을 고려해서 코딩했다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
static int N, Kim, Lim;
public static void main(String[] args) throws Exception {
SetData();
System.out.println(GoTournament());
}
private static void SetData() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
Kim = Integer.parseInt(st.nextToken());
Lim = Integer.parseInt(st.nextToken());
}
private static int GoTournament() {
int count = 0;
while(Kim != Lim) {
Kim = Kim/2 + Kim%2;
Lim = Lim/2 + Lim%2;
count++;
}
return count;
}
}
'algorithm' 카테고리의 다른 글
[JAVA] 백준 1735번 : 분수 합 (0) | 2020.11.27 |
---|---|
[JAVA] 백준 1929번 : 소수 구하기 (0) | 2020.11.27 |
[JAVA] 백준 13164번 : 행복 유치원 (0) | 2020.11.24 |
[JAVA] 백준 14442번 : 벽 부수고 이동하기 2 (0) | 2020.11.23 |
[JAVA] 백준 1092번 : 배 (0) | 2020.11.21 |