공부/programmers 문제
-
Programmers [기지국 설치]공부/programmers 문제 2019. 10. 1. 11:32
#include #include using namespace std; int solution(int n, vector stations, int w) { int head = 0, tail = 0, answer = 0; int cur, val; for (int i = 0; i =head && tail!=0) { val = tail - head + 1; if ((val % (2 * w + 1)) == 0) val = (val / (2 * w + 1)); else val = (val / (2 * w + 1)) + 1; answer += val; } head = cur + w + 1..
-
Programmers [섬 연결하기] - 분명 Prim's algorithm...? 을 짰는데..공부/programmers 문제 2019. 10. 1. 11:25
#include #include #include #include #include using namespace std; int arr[100][100]; int visit[100]; priority_queue q; int solution(int n, vector costs) { int answer = 0, cur, s = costs.size(); bool flag = false, skip = false; pair temp; if (n == 1){return 0;} for (int i = 0; i < s; i++) { arr[costs[i][0]][costs[i][1]] = costs[i][2]; arr[costs[i][1]][costs[i][0]] = costs[i][2]; } cur = costs[0][..