문제
https://www.acmicpc.net/problem/12100
해설
rotatee()를 만들어야 하는 문제(암기)
2차원 배열을 여러번 복사해야하는 일이 있으면 구조체 만들어서 구현하기
코드
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
|
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,ret;
int mp[24][24];
int cnt_num(int a[24][24]){
int tmp =0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
tmp = max(tmp,a[i][j]);
}
}
return tmp;
}
void rotate(int a[24][24]){
int temp[24][24];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
temp[i][j] = a[n-j-1][i];
}
}
memcpy(a,temp,sizeof(temp));
}
int go(int b[24][24],int cnt){
int a[24][24];
memcpy(a,b,sizeof(a));
for(int i=0;i<n;i++){
int ck=0;
for(int j=0;j<n;j++){
int x = j-1;
if(a[i][j] == 0)
continue;
while(x>=0){
if(a[i][x] == 0 && x>ck){
x--;
continue;
}
else if(a[i][x] == a[i][j]){
a[i][x] = a[i][j] *2;
a[i][j] = 0;
ck = x+1;
break;
}
else if(a[i][x] == 0){
a[i][x] = a[i][j];
a[i][j] = 0;
break;
}
else{
int tmp = a[i][j];
a[i][j] = 0;
a[i][x+1] = tmp;
ck = x+1;
break;
}
}
}
}
if(cnt == 5)
return cnt_num(a);
else{
int tmp_ret = 0;
for(int i=0;i<4;i++){
tmp_ret = max(tmp_ret,go(a,cnt+1));
rotate(a);
}
return tmp_ret;
}
}
int main(){
cin >> n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin >> mp[i][j];
}
}
for(int i=0;i<4;i++){
ret = max(ret,go(mp,1));
rotate(mp);
}
cout << ret;
return 0;
}
|
cs |
'백준 알고리즘(C++)' 카테고리의 다른 글
백준 2792번 보석 상자 ( C++ ) (0) | 2024.09.09 |
---|---|
백준 3190번 뱀 ( C++ ) (2) | 2024.09.08 |
백준 14889번 스타트와 링크 ( C++ ) (0) | 2024.09.05 |
백준 17144번 미세먼지 안녕! ( C++ ) (1) | 2024.09.04 |
백준 1700번 멀티탭 스케줄링 ( C++ ) (0) | 2024.09.04 |