(C++) - 백준(BOJ)코딩 7576번 : 토마토 답
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#include #include using namespace std;int N, M, h, w,d[1000][1000], a[1000][1000], dh[] = { 0,0,-1,1 }, dw[] = { -1,1,0,0 }, ans,cnt;queue q;int main() { cin >> M >> N; for (int i = 0; i a[i][j]; d[i][j] = -1; if (a[i][j] == 1)//이미 익어있는 상태라면 큐에 넣어줌 -> 먼저 들어가 있는(익어있는) 큐(토마토)의 요소 부터 탐색하기 위함 { q.push(make..
(C++) - 백준(BOJ) 2178번 : 미로 찾기 답
https://www.acmicpc.net/problem/2178 간단한 BFS문제였습니다. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include #include #include using namespace std;int h, w, N, M,cnt, d[101][101], a[101][101],c[101][101], dh[] = { 0,0,-1,1 }, dw[] = { -1,1,0,0};void BFS(int h, int w){ queue q; q.push(make_pair(h, w)); //체크 d[h][w] = ++cnt; c[h][w] = 1; while (!q.empty()) { ..
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 4963번:섬의 개수(DFS) 답
1234567891011121314151617181920212223242526272829303132333435#include #include using namespace std;int h,w,a[51][51], d[51][51], cnt, dh[] = { 0,0,-1,1,1,1,-1,-1 }, dw[] = { -1,1,0,0,-1,1,-1,1 };void DFS(int H, int W, int cnt){ d[H][W] = cnt; for (int i = 0; i
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 4963번:섬의 개수(BFS) 답
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#include #include #include using namespace std;int d[51][51],a[51][51], cnt, dx[] = {0,0,-1,1,1,1,-1,-1}, dy[] = {-1,1,0,0,1,-1,1,-1 },w,h;void BFS(int x, int y, int cnt){ queue q; q.push(make_pair(x, y)); d[x][y] = cnt; while (!q.empty()) { x = q.front().first; y = q.front().second; q.pop(); for (int i = 0; i