반응형 코딩/문제풀이-백준35 백준 1916 - 최소비용 구하기 (C++) 문제 해결 방법 : 다익스트라 알고리즘을 사용. Astar의 전 단계 느낌의 알고리즘이라 쉽게 풀었다. 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 #include #include #include #include using namespace std; #define INT_MAX 2147483647 struct Route { Route(int a, int b): destination(a), cost(b) {} int des.. 2021. 5. 7. 백준 2805 - 나무 자르기 (C++) 문제 해결 방법 : 정렬 후, 이분 탐색을 활용하여서 탐색한다. 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //입력 vector TreeVec; long long TreeNum, TreeLength, LengthMax=0; cin >> TreeNum >> TreeLengt.. 2021. 5. 7. 백준 16234번 - 인구 이동 (C++) 문제 해결 방법 : 시작점부터 배열을 BFS방식으로 하나의 국가로 묶어서 인구 이동을 처리하였다. -> 이후 반복. 아쉬운 점 : 시간이 너무 많이 걸렸고, 코드도 비 효율적이며, 가독성마저 구리다. 상위권은 한자릿수던데 난 700ms... 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90.. 2021. 5. 7. 백준 1735번 - 분수 합 (C++) 문제 문제 풀이 두 분수를 더하고, 최소공약수를 구해주면 된다. 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include using namespace std; int gcd(int a, int b) { int r; while (b != 0) { r = a % b; a = b; b = r; } return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, s, d, f; cin >> a >> s >> d >> f; a *= f; d *= s; a += d; s *= f; int GCD = .. 2021. 5. 5. 이전 1 ··· 4 5 6 7 8 9 다음 반응형