본문 바로가기
반응형
[PCCP] Lv2: 롤케이크 자르기(132265) 해설 문제- 문제 링크: 롤케이크 자르기 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: topping의 길이- topping의 길이만큼 반복문을 수행하므로 시간 복잡도는 O(N)- 내부 연산들은 모두 O(1)- 최종 시간 복잡도: O(N)더보기#include #include #include #include using namespace std;int solution(vector topping) { int answer = 0; // 남아있는 각 토핑의 개수 unordered_map topping_cnt; // 절반에 속한 토핑의 종류 unordered_set half_topping; // 카운터에 각 토핑의 개수를 저장.. 2024. 12. 25.
[PCCP] Lv2: 이진 변환 반복하기(70129) 해설 문제- 문제 링크: 이진 변환 반복하기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: 주어진 수- while 문에서 N이 1이 될 때까지 2로 나누므로 시간 복잡도는 O(logN)- count() 호출시 필요한 시간 복잡도는 O(N)- 최종 시간 복잡도: O(NlogN)더보기#include #include #include #include using namespace std;vector solution(string s) { int transforms = 0; int removedZeros = 0; // s가 "1"이 될 때까지 계속 반복 .. 2024. 12. 25.
[PCCP] Lv2: 양궁대회(92342) 해설 문제- 문제 링크: 양궁대회 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- 0-10점 각 과녁에 화살을 맞힌다/못 맞힌다 두 상태가 있으므로 시간복잡도는 O(2^11)더보기#include using namespace std;vector answer;vector ryan(11, 0);int maxScore = -1;// 어피치와 라이언의 점수 차이 계산int calcScoreDiff(const vector &apeach) { int scoreApeach = 0; int scoreLion = 0; for (int i = 0; i = ryan[i]) scoreApeach += 10 - i;.. 2024. 12. 25.
[PCCP] Lv2: N-Queen(12952) 해설 문제- 문제 링크: N-Queen 해설- 자료구조: - 시간복잡도:  코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: 퀸의 개수- 각 행에 퀸을 놓는 방법의 경우의 수는 N!이고, 시간 복잡도는 O(N!)더보기#include #include using namespace std;// 현재 행에 이미 다른 퀸이 있는지 확인bool isSameRow(int placedRow, int currentRow) { return placedRow == currentRow; }// 대각선에 다른 퀸이 있는지 확인bool isDiagonalAttack(int placedCol, int placedRow, int currentCol, int .. 2024. 12. 25.
[PCCP] Lv2: 피로도(87946) 해설 문제- 문제 링크: 피로도 코드(C언어)solution 1)더보기#includesolution 2)더보기#include (C++)solution 1)- N: 던전의 개수- 최악의 경우 모든 경로를 탐색하므로 경우의 수는 N*(N-1)*...*1이므로 시간복잡도는 O(N!)더보기#include #include using namespace std;int maxDepth = 0;bool visited[8] = {false,};// 던전의 최대 방문수를 갱신하면서 깊이 우선 탐색으로 던전 탐색void exploreDungeon(int depth, int power, vector> &dungeons) { if (maxDepth power) continue; /.. 2024. 12. 25.
[PCCP] Lv2: 전력망을 둘로 나누기(86971) 해설 문제- 문제 링크: 전력망을 둘로 나누기 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C#)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (Java)solution 1)- N은 송전탑의 개수- 깊이우선탐색을 이용하여 한 번에 탑을 구하므로 시간 복잡도는 O(N)- N이 100이하이므로 O(N^2)으로 풀이 가능더보기import ja.. 2024. 12. 25.
[PCCP] Lv2: 배달(12978) 해설 문제- 문제 링크: 배달 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (C#)solution 1)더보기#includesolution 2)더보기#includesolution 3)더보기#include (Java)solution 1)- E: road의 길이- 그래프를 추가할 때 시간 복잡도는 O(E)- 다익스트라 알고리즘은 우선순위 큐를 활용했으므로 O((N + E)logN)- 마지막 결과 리스트를 순회하며 K.. 2024. 12. 25.
[PCCP] Lv2: 게임 맵 최단거리(1844) 해설 문제- 문제 링크: 게임 맵 최단거리 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N*N: 배열의 크기- 너비우선탐색은 모든 노드를 한 번씩 확인하므로 최종 시간 복잡도는 O(N*M)더보기#include #include using namespace std;const int MAX_SIZE = 100;const int dx[4] = {-1, 0, 1, 0};const int dy[4] = {0, 1, 0, -1};int check[MAX_SIZE][MAX_SIZE];// 좌표 정보 및 좌표 연산을 하기.. 2024. 12. 25.
[PCCP] Lv2: 미로 탈출(159993) 해설 문제- 문제 링크: 미로 탈출 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: 지도 한 변의 길이- isWithinRange()의 시간복잡도: O(1)- findStartPoint()의 시간복잡도: O(N^2)- 이동과정은 최악의 경우 지도의 크기가 N*N, 네 방향으로 이동하므로 시간 복잡도는 O(4*(N^2))- 최종 시간 복잡도: O(N^2)더보기#include #include #include using namespace std;// 현재 좌표, 해당 좌표까지 이동 횟수struct Point .. 2024. 12. 25.
[PCCP] Lv2: 예상 대진표(12985) 해설 문제- 문제 링크: 예상 대진표 해설- 자료구조: - 시간복잡도:  (풀이과정)1) 2) 3) 4)  코드(C언어)solution 1)더보기solution 1#includesolution 2)더보기#includesolution 3)더보기#include (C++)solution 1)- N: 참가한 인원 수- 같은 번호가 될 때까지 계속해서 2로 나누는 연산: O(logN)더보기#include using namespace std;int solution(int n, int a, int b){ int answer = 0; do { a = (a + 1) / 2; b = (b + 1) / 2; ++answer; } while (a != b); return .. 2024. 12. 24.
반응형