[백준] 10814번: 나이순 정렬
·
PS
문제https://www.acmicpc.net/problem/10814  개념정렬  실행 결과     구현 코드(c++)#include #include #include using namespace std;// 정렬 기준 - 나이 오름차순bool comp(const pair& a, const pair& b) { return a.first > n; vector> arr(n); for (int i = 0; i > arr[i].first >> arr[i].second; } // 안정적인 정렬 사용 stable_sort(arr.begin(), arr.end(), comp); for (const auto& member : arr) { cout     코드 설명먼저 나는 일반 sort 함수를 사용했..
[백준] 9935번: 문자열 폭발
·
PS
문제https://www.acmicpc.net/problem/9935  개념문자열, 스택  실행 결과    구현 코드(c++)#include #include using namespace std;int main() { string a, b, res; cin >> a >> b; for (char c : a) { res += c; if (res.size() >= b.size()) { int idx = res.size() - b.size(); if (res.substr(idx) == b) res.erase(idx); } } cout     코드 설명처음 문제를 풀 때는 스택 자료구조를 사용했다. 문자열의 인덱스를 이용해 한 글자씩 스택에 넣고 폭발 문자열과..
[백준] 2667번: 단지번호붙이기
·
PS
문제https://www.acmicpc.net/problem/2667  개념그래프, DFS, BFS  실행 결과     구현 코드(c++)#include #include #include #include using namespace std;int g[25][25];bool v[25][25];int dx[4] = {-1, 1, 0, 0};int dy[4] = {0, 0, -1, 1};int n;int dfs(int x, int y) { int cnt = 1; v[x][y] = true; for (int i = 0; i = 0 && ny >= 0 && nx > n; cin.ignore(); for (int i = 0; i danzis; int cnt = 0; for (int i = 0; i   ..
[코드트리] 제곱수의 합으로 나타내기
·
PS
문제 코드트리 | 코딩테스트 준비를 위한 알고리즘 정석국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.www.codetree.ai  개념DP  실행 결과     구현 코드(c++)#include #include #include using namespace std;int sol(int n) { vector dp(n + 1, 5000); dp[0] = 0; for (int i = 1; i > n; cout     코드 설명최소 개수의 제곱수 합으로 표현하기 위한 최소 제곱수의 수를 저장하는 dp 배열을 선언한다. 최소 제곱수를 계산해야하므로 문제에서 최대 범위로 주어진 5000으로 초기화한다. j를 각 제곱수라고 하면, j를 ..
[백준] 1010번: 다리 놓기
·
PS
문제https://www.acmicpc.net/problem/1010  개념수학(조합), 다이나믹 프로그래밍  실행 결과    구현 코드(c++)#include using namespace std;int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; unsigned long long res = 1; for (int i = 0; i     코드 설명단순히 조합 mCn을 계산하는 문제이다.처음에는 공식을 사용하여 단순 계산식을 만들었으나 시간 초과로 실패하거나 메모리 에러가 발생했다..