Recent Posts
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 |
Tags
- vfr video
- PytestPluginManager
- Value too long for column
- terminal
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- 깡돼후
- preemption #
- tolerated
- Spring Batch
- kotlin
- JanusWebRTCServer
- 오블완
- PersistenceContext
- JanusWebRTCGateway
- k8s #kubernetes #쿠버네티스
- 달인막창
- 자원부족
- 겨울 부산
- 코루틴 컨텍스트
- table not found
- python
- pytest
- mp4fpsmod
- JanusGateway
- taint
- 티스토리챌린지
- JanusWebRTC
- 개성국밥
- 코루틴 빌더
- VARCHAR (1)
Archives
너와 나의 스토리
[BOJ] 13565 침투 본문
반응형
문제: https://www.acmicpc.net/problem/13565
문제 풀이:
맨 윗줄에서 0인 위치를 큐에 넣어놓고 시작해서
마지막 줄에 도달하는지만 보면 된다.
소스 코드:
#include <iostream>
#include <vector>
#include <string.h>
#include <queue>
#include <string>
using namespace std;
typedef pair<int, int> P;
int n, m;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1, -1, 0, 0 };
char arr[1002][1002];
bool visit[1002][1002];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
queue<P> q;
for (int i = 0; i < m; i++) {
if (arr[0][i] == '0') q.push({ 0,i });
}
while (!q.empty()) {
int curx = q.front().first;
int cury = q.front().second;
q.pop();
for (int i = 0; i < 4; i++) {
int xx = curx + dx[i];
int yy = cury + dy[i];
if (xx<0 || xx>=n || yy<0 || yy>=m || visit[xx][yy]||arr[xx][yy]=='1') continue;
if (xx == n - 1) {
cout << "YES\n";
return 0;
}
visit[xx][yy] = true;
q.push({ xx,yy });
}
}
cout<<"NO\n";
return 0;
}
반응형
'Algorithm > bfs, dfs' 카테고리의 다른 글
1949. [모의 SW 역량테스트] 등산로 조성 (0) | 2020.06.05 |
---|---|
[BOJ] 1938 통나무 옮기기 (0) | 2020.06.02 |
(BOJ) 3830 교수님은 기다리지 않는다 (0) | 2019.07.31 |
(BOJ) 12763 지각하면 안 돼 (0) | 2019.05.20 |
(BOJ) 16236 아기 상어 (0) | 2019.03.07 |
Comments