도형의 종류별로 회전과 대칭의 index를 확인해보며 넣었을 경우 얻는 값을 최대로 경신해주기만 하면 풀리는 막일 문제였다. 꼼꼼하게 체크할게 거의 없었고 가능하면 정리해서 코드를 짜야 하지만 역량테스트를 치른다는 가정하에 가장 빠르게 해결하기 위하여 너저분하게 코드가 짜였다.

https://github.com/ukjinlee66/BOJ/blob/master/14500.cpp

 

ukjinlee66/BOJ

baekjoon. Contribute to ukjinlee66/BOJ development by creating an account on GitHub.

github.com

https://www.acmicpc.net/problem/14500

 

14500번: 테트로미노

폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다. 정사각형은 서로 겹치면 안 된다. 도형은 모두 연결되어 있어야 한다. 정사각형의 변끼리 연결되어 있어야 한다. 즉, 꼭짓점과 꼭짓점만 맞닿아 있으면 안 된다. 정사각형 4개를 이어 붙인 폴리오미노는 테트로미노라고 하며, 다음과 같은 5가지가 있다. 아름이는 크기가 N×M인 종이 위에 테트로미노 하나를 놓으려고 한다. 종이는 1×1 크기의 칸으로 나누

www.acmicpc.net

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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int map[501][501];
int n,m;
int res;
bool check(int x, int y)
{
    if (x<1 || y<1 || x>|| y>m) return false;
    return true;
}
void one(int x, int y)
{
    if (check(x + 1, y + 1&& check(x + 1, y) && check(x, y + 1))
        res = max(res, map[x + 1][y + 1+ map[x + 1][y] + map[x][y + 1+ map[x][y]);
}
void two(int x, int y)
{
    if (check(x + 1, y) && check(x + 2, y) && check(x + 3, y))
        res = max(res, map[x][y] + map[x + 1][y] + map[x + 2][y] + map[x + 3][y]);
    //회전
    if (check(x, y + 1&& check(x, y + 2&& check(x, y + 3))
        res = max(res, map[x][y] + map[x][y + 1+ map[x][y + 2+ map[x][y + 3]);
}
void three(int x, int y)
{
    if (check(x + 1, y) && check(x + 2, y) && check(x + 2, y + 1))
        res = max(res,map[x][y] + map[x + 1][y] + map[x + 2][y] + map[x + 2][y + 1]);
    //회전 3가지.
    if (check(x, y + 1&& check(x, y + 2&& check(x - 1, y + 2))
        res = max(res, map[x][y] + map[x][y + 1+ map[x][y + 2+ map[x - 1][y + 2]);
    if (check(x, y + 1&& check(x + 1, y + 1&& check(x + 2, y + 1))
        res = max(res, map[x][y] + map[x][y + 1+ map[x + 1][y + 1+ map[x + 2][y + 1]);
    if (check(x + 1, y) && check(x, y + 1&& check(x, y + 2))
        res = max(res, map[x][y] + map[x + 1][y] + map[x][y + 1+ map[x][y + 2]);
    //반전1 +회전 3가지
    if (check(x, y + 1&& check(x - 1, y + 1&& check(x - 2, y + 1))
        res = max(res, map[x][y] + map[x][y + 1+ map[x - 1][y + 1+ map[x - 2][y + 1]);
    if (check(x, y + 1&& check(x, y + 2&& check(x + 1, y + 2))
        res = max(res, map[x][y] + map[x][y + 1+ map[x][y + 2+ map[x + 1][y + 2]);
    if (check(x, y + 1&& check(x + 1, y) && check(x + 2, y))
        res = max(res, map[x][y] + map[x][y + 1+ map[x + 1][y] + map[x + 2][y]);
    if (check(x + 1, y) && check(x + 1, y + 1&& check(x + 1, y + 2))
        res = max(res, map[x][y] + map[x + 1][y] + map[x + 1][y + 1+ map[x + 1][y + 2]);
}
void four(int x, int y)
{
    if (check(x + 1, y) && check(x + 1, y + 1&& check(x + 2, y + 1))
        res = max(res, map[x][y] + map[x + 1][y] + map[x + 1][y + 1+ map[x + 2][y + 1]);
    if (check(x, y + 1&& check(x - 1, y + 1&& check(x - 1, y + 2))
        res = max(res, map[x][y] + map[x][y + 1+ map[x - 1][y + 1+ map[x - 1][y + 2]);
    if (check(x + 1, y) && check(x, y + 1&& check(x - 1, y + 1))
        res = max(res, map[x][y] + map[x + 1][y] + map[x][y + 1+ map[x - 1][y + 1]);
    if (check(x, y + 1&& check(x + 1, y + 1&& check(x + 1, y + 2))
        res = max(res, map[x][y] + map[x][y + 1+ map[x + 1][y + 1+ map[x + 1][y + 2]);
}
void five(int x, int y)
{
    if (check(x, y + 1&& check(x, y + 2&& check(x - 1, y + 1))
        res = max(res, map[x][y] + map[x][y + 1+ map[x][y + 2+ map[x - 1][y + 1]);
    if (check(x, y + 1&& check(x + 1, y + 1&& check(x - 1, y + 1))
        res = max(res, map[x][y] + map[x][y + 1+ map[x + 1][y + 1+ map[x - 1][y + 1]);
    if (check(x, y + 1&& check(x, y + 2&& check(x + 1, y + 1))
        res = max(res, map[x][y] + map[x][y + 1+ map[x][y + 2+ map[x + 1][y + 1]);
    if (check(x + 1, y) && check(x + 2, y) && check(x + 1, y + 1))
        res = max(res, map[x][y] + map[x + 1][y] + map[x + 2][y] + map[x + 1][y + 1]);
}
void sol(int x,int y,int number) //도형의 번호를받음. (1~5)
{
    switch (number)
    {
    case 1:
        one(x, y);
        break;
    case 2:
        two(x, y);
        break;
    case 3:
        three(x, y);
        break;
    case 4:
        four(x, y);
        break;
    case 5:
        five(x, y);
        break;
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> map[i][j];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            for (int k = 1; k <= 5; k++)
            {
                sol(i, j, k);
            }
        }
    }
    cout << res;
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

'Problem Solving > 삼성 역량테스트' 카테고리의 다른 글

BOJ-17406 배열돌리기 4  (0) 2019.11.10
BOJ-17837 새로운 게임2  (0) 2019.11.06
BOJ-12100 2048(Easy)  (0) 2019.11.06
BOJ-17144 미세먼지 안녕  (0) 2019.11.06
BOJ-17780 새로운 게임  (0) 2019.11.05

+ Recent posts