ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • cmp 함수 결과
    아무거나적어~ 2022. 7. 7. 14:41
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    #include <bits/stdc++.h>
    #define endl "\n" // don't use when you cover interactive problem
    #define all(v) (v).begin(), (v).end()
     
    using namespace std;
    typedef long long ll;
    typedef pair<intint> pi;
    typedef pair<ll, ll> pl;
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        priority_queue<intvector<int>, greater<> > pq;
        pq.push(1);
        pq.push(2);
        pq.push(3);
     
        cout << pq.top() << endl// 1이 튀어나옴
     
        return 0;
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    #include <bits/stdc++.h>
    #define endl "\n" // don't use when you cover interactive problem
    #define all(v) (v).begin(), (v).end()
     
    using namespace std;
    typedef long long ll;
    typedef pair<intint> pi;
    typedef pair<ll, ll> pl;
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        vector<int> v = {123};
        sort(all(v), greater<>());
        for(const auto& e: v) cout << e << ' '// 3 2 1
     
        return 0;

    비교함수 true 일때 자리 바꿈
    greater 함수가 return a > b 라서 sort 할땐 큰 수가 앞으로 나오고
    priority queue에서는 부모노드와 자식노드 비교함수라 부모 노드가 크면 위치를 바꿀겁니다
    그래서 작은게 올라가요(root 가 index 0)

    '아무거나적어~' 카테고리의 다른 글

    백준 문제집 만들기 부분-자동화  (0) 2022.08.22
    Markdown with LaTex  (0) 2022.07.15
    Colab 단축키  (0) 2022.07.06
    한글 자음 모음 분리되는 문제 해결 방법  (0) 2022.06.29
    [c++] Reference vs Pointer  (0) 2022.06.27

    댓글

Designed by Tistory.