[C++] 프로그래머스 프린터 스택/큐
·
Algorithm/Programmers
#include #include #include using namespace std; int solution(vector priorities, int location) { int answer = 0; priority_queue pq; queue q; for(int i = 0; i < priorities.size(); i++) { pq.push({priorities[i], i}); q.push({priorities[i], i}); } while(!pq.empty()) { int currVal = q.front().first; int currNum = q.front().second; //제일 값이 높은 것과 현재 것이 같다, 현재 번호와 location이랑 같아야 된다. if(pq.top().first ==..
[C++] 프로그래머스 기능개발 스택/큐
·
Algorithm/Programmers
#include #include #include using namespace std; vector solution(vector progresses, vector speeds) { vector answer; vector lists; for(int i = 0; i 0)//나눴는데 나머지가 있을 때 한번 더 진행해야 됨 lists.push_back(temp / speeds[i] + 1); else lists.push_back(temp / speeds[i]); } int curr = 0; for(int i = 0; i < lists.size(); i+..
[C++] 프로그래머스 주식가격 스택/큐
·
Algorithm/Programmers
#include #include using namespace std; vector solution(vector prices) { vector answer(prices.size(), 0); for(int i = 0; i prices[j + 1]) break; } } return answer; } 풀이 n번째 자리는 n+1부터 prices.size()만큼 비교를 한다. 자리수가 늘면서 비교할 횟수가 줄어든다. n번째가격이 n+m번째보다 클 때 비교를 멈춘다. break (횟수만큼의 초동안 가격이 떨러지지 않은 것)
[C++] 프로그래머스 다리를 지나는 트럭 스택/큐
·
Algorithm/Programmers
#include #include #include using namespace std; int solution(int bridge_length, int weight, vector truck_weights) { int answer = 0; int currNum = 0, endNum = 0, sum = 0; vector truck_times(truck_weights.size(), 0);//다 지난 트럭 판별 queue q;//현재 트럭 q.push(truck_weights[currNum]); sum = q.front();//무게합 while (!q.empty()) { int nextNum = currNum + 1; answer++; if (truck_times[endNum] == bridge_length) /..
[C++] 프로그래머스 가장 큰 정사각형 찾기 DP
·
Algorithm/Programmers
효율성테스트를 모두 실패한 모든 경우의 수를 찾기 더보기 #include #include using namespace std; vector result(1001, 0); void DFS(int x, int y, int size, vector &board); int solution(vector board) { int answer = 0; int num = 0; for(int i = board.size(); i >= 1; i--) //범위 { if(i > board.size() || i > board[0].size()) continue; DFS(0, 0, i, board); if(result[i] == i * i) { num = i; break; } } answer = result[num]; return a..
[C++] 프로그래머스 쿼드압축 후 개수 세기
·
Algorithm/Programmers
#include #include using namespace std; vector answer; void DFS(int x, int y, int size, vector &arr); vector solution(vector arr) { answer.push_back(0); answer.push_back(0); DFS(0, 0, arr.size(), arr); return answer; } void DFS(int x, int y, int size, vector &arr) { bool noCount = false; int val = arr[x][y]; for(int i = x; i < x + size; i++) { for(int j = y; j < y + size; j++) { if(arr[i][j] != v..