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
- Trie
- SWEA
- CSV
- Priority Queue
- Algorithm
- SQL
- 코테
- aws
- 구현
- GitHub
- 시뮬레이션
- Back tracking
- 모의SW역량테스트
- 알고리듬
- Data Structure
- BFS
- 알고리즘
- 코딩테스트
- programmers
- DFS
- Bruth Force
- Python
- spring boot
- boj
- JavaScript
- django
- Vue.js
- hash table
- Linked list
- gpdb
Archives
- Today
- Total
hotamul의 개발 이야기
[Algorithm][C++] BOJ 15683 감시 본문
myt-algorithm-practice/Samsung SW Certi Adv
[Algorithm][C++] BOJ 15683 감시
hotamul 2021. 9. 22. 22:44url: https://hotamul.tistory.com/manage/newpost/?type=post&returnURL=%2Fmanage%2Fposts
TISTORY
나를 표현하는 블로그를 만들어보세요.
www.tistory.com
풀이 핵심
1. https://na982.tistory.com/95 참고
코드
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int R, C, ret;
int map[8][8];
struct CCTV { int type, r, c; };
CCTV cctv[8];
int cctv_size;
const int rot_size[] = { 4,2,4,4,1 };
void update(int dir, CCTV cctv) {
dir %= 4;
if (dir == 0) {
for (int c = cctv.c + 1; c < C; c++) {
if (map[cctv.r][c] == 6) break;
map[cctv.r][c] = -1;
}
}
if (dir == 1) {
for (int r = cctv.r - 1; r >= 0; r--) {
if (map[r][cctv.c] == 6) break;
map[r][cctv.c] = -1;
}
}
if (dir == 2) {
for (int c = cctv.c - 1; c >= 0; c--) {
if (map[cctv.r][c] == 6) break;
map[cctv.r][c] = -1;
}
}
if (dir == 3) {
for (int r = cctv.r + 1; r < R; r++) {
if (map[r][cctv.c] == 6) break;
map[r][cctv.c] = -1;
}
}
}
void cpy_map(int a[8][8], int b[8][8]) {
for (int r = 0; r < R; r++) {
for (int c = 0; c < C; c++) {
a[r][c] = b[r][c];
}
}
}
void dfs(int idx) {
if (idx == cctv_size) {
int tmp = 0;
for (int r = 0; r < R; r++) {
for (int c = 0; c < C; c++) {
if (map[r][c] == 0) tmp++;
}
}
if (tmp < ret) ret = tmp;
return;
}
int backup[8][8];
int type = cctv[idx].type;
cpy_map(backup, map);
for (int dir = 0; dir < rot_size[type]; dir++) {
if (type == 0) {
update(dir, cctv[idx]);
}
if (type == 1) {
update(dir, cctv[idx]);
update(dir + 2, cctv[idx]);
}
if (type == 2) {
update(dir, cctv[idx]);
update(dir + 1, cctv[idx]);
}
if (type == 3) {
update(dir, cctv[idx]);
update(dir + 1, cctv[idx]);
update(dir + 2, cctv[idx]);
}
if (type == 4) {
update(dir, cctv[idx]);
update(dir + 1, cctv[idx]);
update(dir + 2, cctv[idx]);
update(dir + 3, cctv[idx]);
}
dfs(idx + 1);
cpy_map(map, backup);
}
}
int main() {
scanf("%d %d", &R, &C);
for (int r = 0; r < R; r++) {
for (int c = 0; c < C; c++) {
scanf("%d", &map[r][c]);
if (map[r][c] != 0 && map[r][c] != 6) {
cctv[cctv_size].r = r;
cctv[cctv_size].c = c;
cctv[cctv_size++].type = map[r][c] - 1;
}
}
}
ret = 100;
dfs(0);
printf("%d", ret);
return 0;
}
'myt-algorithm-practice > Samsung SW Certi Adv' 카테고리의 다른 글
[Algorithm][C++] BOJ 20056 마법사 상어와 파이어볼 (0) | 2021.09.24 |
---|---|
[Algorithm][C++] BOJ 15684 사다리 조작 (0) | 2021.09.23 |
[Algorithm][C++] BOJ 14891 톱니바퀴 (0) | 2021.09.19 |
[Algorithm][C++] BOJ 14503 로봇 청소기 (0) | 2021.09.15 |
[Algorithm][C++] BOJ 3190 뱀 (0) | 2021.09.14 |
Comments