Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- dfs
- 백준
- 삼성테스트
- 후쿠오카 4박 5일
- 완전탐색
- 일본 여행
- 다이나믹 프로그래밍
- 시뮬레이션
- brute force
- 후쿠오카 여행경비
- 완전 탐색
- 알고리즘
- 플로이드 와샬
- 삼성 SW 테스트
- 플로이드
- deque
- IOS
- 깊이 우선 탐색
- 하카타역
- 미로찾기
- 후쿠오카 캐널시티
- 너비 우선 탐색
- DP
- 후쿠오카
- BOJ
- 큐
- BFS
- 삼성시험
- 후쿠오카 요도바시 하카타
- queue
Archives
- Today
- Total
맛있는감귤
BOJ : 2178 미로찾기 본문
문제 : https://www.acmicpc.net/problem/2178
github : https://github.com/JEONG-SEUNGWOOK/BOJ/blob/master/2178.cpp
지극히 기본적인 BFS 문제
#include <iostream>
#include <queue>
using namespace std;
int N,M,ans=1;
queue<pair<int, int>> q;
char map[102][102];
bool isVisited[102][102];
int px[4]={1,-1,0,0};
int py[4]={0,0,1,-1};
int main(){
cin>>N>>M;
for(int i=0; i<N; i++)
cin>>map[i];
pair<int, int> s;
s.first=0, s.second=0;
isVisited[s.first][s.second]=true;
q.push(s);
while(!q.empty()){
int q_size = q.size();
while(q_size--){
pair<int, int> p;
p=q.front(); q.pop();
int x=p.first, y=p.second;
if(x==N-1 && y==M-1){
cout<<ans<<'\n';
return 0;
}
for(int i=0; i<4; i++){
if(x+px[i]>=0 && x+px[i]<N && y+py[i]>=0 && y+py[i]<M && !isVisited[x+px[i]][y+py[i]] && map[x+px[i]][y+py[i]]=='1'){
pair<int, int> temp;
temp.first = x+px[i]; temp.second = y+py[i];
q.push(temp);
isVisited[x+px[i]][y+py[i]]=true;;
}
}
}
ans++;
}
}'알고리즘 > 백준 알고리즘' 카테고리의 다른 글
| BOJ : 2292 벌집 (0) | 2017.01.19 |
|---|---|
| BOJ : 2206 벽 부수고 이동하기 (2) | 2017.01.19 |
| BOJ : 1966 프린터 큐 (2) | 2017.01.19 |
| BOJ : 1965 상자넣기 (0) | 2017.01.19 |
| BOJ : 1932 숫자삼각형 (0) | 2017.01.19 |