회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
[질문] p3055 질문있습니다.
3055번 - 탈출
jhl7193
2년 전
0
정답처리가 되지 않습니다.
package day1.P3055; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static final int[] NX = {-1, 1, 0, 0}; static final int[] NY = {0, 0, -1, 1}; static int R, C; static char[][] map; // y, x static int[][] dp; // y, x static Queue<Point> queue; public static void main(String[] args) throws FileNotFoundException { System.setIn(new FileInputStream("src/day1/P3055/input.txt")); int x = 0; int y = 0; for(int i = 0; i < 4; i++) { int tx = x + NX[i]; int ty = y + NY[i]; } Scanner sc = new Scanner(System.in); R = sc.nextInt(); C = sc.nextInt(); map = new char[R][C]; dp = new int[R][C]; queue = new LinkedList<>(); Point st = null; for(int r = 0; r < R; r++) { // 맵 만들기 String line = sc.next(); for(int c = 0; c < C; c++) { map[r][c] = line.charAt(c); if(map[r][c] == '*') { queue.add(new Point(r, c, '*')); }else if(map[r][c] == 'S') { st = new Point(r, c, 'S'); } } } queue.add(st); for (int r = 0; r < R; r++) { // 맵 보이게 만들기(디버깅용) System.out.println(Arrays.toString(map[r])); } System.out.println(); // 큐에 시작점을 넣음 (물 -> 고슴도치 순) boolean foundAnswer = false; while(!queue.isEmpty()) { // 1. 큐에서 꺼내옴 Point p = queue.poll(); // 2. 목적지인가? (고슴도치) // (고슴도치) map에서 목적지인지 확인 후 맞으면 탈출. if(p.type == 'D') { // 정답처리 System.out.println("Daddddddd"); System.out.println(dp[p.y][p.x]); foundAnswer = true; break; } //3. 연결된 곳을 순회 (좌우위아래) for (int i = 0; i < 4; i++) { int ty = p.y + NY[i]; int tx = p.y + NX[i]; //4. 갈 수 있는가? (공통) : 맵을 벗어나지 않고 if(0 <= ty && ty < R && 0 <= tx && tx < C) { // 부등호 쓸 땐 오름차순으로 if(p.type == 'S' || p.type == '.') { // 4. 갈 수 있는가? (고슴도치) : ., D, 방문하지 않은 곳 // (고슴도치) map에서 해당 위치 주변이 갈 수 있는지 확인. if((map[ty][tx] == '.' || map[ty][tx] == 'D') && dp[ty][tx] == 0){ // 5. 체크인 (고슴도치) // 갈 수 있다면, dp에서 방문한 적 있는지 확인. dp[ty][tx] = dp[p.y][p.x] + 1; // 6. 큐에 넣음 // 방문한 적 없다면, 해당 점을 큐에 넣기. queue.add(new Point(ty, tx, map[ty][tx])); } }else if(p.type == '*') { // 4. 갈 수 있는가? (물) : ., S, // (물) map에서 해당 물 위치 주변이 갈 수 있는지 확인. if(map[ty][tx] == '.' || map[ty][tx] == 'S') { // 5. 체크인 (물) // (물) 갈 수 있다면, map[ty][tx] = '*'; // 6. 큐에 넣음 // (물) 해당 점을 큐에 넣기. queue.add(new Point(ty, tx, '*')); } } } } } if(foundAnswer = false) { System.out.println("KAKTUS"); } } } class Point{ int x; int y; char type; public Point(int y, int x, char type) { this.y = y; this.x = x; this.type = type; } @Override public String toString() { return "[y=" + y + ", x=" + x + ", type=" + type + "]"; } }
댓글을 작성하려면
로그인
해야 합니다.
jhl7193 2년 전
정답처리가 되지 않습니다.