티스토리 뷰

출저 : https://www.acmicpc.net/problem/4920


"전체 다해보자. 이상한 문제 trim() 주의."



브루트포스. 전체 다해보자. 삼성 기출의 테트로미노가 훨씬 깔끔한 문제... 이거는 좌표 지정 다 해줘야 한다. 좌표 지정할때는 정말 정신 차리고 해야 한다. 

그리고 입력으로 주어지는 데이터에 공백이 많으므로 trim() 하여 공백 처리해줬다. 이런 류의 문제 일일히 좌표 지정해주면 풀릴거 같으면 그냥 좌표 지정하자.

만약 좌표 지정하는데 너무 오래 걸린다... 막 테트리스 도형이 아니라 막 이상하다... 이러면 규칙을 찾아보자.

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
class Main {
 
    static int N;
    static int[][] map;
    static int max;
    static int[][][][] d ={
            {
                {
                    {0,0,0,0},
                    {0,1,2,3}
                },
                {
                    {0,1,2,3},
                    {0,0,0,0}
                }
            },
            {
                {
                    {0,0,1,1},
                    {0,1,1,2}
                },
                {
                    {0,1,1,2},
                    {0,0,-1,-1}
                }
            },
            {
                {
                    {0,0,0,1},
                    {0,1,2,2}
                },
                {
                    {0,1,2,2},
                    {0,0,0,-1}
                },
                {
                    {0,1,1,1},
                    {0,0,1,2}
                },
                {
                    {0,0,1,2},
                    {0,1,0,0}
                }
            },
            {
                {
                    {0,1,1,1},
                    {0,-1,0,1}
                },
                {
                    {0,1,1,2},
                    {0,0,1,0}
                },
                {
                    {0,0,0,1},
                    {0,1,2,1}
                },
                {
                    {0,1,1,2},
                    {0,-1,0,0}
                }
            },
            {
                {
                    {0,0,1,1},
                    {0,1,1,0}
                }
            }
        
    };
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int t = 1;
        
        while((N = Integer.parseInt(br.readLine().trim())) != 0) {
            map = new int[N][N];
            max = Integer.MIN_VALUE;
            
            for (int i = 0; i < N; i++) {
                StringTokenizer st = new StringTokenizer(br.readLine());
                for (int j = 0; j < N; j++) {
                    map[i][j] = Integer.parseInt(st.nextToken().trim());
                }
            }
            
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    for (int a = 0; a < 5; a++) {
                        for (int b = 0; b < d[a].length; b++) {
                            int sum = 0;
                            boolean ok = true;
                            for (int c = 0; c < 4; c++) {
                                int x = d[a][b][0][c];
                                int y = d[a][b][1][c];
                                if(!isRange(i+x, j+y)) {
                                    ok = false;
                                    break;
                                }
                                sum += map[i+x][j+y];
                            }
                            if(ok) {
                                max = Math.max(max, sum);
                            }
                        }
                    }
                }
            }
            System.out.println((t++)+". "+max);
        }
    }
    
    static boolean isRange(int x, int y) {
        if( x < 0 || x >= N || y < 0 || y >= N) return false;
        return true;
    }
    
    static int getValue(int x, int y) {
        return map[x][y];
    }
}
cs









댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday