분류 전체보기60 백준 1764 c++ https://www.acmicpc.net/problem/1764 이번에 set이라는 자로구조를 썼는데 집합과 같은 역할을 하는데 hash map을 기반으로 만들어져서 탐색이 빠르다는 장점이 있다. 그래서 사용했다.#include#include#include#includeusing namespace std;set unheard;vector notwo;int main() { int h, w; cin >> h >> w; for (int i = 0; i > temp; unheard.insert(temp); } for (int i = 0; i > temp; if (unheard.find(temp) != unheard.end()) { notwo.push_back(temp); } } sort(notwo... 2024. 12. 3. 백준 2606 그래프문제 C++ https://www.acmicpc.net/problem/2606 그냥 dfs로 순회했다.#include#include#include#includeusing namespace std;vector graph[101];bool visited[101] = { 0, };int v, n;int sum = 0;void dfs(int i) { visited[i] = true; for (int k : graph[i]) { if (visited[k] == false) { dfs(k); sum++; } }}int main() { cin >> v >> n; for (int i = 0; i > temp1 >> temp2; graph[temp1].push_back(temp2); graph[temp2].push_.. 2024. 12. 1. 백준 1966 C++ https://www.acmicpc.net/problem/1966 우선순위 큐가 있는지 모르고 vector로 sort돌려서 우선순위를 따로 체크했는데그냥 우선순위 큐를 쓰면 더 편하게 풀 수 있을 것 같다. #include#include#include#includeusing namespace std;struct MyStruct{ int num; int prior;};void solve(int n, int w) { queueq; vectorv; int num = 1; int vnum = 0; for (int i = 0; i > temp; q.push({i, temp}); v.push_back(temp); } sort(v.rbegin(), v.rend()); while (!q.empty()) { .. 2024. 11. 30. 1920 C++ (정렬/탐색) https://www.acmicpc.net/problem/1920 algorism 라이브러리가 익숙하면 쉬운 문제이다. binary_search(), sort()만 쓰면 된다.이진탐색은 정렬 된 데이터만 탐색이 가능하므로 sort를 돌려야한다.#include#include#include#includeusing namespace std;stackstk;int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, n2; cin >> n; vectorv(n); for (int i = 0; i > v[i]; } sort(v.begin(), v.end()); cin >> n2; for (int i = 0; i > temp; if (binary_sear.. 2024. 11. 28. 1026 C++ 그리디 그냥 벡터 두개 있는데 하나는 오름차순, 하나는 내림차순#include#include#includeusing namespace std;vectorA;vectorB;int main() { int n; int sum = 0; cin >> n; for (int i = 0; i > temp; A.push_back(temp); } for (int i = 0; i > temp; B.push_back(temp); } sort(A.rbegin(), A.rend()); sort(B.begin(), B.end()); for(int i=0; i 2024. 11. 26. ios_base::sync_with_stdio(0); cin.tie(0); 이게 뭐야? ### `ios_base::sync_with_stdio(0);`와 `cin.tie(0);`의 의미 이 두 줄은 **C++에서 입력과 출력 속도를 최적화**하기 위해 자주 사용되는 코드입니다. 특히, 많은 입력과 출력을 처리해야 하는 경우 성능을 크게 향상시킬 수 있습니다. --- ### 1. **`ios_base::sync_with_stdio(0);`** - **기본 동작** C++의 `cin`과 `cout`은 C의 `scanf`와 `printf`와 동기화되어 동작합니다. 이는 두 입력/출력 방식을 함께 사용했을 때 데이터의 순서를 보장하지만, 성능이 떨어질 수 있습니다. - **역할** `ios_base::sync_with_stdio(0);`는 이 동기화를 끊어 C++의 입출력(`cin`.. 2024. 11. 20. 이전 1 2 3 4 5 ··· 10 다음