https://stepbystep321.tistory.com/39
#include #include #include using namespace std; int main() { int n, b; scanf("%d %d", &n, &b); int rest; string result = ""; while (n > 0) { rest = n % b; n = n / b; if (rest < 10) { result = to_string(rest) + result; } else { result = (char)('A' + rest - 10) + result; } } cout
1. 다익스트라 알고리즘 한 정점에서 모든 정점으로의 최단경로를 구하는 알고리즘이다. https://www.acmicpc.net/problem/1753 1753번: 최단경로 첫째 줄에 정점의 개수 V와 간선의 개수 E가 주어진다. (1≤V≤20,000, 1≤E≤300,000) 모든 정점에는 1부터 V까지 번호가 매겨져 있다고 가정한다. 둘째 줄에는 시작 정점의 번호 K(1≤K≤V)가 주어진다. www.acmicpc.net #include #include #include #include #define INF 1000000000 using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int v, e, sta..
https://programmers.co.kr/learn/courses/30/lessons/49189 코딩테스트 연습 - 가장 먼 노드 6 [[3, 6], [4, 3], [3, 2], [1, 3], [1, 2], [2, 4], [5, 2]] 3 programmers.co.kr 난이도 최단거리 / 난이도 ⭐️⭐️⭐️/ 1.5시간 문제풀이 최단거리 문제이다. 다익스트라 알고리즘을 알고있으면 쉽게 풀 수 있으나, 몰라서 오래걸렸다. #include #include #include #include #include #define INF 1000000000 using namespace std; int solution(int n, vector edge) { int answer = 0; vector vertex(n+1..
https://programmers.co.kr/learn/courses/30/lessons/42842 코딩테스트 연습 - 카펫 Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 programmers.co.kr 난이도 완전탐색 / 난이도 ⭐️/ 10분 문제풀이 #include #include using namespace std; vector solution(int brown, int yellow) { vector answer; // 1 24 => 26*2 + 3*2 - 4 = 54 // 2 12 => 8 + 28 - 4 = 32 // 3 8 => 10 + 20 - ..
#include #include #include #include using namespace std; // 10^7 bool comp(const string p1, const string p2){ if(p1.size() < p2.size()){ return true; }else{ return false; } } bool solution(vector phone_book) { bool answer = true; sort(phone_book.begin(), phone_book.end()); int pattern_size; for(int i=0; i< phone_book.size() - 1; i++){ if(phone_book[i]

https://programmers.co.kr/learn/courses/30/lessons/42576 코딩테스트 연습 - 완주하지 못한 선수 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수 programmers.co.kr 난이도 해시(map) / 난이도 ⭐️⭐️(시간복잡도 때문에 +1) / 15분 문제풀이 선수의 수 10^5 완전탐색) 10^5 * 10 ^ 5 * 20 이중 포문O(n^2)으로 풀이할 경우 10^12로 100 억이다. 시간 초과에 걸린다. 보통 알고리즘 문제에서 1억(1초)을 마지노선이라고 생각하고 풀이해야한다. 해시) map 자료구조의 경우 ..