본문 바로가기

알고리즘/완전 탐색13

백준 7562번 : 나이트의 이동 문제 링크 : www.acmicpc.net/problem/7562 내 풀이(2021.3.1.) : BFS #include #include using namespace std; typedef pair pr; int map[300][300] = { 0, }; int visit[300][300] = { 0, }; int dy[] = {-1,-2,-2,-1,1,2,2,1}; int dx[] = { -2,-1,1,2, -2,-1,1,2, }; void init() { for (int i = 0; i < 300; i++) { for (int j = 0; j < 300; j++) { map[i][j] = 0; visit[i][j] = 0; } } } int main() { ios_base::sync_with_stdi.. 2021. 3. 1.
백준 16236번 : 아기 상어 문제 링크 : www.acmicpc.net/problem/16236 풀이에 참고한 링크 : www.acmicpc.net/board/view/35923 내 풀이(2021.1.29.) : #include #include using namespace std; typedef pair int_pair; int map[20][20]; int visit[20][20]; int N; int dy[] = { -1,0,1,0 }; int dx[] = { 0,-1,0,1 }; int total_time = 0; int cy, cx; struct comp { bool operator()(int_pair& a, int_pair& b) { if (a.first == b.first) return a.second > b.second.. 2021. 1. 29.
백준 9019번 : DSLR 문제 링크 : www.acmicpc.net/problem/9019 풀이에 참고한 링크 : www.acmicpc.net/board/view/28910 www.acmicpc.net/board/view/23149 내 풀이1(2021.1.27.) : BFS #include #include #include #include using namespace std; string to4(string str) { string prefix = ""; for (int i = 0; i < 4 - str.size(); i++) prefix += "0"; return prefix + str; } string DSLR(char cal, string str) { switch (cal) { case 'D': return to4(to_st.. 2021. 1. 27.
백준 7569번 : 토마토 문제 링크 : www.acmicpc.net/problem/7569 내 풀이(2021.1.25.) : BFS #include #include #include using namespace std; int N, M, H; int map[100][100][100]; // [z][y][x] = [H][N][M] int dz[6] = {1,-1,0,0,0,0}; int dy[6] = {0,0,-1,1,0,0}; int dx[6] = {0,0,0,0,-1,1}; queue q; bool check() { for (int i = 0; i < H; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < M; k++) { if (map[i][j][k] == 0) return .. 2021. 1. 25.