[BOJ] 18808번 : 스티커 붙이기
2024. 8. 20. 09:03ㆍAlgorithm
1. problem :
https://www.acmicpc.net/problem/18808
2. solution 1 :
// source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x0D/solutions/18808.cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, k; // 노트북 행, 열 스티커 개수
int r, c; // 스티커 row, col ;
int paper[12][12];
int note[42][42];
bool pastable(int x, int y) {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (note[x + i][y + j] == 1 && paper[i][j] == 1) return false;
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (paper[i][j] == 1) note[x + i][y + j] = 1;
}
}
return true;
}
void rotate() {
int temp[12][12];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
temp[i][j] = paper[i][j];
}
}
for (int i = 0; i < c; i++) {
for (int j = 0; j < r; j++) {
paper[i][j] = temp[r - 1 - j][i];
}
}
swap(r, c);
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
while (k--) {
cin >> r >> c;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> paper[i][j];
}
}
for (int rot = 0; rot < 4; rot++) {
bool is_paste = false;
for (int i = 0; i <= n - r; i++) {
if (is_paste) break;
for (int j = 0; j <= m - c; j++) {
if (pastable(i, j)) {
is_paste = true;
break;
}
}
}
if (is_paste) break;
rotate();
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cnt += note[i][j];
}
}
cout << cnt << '\n';
}
source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x0D/solutions/18808.cpp
basic-algo-lecture/0x0D/solutions/18808.cpp at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
'Algorithm' 카테고리의 다른 글
[BOJ] 15686번 : 치킨 배달 (0) | 2024.08.20 |
---|---|
[BOJ] 12100번 : 2048 (Easy) (0) | 2024.08.20 |
[BOJ] 15683번 : 감시 (0) | 2024.08.19 |
[BOJ] 16987번 : 계란으로 계란치기 (0) | 2024.08.19 |
[BOJ] 1941번 : 소문난 칠공주 (0) | 2024.08.19 |