문제 >> [SWEA] 7236 : 저수지의 물의 총 깊이 구하기
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Queue; import java.util.StringTokenizer; //SWEA :: 7236 저수지의 물의 총 깊이 구하기 //2019-03-07 public class Solution_7236_저수지의물의총깊이구하기_유승아 { static char[][] map; static int[][] count; static int n; public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(bf.readLine()); for (int tc = 1; tc <= T; tc++) { n = Integer.parseInt(bf.readLine()); map = new char[n][n]; count = new int[n][n]; for (int i = 0; i < n; i++) { StringTokenizer st = new StringTokenizer(bf.readLine(), " "); for (int j = 0; j < n; j++) { map[i][j] = st.nextToken().charAt(0); } } // input int ans = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (map[i][j] == 'G') continue; solve(i, j); ans = ans < count[i][j] ? count[i][j] : ans; } } System.out.println("#" + tc + " " + ans); } // end of tc }// end of main static int[] dx = { -1, 1, 0, 0, 1, 1, -1, -1 }; static int[] dy = { 0, 0, -1, 1, -1, 1, -1, 1 }; public static void solve(int y, int x) { int wCnt = 0; for (int i = 0; i < 8; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 || ny > n - 1 || nx < 0 || nx > n - 1) continue; if (map[ny][nx] == 'W') wCnt++; } if (wCnt == 0) count[y][x] = 1; else count[y][x] = wCnt; } } | cs |
'Algorithm Problem Solving' 카테고리의 다른 글
[SWEA] 1258 : [S/W 문제해결 응용] 7일차 - 행렬찾기 (0) | 2019.03.07 |
---|---|
[BOJ] 9663 : N-Queen (0) | 2019.03.07 |
[SWEA] 1861 : 정사각형 방 (0) | 2019.03.07 |
[BOJ] 8983 : 사냥꾼 / [JUNGOL] 2364 : 사냥꾼 (1) | 2019.03.07 |
[BOJ] 1012 : 유기농배추 (1) | 2019.02.17 |