7576๋ฒ
-
[BaekJoon] 7576๋ฒ : ํ ๋งํSW Test/BaekJoon 2021. 4. 23. 01:38
์ด ๊ธ์ c++๋ก ํ์ด๋ฅผ ์์ฑํ์์ต๋๋ค. ๋ฌธ์ ์์ ํ์ด ์์์ ์ด ์ฌ๋ฌ ๊ฐ ์๋ BFS ๋ฌธ์ ๋ก BFS์ ๋ํ ํน์ง์ด ์ ๋๋ก ์์ด์ผ ํฉ๋๋ค. BFS๋ ํ์ ์ฒ์ ์์์ ์ ํ ๊ฐ ๋ด์๋ค๋ฉด, ์ด ๋ฌธ์ ๋ ์์์ ์ด ์ฌ๋ฌ ๊ฐ ์์ผ๋ฉด ์ฌ๋ฌ ๊ฐ๋ฅผ ํ๋์ ํ์ ๋ด๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. ํ์์ front์ ํด๋น๋๋ ์์์ ์์ BFS๋ฅผ ์งํํ๊ฒ ๋๊ณ ํน์ ์์ญ์ ์ฌ๋ฌ ์์์ ์ค ์ฒ์ ๋ฐฉ๋ฌธํ ๋๊ฐ ์ต๋จ ๊ฑฐ๋ฆฌ์ ๋๋ค. #include #include #include using namespace std; int n,m; int arr[1000][1000]; int dist[1000][1000]; int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}; bool inside(int y, int x){ return..