Algorithm/Problem Solving 2020. 6. 2. 21:06

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/11004

 

사용 알고리즘

- 정렬

 

풀이

- STL nth_element 이용

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/11004.cpp

#include <cstdio>
#include <algorithm>
 
using namespace std;
 
int arr[5000003];
 
int main(void) {
    int n, k; scanf("%d %d"&n, &k);
    --k;
    for (int i = 0; i < n; ++i) scanf("%d"&arr[i]);
    nth_element(arr, arr + k, arr + n);
    printf("%d\n", arr[k]);
    return 0;
}
cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/1377] 버블 소트  (0) 2020.06.03
[BOJ/11652] 카드  (0) 2020.06.01
[BOJ/10989] 수 정렬하기 3  (0) 2020.05.26
[BOJ/10825] 국영수  (0) 2020.05.24
[BOJ/10814] 나이순 정렬  (0) 2020.05.22
posted by DevMoomin
: