공부/PS (백준)
-
[BOJ] 10866 덱 / C++공부/PS (백준) 2023. 1. 14. 16:51
https://www.acmicpc.net/problem/10866 10866번: 덱 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include #define DEQUE_SIZE10000 using namespace std; int N; // 명령의 수 (1 N; while (N--) { cin >> cmd; if (cmd == "push_front") { cin >> input_data; push_front(input_data); } else if (cmd == "push_back") { ..
-
[BOJ] 10845 큐 / C++공부/PS (백준) 2023. 1. 3. 20:12
https://www.acmicpc.net/problem/10845 10845번: 큐 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include #define MAX_CAPACITY10000 using namespace std; int N; // 명령의 수 (1 N; for (int i = 0; i > cmd; if (cmd == "push") { cin >> input_data; push(input_data); } else if (cmd == "pop") { ..
-
[BOJ] 1966 프린터 큐 / C++공부/PS (백준) 2022. 5. 18. 02:06
https://www.acmicpc.net/problem/1966 1966번: 프린터 큐 여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에 www.acmicpc.net #include #include using namespace std; int T, N, M; queue q; priority_queue pq; int sequence[110]; int cnt, answer; void init() { for (int i = 0; i = top_priority) { // 현재 문서가 나머지 문서들보다 우선순위가 높음 pq.pop(); sequence[cur_index] ..
-
[BOJ] 19238 스타트 택시 / C++공부/PS (백준) 2022. 4. 28. 23:49
https://www.acmicpc.net/problem/19238 19238번: 스타트 택시 첫 줄에 N, M, 그리고 초기 연료의 양이 주어진다. (2 ≤ N ≤ 20, 1 ≤ M ≤ N2, 1 ≤ 초기 연료 ≤ 500,000) 연료는 무한히 많이 담을 수 있기 때문에, 초기 연료의 양을 넘어서 충전될 수도 있다. 다 www.acmicpc.net #include #include #include #include #define MAX_N 21 #define MAX_M 401 using namespace std; int N, M, fuel; int MAP[MAX_N][MAX_N]; // -2: EMPTY, -1: int dist[MAX_N][MAX_N]; struct DRIVER { int r, c, t;..
-
[BOJ] 23288 주사위 굴리기 2공부/PS (백준) 2022. 4. 24. 21:07
https://www.acmicpc.net/problem/23288 23288번: 주사위 굴리기 2 크기가 N×M인 지도가 존재한다. 지도의 오른쪽은 동쪽, 위쪽은 북쪽이다. 지도의 좌표는 (r, c)로 나타내며, r는 북쪽으로부터 떨어진 칸의 개수, c는 서쪽으로부터 떨어진 칸의 개수이다. 가장 왼 www.acmicpc.net #include #include #define MAX21 using namespace std; int N, M, K; int BOARD[MAX][MAX]; int visited[MAX][MAX]; int dr[] = { -1,0,1,0 }; // 북동남서 int dc[] = { 0,1,0,-1 }; struct DICE { int r, c, bottom, top, front, b..
-
[BOJ] 16235 나무 재테크공부/PS (백준) 2022. 4. 19. 23:39
https://www.acmicpc.net/problem/16235 16235번: 나무 재테크 부동산 투자로 억대의 돈을 번 상도는 최근 N×N 크기의 땅을 구매했다. 상도는 손쉬운 땅 관리를 위해 땅을 1×1 크기의 칸으로 나누어 놓았다. 각각의 칸은 (r, c)로 나타내며, r은 가장 위에서부터 www.acmicpc.net 비교적 쉬운 문제였지만 (문제 설명대로 구현만 하면 됐기에) 시간 제한이 0.3초로 매우 짧았기때문에 처음 제출한 코드는 시간초과가 떴다. #include #include #include using namespace std; int N, M, K; int A[20][20]; // 로봇이 공급하는 양분 int nutrient[20][20]; struct TREE { int age, ..
-
[BOJ] 16236 아기 상어 / C++공부/PS (백준) 2022. 4. 16. 02:52
https://www.acmicpc.net/problem/16236 16236번: 아기 상어 N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. 공간은 1×1 크기의 정사각형 칸으로 나누어져 있다. 한 칸에는 물고기가 최대 1마리 존재한다. 아기 상어와 물고기는 모두 크기를 가 www.acmicpc.net #include #include #include #include using namespace std; int N, M; int MAP[30][30]; // 0: 빈칸, 1 ~ 6: 물고기의 크기, 9: 아기 상어의 위치 int dist[30][30]; int answer = 0; int dr[] = { -1,0,1,0 }; int dc[] = { 0,-1,0,1 }; struct SHARK..
-