티스토리 뷰
https://www.acmicpc.net/problem/16918
16918번: 봄버맨
첫째 줄에 R, C, N (1 ≤ R, C, N ≤ 200)이 주어진다. 둘째 줄부터 R개의 줄에 격자판의 초기 상태가 주어진다. 빈 칸은 '.'로, 폭탄은 'O'로 주어진다.
www.acmicpc.net
맵의 상태는 반복되는 패턴이 있기때문에 입력되는 n과 같은 패턴을 가지는 첫번째 시간까지만 계산하였습니다.
C++ 소스 코드
#include <iostream>
#include <string>
using namespace std;
int r,c,n;
const int dx[]={0,0,-1,1}, dy[]={-1,1,0,0};
int timer[201][201];
string map[201];
void solve(int N){
for(int t=2;t<=N;t++){
if(t%2 == 0){
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(map[i][j] == 'O') continue;
map[i][j] = 'O';
timer[i][j]=t+3;
}
}
}else {
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if (timer[i][j]==t){
for(int k=0;k<4;k++){
int nx = i+ dx[k], ny = j + dy[k];
if (nx < 0 || nx >= r || ny <0 || ny >=c) continue;
map[nx][ny]='.';
}
map[i][j]='.';
timer[i][j] = 0;
}
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> r >> c >> n;
for(int i=0;i<r;i++){
cin >> map[i];
for(int j=0;j<c;j++){
if (map[i][j]=='O'){
timer[i][j]=3;
}
}
}
if (n==1){
for(int i=0;i<r;i++){
cout << map[i] << '\n';
}
return 0;
}else if (n%4 == 2) n=2;
else if (n%4 == 3) n=3;
else if (n%4 == 0) n=4;
else if (n%4 == 1) n=5;
solve(n);
for(int i=0;i<r;i++){
cout << map[i] << '\n';
}
return 0;
}
'Algorithm > 알고리즘 문제풀이' 카테고리의 다른 글
프로그래머스) Lv1 - 체육복 (0) | 2020.07.09 |
---|---|
BOJ) 2252 - 줄 세우기 (0) | 2020.07.08 |
BOJ) 16920 - 확장 게임 (0) | 2020.07.07 |
프로그래머스) Lv3 - 경주로 건설 [2020 카카오 인턴십] (0) | 2020.07.05 |
프로그래머스) Lv2 - 수식 최대화 [2020 카카오 인턴십] (0) | 2020.07.05 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- blendshapes
- 카카오인턴십
- DispatchQueue
- GraphDB
- 프로그래머스
- Reactivex
- SwiftUI
- rxswift
- Swift
- Swift unowned
- disposeBag
- 코코아팟
- cocoapods
- Kotlin
- infallible
- ios
- 백준
- 백준온라인저지
- C++
- SWEA
- rxswift6
- UIHostingController
- 안드로이드
- boj
- Lottie
- blendshape
- coreml
- 알고리즘
- ARKit
- Swift weak
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함