Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- string
- SQL
- Matrix
- Tree
- bit manipulation
- array
- Binary Tree
- greedy
- database
- Number Theory
- Counting
- geometry
- two pointers
- dynamic programming
- Class
- Math
- 구현
- 코테
- 자바
- implement
- Stack
- hash table
- Method
- simulation
- sorting
- java
- 파이썬
- Data Structure
- Binary Search
- 코딩테스트
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1688. Count of Matches in Tournament 본문
1. Input
1) 정수 n
2. Output
1) 다음 규칙에 따라 토너먼트를 진행할 때 우승자가 나올 때 까지의 경기 수를 반환
// 규칙
- 현재 팀이 짝수개라면 2팀씩 짝지어 경기를 진행한다. 이때 진행되는 경기수는 n/2이며 n/2팀이 다음 라운드에 진출하게 된다.
- 현재 팀이 홀수개라면 랜덤으로 1팀이 부전승이 되고 나머지는 경기를 진행한다. 이때 진행되는 경기수는 (n-1)/2이며 (n-1)/2 +1팀이 다음 라운드에 진출하게 된다.
3. Constraint
1) 1 <= n <= 200
4. Example
Input: n = 7 -> Output: 6
설명:
- 1라운드: 7팀, 3경기, 4팀 진출
- 2라운드: 4팀, 2경기, 2팀 진출
- 3라운드: 2팀, 1경기, 우승팀 1팀
- 총 3 + 2 + 1 = 6경기를 진행했으므로 6을 반환한다.
5. Code
1) 첫 코드(2022/06/05)
int count = 0;
while(n>1){
if(n%2==0){
count += n/2;
n /= 2;
} else{
count += (n-1)/2;
n = (n-1)/2 +1;
}
}
return count;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 976. Largest Perimeter Triangle (0) | 2023.01.02 |
---|---|
[LeetCode/Easy] 1704. Determine if String Halves Are Alike (0) | 2023.01.02 |
[LeetCode/Easy] 1684. Count the Number of Consistent Strings (0) | 2023.01.02 |
[LeetCode/Easy] 1678. Goal Parser Interpretation (0) | 2023.01.02 |
[LeetCode/Easy] 1672. Richest Customer Wealth (0) | 2023.01.02 |