본문 바로가기

프로그래머스72

입국심사 C++ #include #include #include using namespace std; long long cal(long long mid,vector v) { long long num = 0; for (int i = 0; i < v.size(); i++) { num += (mid / v[i]); } return num; } long long solution(int n, vector times) { sort(times.begin(), times.end()); long long maxvalue = times[times.size() - 1]; long long answer = maxvalue * n; long long low = 0; long long high = answer; while (low = n) { .. 2019. 9. 28.
디스크 컨트롤러 #include #include #include using namespace std; bool cmp(pair a,pair b){ if (a.second == b.second) return a.first < b.first; else return a.second < b.second; } int solution(vector jobs) { int answer = 0; vector v; //start, worktime for (int i = 0; i < jobs.size(); i++) v.push_back(make_pair(jobs[i][0], jobs[i][1])); sort(v.begin(), v.end(), cmp); int time = 0, totaltime = 0; while (!v.size() == .. 2019. 9. 28.
섬 연결하기 #include #include #include #include using namespace std; int kruskal(int sizes, vector c) { vector v; sort(c.begin(), c.end()); int answer = 0; v.push_back(c[0][0]); while (v.size() < sizes) { int temp = 987654321; int index = 0; for (int i = 0; i < c.size(); i++) { if(count(v.begin(),v.end(),c[i][0]) == 1 && count(v.begin(),v.end(),c[i][1])==1) continue; else { if (count(v.begin(), v.end(), c[i.. 2019. 9. 25.
가장 먼 노드 #include #include #include #include using namespace std; const int MAX = 20001; int graph[MAX][MAX]; int answer = 0; int maxroute = 0; int bfs(int sizes) { int visited[MAX]; memset(visited, -1, sizeof(visited)); queue q; q.push(make_pair(1,0)); visited[1] = 1; while (!q.empty()) { answer = q.size(); int qsize = q.size(); while (qsize > 0) { int current = q.front().first; int count = q.front().se.. 2019. 9. 23.