회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
도저히 어디부분이 틀렸는지 모르겠습니다 ..ㅠㅠ
3055번 - 탈출
djsc6511
6년 전
0
봐주시면 감사하겠습니다..
#include<cstdio> #include<queue> #include<cstring> #include<iostream> using namespace std; int R, C; char map[55][55]; int temp[55][55]; int mx[4] = {0,0,1,-1}; int my[4] = {1,-1,0,0}; queue<pair<pair<int, int>, int>> poolq; queue < pair<pair<int, int>, int>> q; bool s_visited[55][55]; bool p_visited[55][55]; int INF = 91919; bool isMovePossible(int x, int y) { if (x<1 || x>C || y<1 || y>R || map[x][y] == '*' || map[x][y] == 'X') { return false; } return true; } bool isWaterMovePossible(int x, int y) { if (x<1 || x>C || y<1 || y>R || map[x][y] == 'X' || map[x][y] == 'D') { return false; } return true; } int main() { int result = -1; scanf("%d %d", &R, &C); memset(s_visited, false, sizeof(s_visited)); memset(p_visited, false, sizeof(p_visited)); memset(temp, INF, sizeof(temp)); memset(map, '-1', sizeof(map)); for (int i = 1; i <= R; i++) { for (int j = 1; j <= C; j++) { cin >> map[i][j]; if (map[i][j] == '*') { poolq.push(make_pair(make_pair(i, j), 0)); p_visited[i][j] = true; } if (map[i][j] == 'S') { q.push(make_pair(make_pair(i, j), 0)); s_visited[i][j] = true; } } } while (!poolq.empty()) { int poolx = poolq.front().first.first; int pooly = poolq.front().first.second; int pdistance = poolq.front().second; poolq.pop(); for (int i = 0; i < 4; i++) { int npoolx = poolx + mx[i]; int npooly = pooly + my[i]; if (isWaterMovePossible(npoolx, npooly) && map[npoolx][npooly] == '.' && !p_visited[npoolx][npooly] && temp[npoolx][npooly] > pdistance) { p_visited[npoolx][npooly] = true; temp[npoolx][npooly] = pdistance + 1; poolq.push(make_pair(make_pair(npoolx, npooly), pdistance + 1)); } } } while (!q.empty()) { int x = q.front().first.first; int y = q.front().first.second; int distance = q.front().second; //printf("x: %d y:%d distance:%d\n", x, y, distance); q.pop(); for (int i = 0; i < 4; i++) { int nx = x + mx[i]; int ny = y + my[i]; if (isMovePossible(nx, ny) && !s_visited[nx][ny] && (map[nx][ny] == 'D' || temp[nx][ny] > distance + 1)) { s_visited[nx][ny] = true; if (map[nx][ny] == 'D') { result = distance + 1; //printf("result = %d\n", result); break; } q.push(make_pair(make_pair(nx, ny), distance + 1)); } } } if (result == -1) printf("KAKTUS"); else printf("%d", result); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
djsc6511 6년 전
봐주시면 감사하겠습니다..