Algorithm

[BOJ] 11931번 : 수 정렬하기 4

rudgh99_algo 2024. 8. 28. 21:58

1. problem : 

https://www.acmicpc.net/problem/11931

 

2. solution 1 :

// Authored by : heheHwang
// Co-authored by : BaaaaaaaaaaarkingDog
// http://boj.kr/7a7deeedae3b4177a1ed53482685bf15
#include <bits/stdc++.h>
using namespace std;

const int MXN = 2'000'000, HALF = MXN / 2;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);

  vector<bool> isnum(MXN + 2);
  int N, t;
  cin >> N;
  while (N--) {
    cin >> t;
    isnum[t + HALF] = true;
  }
  for (int i = MXN; i >= 0; i--)
    if (isnum[i]) cout << i - HALF << '\n';
}

/*
수의 등장 여부만 확인, 인덱스를 0에서부터 시작할 수 있게 1,000,000을 더함.
*/

merge sort말고 이러한 방법도 있군.

source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x0E/solutions/11931.cpp

 

basic-algo-lecture/0x0E/solutions/11931.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com