Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- UnrealEngine4
- 팰린드롬 만들기
- GeeksForGeeks
- UnrealEngine5
- 오블완
- 언리얼엔진5
- baekjoon
- 티스토리챌린지
- C++
- directx
- Unreal Engine5
- winapi
- IFileDialog
- 프로그래머스
- C
- Frustum
- 줄 세우기
- const
- 2294
- TObjectPtr
- Programmers
- UE5
- 1563
- softeer
- RVO
- DirectX11
- NRVO
- algorithm
- RootMotion
- 백준
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 17406번 :: 배열 돌리기 4 본문
https://www.acmicpc.net/problem/17406
|
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_set>
#include <thread>
#include <atomic>
using namespace std;
struct RotateInfo
{
int r, c, s;
};
int n, m, k;
int arr[53][53] = { 0 };
int tempArr[53][53] = { 0 };
int dirs[4][2] = { {0,1}, {1,0}, {0,-1}, {-1,0} };
vector<RotateInfo> rotateInfos;
vector<int> indices;
bool visited[7] = { false };
int answer = 0x3f3f3f3f;
bool IsInRange(int cy, int cx, int sy, int sx, int dy, int dx)
{
if (cy < sy || cy > dy) return false;
if (cx < sx || cx > dx) return false;
return true;
}
void Rotate(const RotateInfo& rotateInfo)
{
int sy = rotateInfo.r - rotateInfo.s;
int sx = rotateInfo.c - rotateInfo.s;
int dy = rotateInfo.r + rotateInfo.s;
int dx = rotateInfo.c + rotateInfo.s;
while (sy < dy && sx < dx) // 바깥쪽부터 회전.
{
int cy = sy;
int cx = sx;
int prevNum = tempArr[cy][cx];
tempArr[cy][cx] = 0;
for (int i = 0; i < 4; ++i)
{
while (1) // 한방향 끝까지 쭈욱
{
int ny = cy + dirs[i][0];
int nx = cx + dirs[i][1];
if (!IsInRange(ny, nx, sy, sx, dy, dx))
{
break;
}
int nextNum = tempArr[ny][nx];
tempArr[ny][nx] = prevNum;
prevNum = nextNum;
cy = ny;
cx = nx;
}
}
++sy;
++sx;
--dy;
--dx;
}
}
void GetMinRowSum()
{
memcpy(tempArr, arr, sizeof(arr));
for (int i = 0; i < indices.size(); ++i)
{
int index = indices[i];
Rotate(rotateInfos[index]);
}
// 최솟값 구하기
for (int i = 1; i <= n; ++i)
{
int sum = 0;
for (int j = 1; j <= m; ++j)
{
sum += tempArr[i][j];
}
answer = min(answer, sum);
}
}
void DFS()
{
if (indices.size() == k)
{
GetMinRowSum();
return;
}
for (int i = 0; i < rotateInfos.size(); ++i)
{
if (visited[i]) continue;
visited[i] = true;
indices.push_back(i);
DFS();
visited[i] = false;
indices.pop_back();
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cin >> arr[i][j];
}
}
for (int i = 0; i < k; ++i)
{
int a, b, c;
cin >> a >> b >> c;
rotateInfos.push_back({ a,b,c });
}
DFS();
cout << answer;
}
|
cs |
수열로 경우의 수를 뽑고 그거에 따라 배열을 회전을 시키는 문제.
이런 시뮬레이션 문제를 좋아하지 않아서 좀 외면하는 경향이 있긴 한데.. 한번쯤은 풀어놔야 할 것 같아서 해봤다.
실제 회전하는 코드만 인덱스 안헷갈리게 주의하면 되고, 이외에는 경우의 수 뽑기정도?
'Algorithm > Baekjoon' 카테고리의 다른 글
| [Algorithm]Baekjoon 2539번 :: 모자이크 (0) | 2025.11.04 |
|---|---|
| [Algorithm]Baekjoon 16434번 :: 드래곤 앤 던전 (0) | 2025.09.17 |
| [Algorithm]Baekjoon 11758번 :: CCW (0) | 2025.03.21 |
| [Algorithm]Baekjoon 14621번 :: 나만 안되는 연애 (1) | 2025.03.19 |
| [Algorithm]Baekjoon 6497번 :: 전력난 (0) | 2025.03.19 |