1697๋ฒ
-
[BaekJoon] 1697๋ฒ : ์จ๋ฐ๊ผญ์งSW Test/BaekJoon 2021. 4. 23. 01:52
์ด ๊ธ์ c++๋ก ํ์ด๋ฅผ ์์ฑํ์์ต๋๋ค. ๋ฌธ์ ํ์ด BFS๋ฅผ ํ์ฉํ๋ ๋ฌธ์ ์ธ๋ฐ 2์ฐจ์์ด ์๋ 1์ฐจ์์ผ๋ก ์์ฑํ๋ฉด ๋ฉ๋๋ค. #include #include using namespace std; int arr[100005]; int main(){ int n,k; cin>>n>>k; queue q; arr[n] = 1; q.push(n); while(!q.empty()){ int cur = q.front(); if(cur == k) break; q.pop(); if(cur>0 && arr[cur-1] == 0){ q.push(cur-1); arr[cur-1] = arr[cur]+1; } if(cur