yung0011   2년 전

out of bounds 오류나는 이유가 궁금합니다.

sh5017   2년 전

#include

using namespace std;

int n,k;

bool chk[100005];

queue > q;

void bfs(int start)

{

q.push({start,0});

chk[start]=true;

while(!q.empty()){

int nx=q.front().first;

int ny=q.front().second;

q.pop();

if(nx==k){

cout<=0&&chk[nx-1]==false){

chk[nx-1]=true;

q.push({nx-1,ny+1});

}

if(nx*2<=100000&&chk[nx*2]==false ){

chk[nx*2]=true;

q.push({nx*2,ny+1});

}

}

}

int main()

{

cin>>n>>k;

bfs(n);

return 0;

}

해결완 토요일에 설명 해 주겠음

ash9river   2년 전

21, 25, 29 줄의 and 연산자의 앞을 먼저 검사하게 되어서 out of bound가 발생합니다. 앞뒤를 바꿔주세요

댓글을 작성하려면 로그인해야 합니다.