티스토리 뷰

coding test/백준

[BOJ]2589_보물섬

아풀 2018. 7. 17. 23:58

문제_2589

>>코드

import java.io.*;
import java.util.*;

public class boj_2589 {

	static int n, m, answer = 0;
	static char[][] map;
	static int[][] distance;
	static int[] dx = {1, -1, 0, 0};
	static int[] dy = {0, 0, 1, -1};
	
	static Queue q;
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		map = new char[n][m];
		distance = new int[n][m];

		q = new LinkedList();
		
		for(int i = 0 ; i < n ; i++) {
			map[i] = br.readLine().toCharArray();
			for(int j = 0 ; j < m ; j++) {
				if(map[i][j] == 'L') distance[i][j] = 1;	
				else	distance[i][j] = 0;
			}
			
		}
		for(int i = 0 ; i < n ; i++) {
			for(int j = 0 ; j < m ; j++) {
				if(distance[i][j] != 0) {
					int tempMax = bfs(i, j);
					answer = answer < tempMax ? tempMax : answer;
					initVisit();
				}
			}
		}
		System.out.println(answer);
	}
	
	static int bfs(int x, int y) {
		int max = 0;
		
		q.add(new position(x,y));
		
		while(!q.isEmpty()) {
			position temp = q.poll();
			for(int i = 0 ; i < 4 ; i++) {
				int tempX = temp.x+dx[i];				
				int tempY = temp.y+dy[i];
				
				if(0<=tempX && tempX=1) distance[i][j] = 1;
		}
	}

}

class position{
	int x, y;
	public position(int x, int y) {
		this.x = x;
		this.y = y;
	}
}


>>해설


'coding test > 백준' 카테고리의 다른 글

[BOJ]2579_계단 오르기  (0) 2018.07.18
[BOJ]2644_촌수계산  (0) 2018.07.16
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
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 31
글 보관함