본문 바로가기

백준 문제풀이

(79)
Insertion Sorting #include void InsertionSort(std::vector & arr) { for (int i = 1; i = 0 && tmp < arr[idx]) { arr[idx + 1] = arr[idx]; --idx; } arr[idx + 1] = tmp; } } void printArr(std::vector arr){ for (auto ele : arr) { std::cout
[C++] 백준 문제풀이 (Simulation) 20006번 랭킹전 대기열 https://www.acmicpc.net/problem/20006 20006번: 랭킹전 대기열 모든 생성된 방에 대해서 게임의 시작 유무와 방에 들어있는 플레이어들의 레벨과 아이디를 출력한다. 시작 유무와 플레이어의 정보들은 줄 바꿈으로 구분되며 레벨과 아이디는 한 줄에서 공백 www.acmicpc.net #include int p, m, l; std::string n; std::vector rooms[300]; std::pair room_min_max[300]; int room_count = 0; bool check; int main(int argc, char** argv){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cin..
[C++] 백준 문제풀이 (Simulation) 11559번 Puyo Puyo https://www.acmicpc.net/problem/11559 11559번: Puyo Puyo 총 12개의 줄에 필드의 정보가 주어지며, 각 줄에는 6개의 문자가 있다. 이때 .은 빈공간이고 .이 아닌것은 각각의 색깔의 뿌요를 나타낸다. R은 빨강, G는 초록, B는 파랑, P는 보라, Y는 노랑이다. www.acmicpc.net #include const int h = 12; const int w = 6; std::string field[h]; bool visit[h][w]; int ans; const int dy[] = {-1, 1, 0, 0}; const int dx[] = {0, 0, -1, 1}; std::vector save; bool boom; void bfs(int i, int j, ..
[C++] 백준 문제풀이 (Simulation) 18808번 스티커 붙이기 https://www.acmicpc.net/problem/18808 18808번: 스티커 붙이기 혜윤이는 최근에 다양한 대회를 참여하면서 노트북에 붙일 수 있는 스티커들을 많이 받았다. 스티커는 아래와 같이 사각 모눈종이 위에 인쇄되어 있으며, 스티커의 각 칸은 상하좌우로 모두 연 www.acmicpc.net #include int n, m, k; int r[100][4]; // r[i][0] i번째 기본스티커, 180도 회전 행 r[i][1] i 번째 스티커 90도, 270도 행 int c[100][4]; // c[i][0] i번째 기본스티커, 180도 회전 열 c[i][1] i 번째 스티커 90도, 270도 열 int stickers[100][4][10][10]; int note[40][40]; in..
[C++] 백준 문제풀이 (Back Tracking) 1405번 미친 로봇 https://www.acmicpc.net/problem/1405 1405번: 미친 로봇 첫째 줄에 N, 동쪽으로 이동할 확률, 서쪽으로 이동할 확률, 남쪽으로 이동할 확률, 북쪽으로 이동할 확률이 주어진다. N은 14보다 작거나 같은 자연수이고, 모든 확률은 100보다 작거나 같은 자 www.acmicpc.net #include bool map[29][29]; int n; int p[4]; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; double part, total; void dfs(int y, int x, int d, double sum) { map[y][x] = true; if (d == n){ part += sum; return; } for (in..
[C++] 백준 문제풀이 (Greedy) 15903번 카드 합체 놀이 https://www.acmicpc.net/problem/15903 15903번: 카드 합체 놀이 첫 번째 줄에 카드의 개수를 나타내는 수 n(2 ≤ n ≤ 1,000)과 카드 합체를 몇 번 하는지를 나타내는 수 m(0 ≤ m ≤ 15×n)이 주어진다. 두 번째 줄에 맨 처음 카드의 상태를 나타내는 n개의 자연수 a1, www.acmicpc.net #include //[C++] 백준 문제풀이 (Greedy) int main(int argc, char *argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::priority_queue pq; int n, m; std::cin >> n >> m; int a; for (int i..
[C++] 백준 문제풀이 (Greedy) 11000번 강의실 배정 https://www.acmicpc.net/problem/11000 11000번: 강의실 배정 첫 번째 줄에 N이 주어진다. (1 ≤ N ≤ 200,000) 이후 N개의 줄에 Si, Ti가 주어진다. (0 ≤ Si < Ti ≤ 109) www.acmicpc.net #include // [C++] 백준 문제풀이 (Greedy) int n; std::vector classes; std::priority_queue pq; bool cmp(std::pair lhs, std::pair rhs){ if (lhs.first == rhs.first) return lhs.second < rhs.second; return lhs.first < rhs.first; } int main(int argc, char *argv[]..
[C++] 백준 문제풀이 (Greedy) 11501번 주식 https://www.acmicpc.net/problem/11501 11501번: 주식 입력의 첫 줄에는 테스트케이스 수를 나타내는 자연수 T가 주어진다. 각 테스트케이스 별로 첫 줄에는 날의 수를 나타내는 자연수 N(2 ≤ N ≤ 1,000,000)이 주어지고, 둘째 줄에는 날 별 주가를 나타 www.acmicpc.net #include // [C++] 백준 문제풀이 (Greedy) int t, n; int stocks[1000000]; int main(int argc, char *argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> t; while(t--) { std::cin >> n; long long ..