title: "숨바꼭질(1697)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-23" 문제 링크 숨바꼭질(1697) C++ #include #include #include #include using namespace std; void solution(){ int n, k; cin >> n >> k; const int limit = 100000; vector visited(limit+1, false); queue q; q.push({n, 0}); visited[n]=true; while(!q.empty()){ int current = q.front().first; int time = q.front().second; q.pop(); /..
title: "Z(1074)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-23" 문제 링크 Z(1074) C++ #include #include #include using namespace std; int n, r, c; int mark; void divide(int size, int row, int col){ if(r==row && c==col){ // 원하는 위치 cout r >> c; int size = 1 { if (r === row && c === col) { // 위치 찾음. console.log(mark); } else if (r >= row && r = col && c < col + ..
title: "좌표 압축(18870)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-22" 문제 링크 좌표 압축(18870) C++ #include #include #include #include #include using namespace std; int doBst(vector& vec, int target){ int left = 0; int right = vec.size()-1; while(left < right){ int mid = (left + right) / 2; if(vec[mid] == target){ left = mid; break; } else if(vec[mid] < target){ left = mid+1; } el..
title: "최소 힙(1927)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-21" 문제 링크 최소 힙(1927) C++ #include #include #include #include using namespace std; typedef unsigned int uint; void solution(){ int n; cin >> n; priority_queue pq; for(int i=0; i> x; if(x>0){ pq.push(x); } else { if(!pq.empty()){ cout
title: "연결 요소의 개수(11724)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-21" 문제 링크 연결 요소의 개수(11724) C++ #include #include #include #include using namespace std; int find_root(map& parent, int num){ if(parent[num] == num) return num; else return parent[num]=find_root(parent, parent[num]); } void doUnion(map& parent, int num1, int num2){ int rootNum1 = find_root(parent, num1); in..
title: "최대 힙(11279)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-21" 문제 링크 최대 힙(11279) C++ #include #include #include #include using namespace std; void solution(){ int n; cin >> n; priority_queue pq; for(int i=0; i> x; if(x == 0){ if(!pq.empty()){ cout
title: "찾기(1786)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-20" 문제 링크 찾기(1786) C++ #include #include #include using namespace std; vector makeLPS(string pattern){ vector table(pattern.length(), 0); int left=0; int right=1; while(right0 && pattern[left] != pattern[right]){ // 패턴이 맞지 않을 경우 left = table[left-1]; } if(pattern[left] == pattern[right]){ // 패턴이 맞을 경우 table[right]..
title: "동전 0(11047)" category: 백준[Class-3] tags: [C++, JavaScript, 백준] date: "2021-05-20" 문제 링크 동전 0(11047) C++ #include #include #include using namespace std; void solution(){ int n, k; cin >> n >> k; vector coins; for(int i=0; i> coin; coins.push_back(coin); } // 가치가 큰 동전부터 진행(greedy) int total = k; int count = 0; for(int i=coins.size()-1; i>=0; i--){ int coin = coins[i]; if(total >= coin){ co..