목록Algorithm/ES (완전탐색) (23)
:: ADVANCE ::
BAEKJOON ONLINE JUDGE 2178 미로 탐색 https://www.acmicpc.net/problem/2178 35분 어딘가 자꾸 틀려서 시간을 많이 소모함 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include typedef struct tagPoint { int x, y; }Point; int height, width; int map[101][101]; int bfs() { int i; int dy[4] = { 0, 0, -1, 1 }; i..
BAEKJOON ONLINE JUDGE 1182 부분집합의 합 https://www.acmicpc.net/problem/1182 주의정수 S가 0인 경우 공집합도 개수를 세도록 구현했다면 이를 빼주어야 한다.13분 1. DFS 1234567891011121314151617181920212223242526272829303132333435#include int n, s;int number[21];int count; void dfs(int idx, int sum){ if (idx >= n) { if (sum == s) count++; return; } dfs(idx + 1, sum); dfs(idx + 1, sum + number[idx]);} int main(){ int i; scanf("%d %d", &n..
BAEKJOON ONLINE JUDGE 1012 유기농 배추 https://www.acmicpc.net/problem/1012 labeling 문제15분 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#include int width, height;int map[51][51];int label[51][51]; void init(){ int i, j; for (i = 0; i
BAEKJOON ONLINE JUDGE 한국정보올림피아드 2000 2636 치즈 https://www.acmicpc.net/problem/2636 공기와의 접촉면 -> 한 시간 후 녹아 없어짐 -> 공기로 됨구멍 -> 공기처럼 치즈를 녹이진 않음. but 공기와 만나면 공기가 됨 1. input 받고, 구멍과 공기를 구분 -> labeling2_1. 공기와 닿은 면적 공기로 만들기 -> 반복문2_2. 공기와 구멍이 만나면 구멍도 공기로 만들기 -> dfs 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475..
BAEKJOON ONLINE JUDGE 2146 다리 만들기 https://www.acmicpc.net/problem/2146 풀이 1. DFS & BFS DFS 또는 BFS로 섬들을 잇고 BFS로 섬 주위로 다리를 지어 섬들을 연결하면 된다.섬마다 한칸씩 다리를 지어 만나도록 연결하였다. 0ms 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113..
BAEKJOON ONLINE JUDGE 1261 알고스팟 https://www.acmicpc.net/problem/1261 입력이 0일 경우에는 벽을 부술 필요 없이 바로 이동하면 되므로 DFS이건 BFS이건 탐색을 하면 된다.입력이 1일 경우에는 벽을 부수어야 하기 때문에 바로 이동을 하면 안된다. 단계별로 나누면1. 바로 갈 수 있는 곳은 바로간다.2. 더이상 갈 수 없으면 벽을 부순다.3. 벽을 부순 후 갈 수 있는만큼 이동한다.이걸 반복해서 마지막 장소에 도착하면 된다. 풀이 1. 입력이 0인 곳은 DFS, 그 중 벽을 만나면 queue에 저장DFS가 끝난 후 queue에 저장된 벽을 부순 후 다시 DFS를 타서 바로 갈 수 있는 곳은 이동이동하면서 다시 벽을 만나면 queue에 저장 123456..
BAEKJOON ONLINE JUDGE 2580 스도쿠 https://www.acmicpc.net/problem/2580 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100#include typedef struct tagpoint { int x; int y;}POINT; POINT p[90];int size;int nemo[9][10];int horizon[9][10];int vertical[9][10];int ma..
BAEKJOON ONLINE JUDGE 2823번 유턴 싫어 https://www.acmicpc.net/problem/2823 123456789101112131415161718192021222324252627282930313233343536#include int main(){ int i, j; char map[11][11]; int r, c; int cnt; scanf("%d %d\n", &r, &c); for (i = 0; i
BAEKJOON ONLINE JUDGE 2816번 디지털 티비 https://www.acmicpc.net/problem/2816 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include #include #include using namespace std; int main(){ int n; int i = 0, j; string ch; string temp; vector channel; string KBS[2] = { "KBS1", "KBS2" }; scanf("%d", &n); while (n--) { cin >> ch; channel.push_back(ch); } for (..
dovelet 14 단계 BFS 도망간 소를 잡아라 / catch_cow http://59.23.113.171/30stair/catch_cow/catch_cow.php?pname=catch_cow 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include int queue[1000000][2];int visit[1000010]; int main(void){ int start, end; int N, K; scanf("%d%d", &N, &K); if (N == K) { printf("0\n"); return 0; } else if (N > K) { printf("%d\n", N..