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 |
Tags
- 버킷 정렬
- 백준 5397
- 해시구현
- 스택의 특징
- AVL 시간 복잡도
- 백준
- heap
- 원판 돌리기
- Stack 이란
- C/C++ 구현
- 백준 2447
- 백준 1158
- 백준 17471
- 해시 구현
- ㅣ풀이
- 게리멘더링2
- 시간 복잡도
- 풀이
- 조세퍼스 순열
- 자료구조
- 백준 1406
- 구현
- qorwns
- 1764
- 5397
- 백준 17822
- 백준 17779
- dfs
- c#
- 별 찍기 10
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 16918] 붐버맨 본문
분류
시뮬
요구사항
주어진 시간에서의 map의 상태 출력하기
주어진 조건대로 구현하면 된다
풀이
상태를 적어보면
0초일때 입력
1초 일때 X
2초 일때 반전된거 폭탄설치
3초 일때 0초때 심은 폭탄 폭발
4초 일때 반전 설치
5초 일때 2초일때 심은 폭탄 설치
......................
0, 1초 만 예외 처리해주고
나머지는 홀수, 짝수 똑같이 동작한다
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
int n, m, k;
char map[220][220];
int visit[220][220];
int dr[4] = { -1,0,1,0 };
int dc[4] = { 0,-1,0,1 };
void solve() {
int time = 1;
while (true) {
if (k == time) break;
time++;
if (time % 2 == 0) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (map[i][j] == '.') {
map[i][j] = 'O';
visit[i][j] = time + 3;
}
}
}
}
if (time % 2 == 1) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (visit[i][j] == time) {
for (int k = 0; k < 4; k++) {
int nr = i + dr[k];
int nc = j + dc[k];
if (nr < 0 || nc < 0 || nr >= n || nc >= m) continue;
map[nr][nc] = '.';
}
visit[i][j] = 0;
map[i][j] = '.';
}
}
}
}
if (time == k)
break;
}
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf(" %c", &map[i][j]);
if (map[i][j] == 'O') {
visit[i][j] = 3;
}
}
}
solve();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%c", map[i][j]);
}
printf("\n");
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 17825] 윷놀이 (0) | 2020.06.05 |
---|---|
[백준 9012] 괄호 (0) | 2020.05.28 |
[백준 14923] 미로 탈출 (0) | 2020.05.27 |
[백준 17090] 미로 탈출하기 (0) | 2020.05.27 |
[백준 14891] 톱니바퀴 (0) | 2020.05.26 |
Comments