[C++] 프로그래머스 카펫 완전탐색
·
Algorithm/Programmers
#include #include using namespace std; vector solution(int brown, int yellow) { vector answer; for(int i = 6; i = 1이고 2 * 1이 yellow와 같기 때문에 답이므로 answer에 x길이 (i / 2)와 y의 길이 (j / 2 + 2)를 넣어주면 정답이 나온다.
[C++] 프로그래머스 소수찾기 완전탐색
·
Algorithm/Programmers
#include #include #include using namespace std; int solution(string numbers) { int answer = 0; sort(numbers.rbegin(), numbers.rend()); int num = stoi(numbers); vector visited(num + 1, false); for(int i = 2; i
[C++] 프로그래머스 모의고사 완전탐색
·
Algorithm/Programmers
#include #include #include using namespace std; vector solution(vector answers) { vector answer; int counts[3]{0}; int tester1[5] = {1,2,3,4,5}; int tester2[8] = {2,1,2,3,2,4,2,5}; int tester3[10] = {3,3,1,1,2,2,4,4,5,5}; for(int j = 0; j < answers.size(); j++) { if(tester1[j % 5] == answers[j]) counts[0]++; if(tester2[j % 8] == answers[j]) counts[1]++; if(tester3[j % 10] == answers[j]) counts[2..
[C++] 프로그래머스 네트워크 DFS, BFS
·
Algorithm/Programmers
#include #include #include using namespace std; int visited[200]; void DFS(int curr, int n, vector computers); int solution(int n, vector computers) { int answer = 0; for(int i = 0; i < n; i++) { if (visited[i] == false) { DFS(i, n, computers); answer++; } } return answer; } void DFS(int curr, int n, vector computers) { queue q; q.push(curr); visited[curr] = true; while(!q.empty()) { int currNod..
[C++] 백준 10282 해킹 다익스트라알고리즘
·
Algorithm/Baekjoon
#include #include #include #include using namespace std; #define INF 987654321 const int maxCom = 10001; int n, d, c, test; void dijkstra(int start, int end, vector *com); int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> test; for (int i = 0; i > n >> d >> c; vector computer[maxCom]; for (int j = 0; j < d; j++)//의존되고 있는 것을 기준으로 push_back한다. { in..
다익스트라 알고리즘
·
Algorithm/Memo
1. 시작한 곳을 dist를 0으로 잡고 시작. 거리비용들의초기값은 INF로 한다. 2. 우선순위 큐를 사용하여 거리비용이 낮은 순으로 탐색 3. 조건은 현재노드에 있는 다음 노드들, 즉 붙어 있는 노드들을 탐색 4. 그 노드들에 대해서 dist보다 현재 노드와 붙어 있는 노드로 가는 거리비용을 합한 값이 작을 경우 값을 적는다. 5. 다음 우선순위 큐가 없을 때까지 반복하면 모든 곳을 최소비용으로 순회하게 된다. 6. 시작지점부터 도착지점까지 최소 비용을 구하는 문제에 사용. 도움 사이트 : yabmoons.tistory.com/364 [ 다익스트라 알고리즘 ] 개념과 구현방법 (C++) 그래프 알고리즘에서 '최소 비용'을 구해야 하는 경우 사용할 수 있는 대표적인 알고리즘으로는 '다익스트라 알고리즘'..