Recent Posts
Notice
No Rules Rules
이진 검색 트리 (feat. 백준, 5639번) 본문
728x90
반응형
이진 검색 트리
https://www.acmicpc.net/problem/5639
5639번: 이진 검색 트리
트리를 전위 순회한 결과가 주어진다. 노드에 들어있는 키의 값은 106보다 작은 양의 정수이다. 모든 값은 한 줄에 하나씩 주어지며, 노드의 수는 10,000개 이하이다. 같은 키를 가지는 노드는 없다
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
using namespace std;
int arr[10001];
int ans[10001];
void solution(register int s, register int e) {
if (s >= e)
return;
register int i = 0;
for (i = s + 1; i < e; ++i)
if (arr[s] < arr[i])
break;
solution(s + 1, i);
solution(i, e);
cout << arr[s] << "\n";
}
int main(void) {
ios::sync_with_stdio(false), cin.tie(NULL);
register int value, cnt = 0;
while (cin >> value) {
if (value == EOF)
break;
arr[cnt++] = value;
}
solution(0, cnt);
return 0;
}
// *&)*@*
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
백조의 호수 (feat. 백준, 3197번) (0) | 2022.08.31 |
---|---|
집합의 표현 (feat. 백준, 1717번) (0) | 2022.08.30 |
트리의 순회 (feat. 백준, 2263번) (0) | 2022.08.30 |
미확인 도착지 (feat. 백준, 9370번) (0) | 2022.08.30 |
특정한 최단 경로 (feat. 백준, 1504번) (0) | 2022.08.30 |
Comments