티스토리 뷰
문제_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 Queueq; 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]2589_보물섬 (0) | 2018.07.17 |
[BOJ]2644_촌수계산 (0) | 2018.07.16 |
댓글
공지사항
최근에 올라온 글
- Total
- 83,243
- Today
- 6
- Yesterday
- 88
링크
TAG
- BOJ
- C
- debug
- ConstraintLayout
- windows
- 퀵정렬
- OS
- Android
- 정렬 알고리즘
- 스프링
- 백준
- layout
- adapter
- 네트워크
- C++
- 알고리즘
- handshake
- HTTP
- RelativeLayout
- 안드로이드
- 이진탐색트리
- 스프링부트
- 백준알고리즘
- frameLayout
- 운영체제
- LinearLayout
- 윈도우
- WinDbg
- DATABASE
- listview