sonia1317   3년 전

arr[x좌표][y좌표][방향]에  갈 수 있으면 0 없으면 1 저장했구요
q엔 x,y,방향 저장해서 bfs 했어용

while문으로 q에서 하나씩 꺼내면서 동서남북 방향(b=1:동  b=2:서  b=3:남  b=4:북)으로 보는데
현재 향해있는 방향이랑 b랑 일치 : 앞으로 1칸, 2칸, 3칸 전진하여 q에 넣음 (arr[][][] == 0 인경우만)
현재 향해있는 방향이랑 b랑 안일치 : 회전 ( 90도 회전하는 경우만 q에 넣어줌!)

회전할 때, if ((k.o == 1 && b == 2) || (k.o == 2 && b == 1) || (k.o == 3 && b == 4) || (k.o == 4 && b == 3)) continue; 이 구문으로 현재 바라보고 있는 방향(k.o)이 '동'일때 '서'로 향하는 경우랑, 서->동, 남->북, 북->남  인 경우 (180도 회전하는 경우)는 제외시켜줬는데용........ 여기가 틀린건가요..??

계속 30%도 되기 전에 틀렸습니다 뜹니다 ㅠㅠ 

어디가 틀렸는지 알려주시면 정말 감사하겠습니다!!

bupjae   3년 전

180도 회전이 필요한 경우를 충분히 고려하지 않은 것 같습니다.


다음 데이터의 답은 2입니다.

esspks21   3년 전

bupjae님이 제시해주신 데이터는 동쪽방향(1)으로 시작해서 남쪽방향(3)으로 끝나는 오른쪽 90도 회전으로 답이 1이 맞습니다.

물론

1 1

0

1 1 1

1 1 2

로 바꾸어서 질문자님의 코드를 돌리면 제대로 된 답 2가 나옵니다.

sonia1317   3년 전

위에 두분 모두 감사드려요 ㅎㅎㅎ

드디어 해결했습니다!!!!!

원래 코드에선 arr[x][y][방향] 배열에 갈 수 없는 곳은 1, 갈 수 있는 곳은 0을 넣었었는데요

arr[x][y]랑 visit[x][y][방향]을 분리해줘야 했어요....

이유는, 원래 코드에서 Go k 명령으로 방문할 때 arr[][][] == 1 이면 더이상 그 다음칸에 방문 못하도록했었는데, 이렇게 하면  벽이 아니더라도 이전에 회전으로 방문한 곳이면 멈추더라고요 ㅠㅠ

예를 들어서

0 0 0

0 0 0

0 0 0

이고 ( 1 1 3 ) 에서 ( 3 1 3) 으로 go k 명령어 사용할 때, 만약에 ( 2 1 3 )이 방문되어있는 상태면 멈추도록해서 그랬어요....

위 그림에서 (2, 1)이  벽이 아니라면, ( 2 1 3 )이 방문되어 있는 곳이더라도 그 다음칸 ( 3 1 3 )을 확인해줘야합니당~~~


arr[][]랑 visit[][]을 분리하여, go k 명령어에서 arr[][] == 1인 경우(벽인 경우) 에만 더이상 전진을 하지 않고 멈추도록 했고

1이 아니라면 visit[][][]으로 방문 안된 곳인지 확인해서 큐에 넣은 후, 멈추지 않고 그 다음칸도 확인하도록 수정해서 맞았습니다.



42 79
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0
0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 0 1 0 0
1 0 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0
1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0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