코딩테스트/백준

    [플5] 16496 - 큰 수 만들기

    정렬 함수 3번째 인자 _Pred 람다 함수로 깔끔하게 해결 #include #include #include #include #include using namespace std; #define SIZE 1000 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string arr[SIZE]; int n; cin >> n; cin.ignore(); int flag = 0; for (int i = 0; i > arr[i]; if (arr[i] != "0") flag = true; } if (!flag) cout str2 + str1; }); cout

    [실1] 2583 - 영역 구하기 bfs

    #include #include #include #include #include using namespace std; using int_pair = pair; #define SIZE 1000 #define x first #define y second // 상 하 좌 우 int_pair arr_pos[] { {0, 1}, {0,-1}, {-1,0}, {1, 0} }; queue q; bool graph[SIZE][SIZE]{ false }; int zone = 0; // w:넓이, h:높이, k:테스트 개수 int w, h, k; int BFS() { int block_cnt = 0; while (!q.empty()) { auto front = q.front(); q.pop(); for (int i = 0..

    [실1] 14888 - 연산자 끼워넣기

    #include using namespace std; #define OPERATOR_COUNT 4 int n; int arr_operand[1000]; // 수열 int arr_operator[OPERATOR_COUNT]; int min_val = INT_MAX; int max_val = INT_MIN; void DFS(int result, int idx) { if (idx == n) { if (result > max_val) max_val = result; if (result 0) { arr_operator[i]--; ..

    [실1] 11403 - 경로 찾기

    플로이드 와샬 #include #define INF 100000 #define NODE 1000 using namespace std; int graph[NODE][NODE]{ 0 }; void Floyd_washall() { int n; cin >> n; for (int i = 0; i > graph[i][j]; } for (int k = 0; k < n; k++) // 거쳐가는 노드 { for (int i = 0; i < n; i++) // 출발지 노드 { for (int j = 0; j < n; j++) // 도착지 노드 { if (graph[i][k] && graph[k][j]) graph[i][j]= 1; } } } ..

    [실1] 11286 - 절대값 힙

    #include #include #include #include using namespace std; #define y first #define x second int main() { using pq_type = pair; cin.sync_with_stdio(0); cin.tie(0); priority_queue q; int n; cin >> n; for (int i = 0; i > val; if (val != 0) q.push({ abs(val), val }); else { if (q.empty()) cout

    [실1] 1991 - 트리 순회

    #include using namespace std; int n; struct node { char left; char right; }; struct node tree[100]; void preOrder(char root) { if (root == '.') return; else { cout t1 >> t2 >> t3; tree[t1].left = t2; tree[t1].right = t3; } preOrder('A'); cout left); cout data; In_order(_node->right); } // (왼쪽, 오른쪽, 루트) void Post_order(s_node* _node) { if (!_node) return; Post_order(_node->left); Post_order(_node..

    [실1] 2667 - 단지 번호 붙이기

    #include #include #include #include #include #include using namespace std; #define TOTAL_SIZE 5000 #define y first #define x second pair dir[] { { 1, 0 }, // 상 {-1, 0 }, // 하 { 0,-1 }, // 좌 { 0, 1} // 우 }; vector res(TOTAL_SIZE); int map[TOTAL_SIZE][TOTAL_SIZE]{ 0 }; bool visited[TOTAL_SIZE][TOTAL_SIZE]; int b_size = 0; int idx = 0; void BFS(int _y, int _x) { // 탐색 시작 queue q; q.push({ _y, _x })..

    [실2] 1406 - 에디터

    #include #include #include #include #include #include #include using namespace std; list my_list; auto iter = my_list.end(); int count = 0; void Move_left() { if (iter != my_list.begin()) iter--; } void Move_right() { if (iter != my_list.end()) iter++; } void Delete() { if (iter == my_list.begin()) return; iter = my_list.erase(--iter); } void Add(char _letter) { my_list.insert(iter, _letter); } ..

    [실1] 1926 - 그림

    #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_SIZE 502 int board[MAX_SIZE][MAX_SIZE]; bool visited[MAX_SIZE][MAX_SIZE]; int n = 0, m = 0; int dx[4]{ 1, 0, -1, 0 }; int dy[4]{ 0, 1, 0, -1 }; int main() { cin >> n >> m; for (int i = 0; i > board[i][j]; } int mx = 0; //..

    [실1] 2178 - 미로탐색

    특이사항) 좌표 (1,1)부터 (y,x)까지 이동하라는데 (1,1)부터 시작 시 로직이 복잡해지므로 (0,0)부터 시작 #include #include #include #include using namespace std;#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0);#define y first#define x secondusing IntPair = pair;IntPair dir[]{ {1, 0}, // 상 {-1, 0}, // 하 {0, -1}, // 좌 { 0, 1 }, // 우};vector> map, dist;queue q;int y, x, cnt;void Bfs(){ while (!q.empty()) { auto cur = q.front..