본문 바로가기

■ 알고리즘 문제 풀이/SWEA

[SWEA-D3] 1206. View

▶문제설명

[SWEA] 1206. View

https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV134DPqAA8CFAYh&categoryId=AV134DPqAA8CFAYh&categoryType=CODE



▶Solution


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
import java.util.*;
 
class Solution{
    
    public static void main(String args[]) throws Exception{
        int T = 1;
        int W = 0;
        int H = 0;
        int[] HArr = new int[1000];
        Scanner sc = new Scanner(System.in);
        while(T<=10)
        {
            int[][] arr = new int [257][1000];
            W = sc.nextInt();
            for(int col = 0 ; col<W ; col++){
                H = sc.nextInt();
                HArr[col]=H;
                for(int row = 0 ; row<H ; row++){
                    arr[row][col] = 1;
                }
            }
            int answer = 0;
            for(int col = 2 ; col<W-2 ; col++){
                for(int row = 0 ; row<HArr[col] ; row++){
                    boolean checkview = checkView(arr ,row, col);
                    if(checkview){
                        answer++;
                    }
                }
            }
            //System.out.println(Arrays.deepToString(arr));
             System.out.printf("#%d %d\n",T, answer);
            T++;
        }
    }
    public static boolean checkView(int[][] arr, int row, int col){
        if(arr[row][col+1== 0 && arr[row][col+2== 0
           && arr[row][col-1== 0 && arr[row][col-2== 0){
            return true;
        }
        return false;
    }
 
}
cs



'■ 알고리즘 문제 풀이 > SWEA' 카테고리의 다른 글

[SWEA-D4] 1211. Ladder2  (0) 2019.02.20
[SWEA-D4] 1210. Ladder1  (0) 2019.02.20
[SWEA-D3] 1209. Sum  (0) 2019.02.20
[SWEA-D3] 1208. Flatten  (0) 2019.02.20
[SWEA-D2] 1204. 최빈수 구하기  (0) 2019.02.20