-
[C++] ์ผ์ฑ 1210. [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 2์ผ์ฐจ - Ladder1์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 28. 09:29728x90
(30๋ถ) ๋ฌธ์ ํธ๋๋ฐ๋ 10๋ถ๋ ์๊ฑธ๋ ธ๋๋ฐ ์ด๊ฑฐ ์ ๋ ฅ๋ฐ๋ ๋ฐฉ์์ด ํ์ ๋ฌธ์ ํ๊ณ ๋ฌ๋ผ์ ๊ณ์ ํ๋ ธ์์.(ํ ๋ฌธ์ ํ๋๋ง๋ค ํ ์คํธ ๋ฒํธ๋ฅผ ์ ๋ ฅ๋ฐ๊ฒ ํด๋...)
์์ด๋์ด๋ ๊ทธ๋ฅ ๋์์ ์์๋ถํฐ ๋ฐฑํธ๋ ํนํด์ ์ถ๋ฐ์ ์ฐพ๊ธฐ
#include<iostream> #include<vector> #include<string.h> using namespace std; int ladder[100][100]; int check[100][100]; int dir[3][2] = { {0, -1}, {0, 1}, {-1, 0} }; int start; int answer; // ๋์ฐฉ์ ์์๋ถํฐ ์ญ์ผ๋ก ์ถ๋ฐ ์ขํ๋ฅผ ์ฐพ์๊ฐ๋ค void backTracking(int x, int y) { if (x == 0) { answer = y; return; } for (int i = 0; i < 3; i++) { int new_x = x + dir[i][0]; int new_y = y + dir[i][1]; if (new_x < 0 || new_y < 0 || new_x >= 100 || new_y >= 100) continue; if (ladder[new_x][new_y] == 1 && check[new_x][new_y] == false) { check[new_x][new_y] = true; backTracking(new_x, new_y); return; } } } int main() { for (int t = 0; t < 10; t++) { int T; cin >> T; start = 0; answer = 0; memset(check, false, sizeof(check)); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { cin >> ladder[i][j]; if (i == 99 && ladder[i][j] == 2) { start = j; } } } backTracking(99, start); cout << "#" << T << " " << answer << endl; } return 0; }
728x90'์ฝ๋ฉํ ์คํธ > ์ฝ๋ฉํ ์คํธ ์ฐ์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++] ํ๋ก๊ทธ๋๋จธ์ค - ์ ์ ์ผ๊ฐํ (0) 2020.10.28 [C++] ์ผ์ฑ 1868. ํํํํ ์ง๋ขฐ์ฐพ๊ธฐ (0) 2020.10.28 [C++] ํ๋ก๊ทธ๋๋จธ์ค 2019 KAKAO BLIND RECRUITMENT ๋งค์นญ ์ ์ (0) 2020.10.28 [C++] ํ๋ก๊ทธ๋๋จธ์ค 2018 KAKAO BLIND RECRUITMENT [1์ฐจ] ์ ํ๋ฒ์ค (0) 2020.10.28 [C++] ํ๋ก๊ทธ๋๋จธ์ค 2020 KAKAO BLIND RECRUITMENT ๋ธ๋ก ์ด๋ํ๊ธฐ (0) 2020.10.28