Henu
개발냥발
Henu
전체 방문자
오늘
어제
  • 분류 전체보기 (411)
    • DevOps (52)
      • Kubernetes (19)
      • Docker (14)
      • AWS (3)
      • Nginx (4)
      • Linux (4)
      • ArgoCD (1)
      • CN (2)
      • NATS (0)
      • Git (5)
    • Back-End (30)
      • Django (18)
      • Spring (5)
      • JPA (1)
      • MSA (5)
    • CS (87)
      • SystemSoftware (20)
      • OS (25)
      • Computer Architecture (16)
      • Network (23)
      • Database (2)
    • Lang (21)
      • Java (9)
      • Python (4)
      • C# (8)
    • Life (12)
    • 블록체인 (2)
    • Algorithm (204)
      • BOJ (160)
      • 프로그래머스 (19)
      • LeetCode (4)
      • SWEA (1)
      • 알고리즘 문제 해결 전략 (8)
      • DS, algorithms (7)
      • Checkio (5)
    • IT (2)

블로그 메뉴

  • GitHub
  • 글쓰기
  • 관리자

공지사항

  • Free!

인기 글

태그

  • 프로그래머스
  • DFS
  • BFS
  • 다이나믹 프로그래밍
  • Network
  • Kubernetes
  • boj
  • 백트래킹
  • django
  • docker

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Henu

개발냥발

[백준 20165] 인내의 도미노 장인 호석 C++
Algorithm/BOJ

[백준 20165] 인내의 도미노 장인 호석 C++

2021. 7. 22. 14:09
 

20165번: 인내의 도미노 장인 호석

사람을 화나게 하는 법은 다양하다. 그 중에서도 악질은 바로 열심히 세워놓은 도미노를 넘어뜨리는 것이다. 이번에 출시된 보드 게임인 "너 죽고 나 살자 게임"은 바로 이 점을 이용해서 2명이

www.acmicpc.net

구현, 시뮬레이션


 

도미노 넘어뜨리는 구현 : crash_domino() 참고

 

현재 넘어지고 있는 도미노 : last

곧 넘어질 수도 있는 도미노 : Map[nr][nc]

 

현재 넘어지는 도미노의 최대길이를 구한다.

last = max(last, Map[nr][nc])

 

만약 도미노가 있다면 넘어뜨린다. Map[nr][nc] = 0

 

nr과 nc를 현재 방향에 맞춰서 이동시킨다.

하나 넘어뜨렸으므로 현재 넘어지고 있는 도미노의 길이를 1 감소시킨다.

 

 

 

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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#define fasti ios_base::sync_with_stdio(false); cin.tie(0);
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1e9+7
#define pii pair<int, int>
 
typedef long long ll;
// typedef pair<int, int> pii;
 
using namespace std;
 
struct attack{
    int r, c, dir;
};
 
int N, M, R, score;
int Map[101][101];
int TMap[101][101];
 
int dr[4] = {0, 0, 1, -1};
int dc[4] = {1, -1, 0, 0};
 
vector<attack> Attacker;
vector<pii > Defender;
 
void input(){
    cin >> N >> M >> R;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            cin >> Map[i][j];
            TMap[i][j] = Map[i][j];
        }
    }
    int a, b;
    char c;
    for(int i = 0; i < R*2; i++){
        if(i % 2 == 0){
            cin >> a >> b >> c;
            switch (c){
            case 'E': Attacker.push_back({a-1, b-1, 0});break;
            case 'W': Attacker.push_back({a-1, b-1, 1}); break;
            case 'S': Attacker.push_back({a-1, b-1, 2}); break;
            case 'N': Attacker.push_back({a-1, b-1, 3}); break;
            default: break;
            }
        }
        else{
            cin >> a >> b;
            Defender.push_back({a-1, b-1});
        }
    }
}
 
void crash_domino(int r, int c, int dir){
    int last = Map[r][c];
    int nr = r;
    int nc = c;
    while(nr >= 0 && nr < N && nc >= 0 && nc < M && last){
        last = max(last, Map[nr][nc]);
        if(Map[nr][nc]){
            Map[nr][nc] = 0;
            score++;
        }
        nr += dr[dir];
        nc += dc[dir];
        last--;
    }
}
 
inline void raise_domino(int r, int c){
    Map[r][c] = TMap[r][c];
}
 
void show(){
    cout << score << "\n";
    for(int r = 0; r < N; r++){
        for(int c = 0; c < M; c++){
            if(!Map[r][c]) cout << 'F' << " ";
            else cout << 'S' << " ";
        }
        cout << "\n";
    }
}
 
void solve(){
    for(int i = 0; i < R; i++){
        crash_domino(Attacker[i].r, Attacker[i].c, Attacker[i].dir);
        raise_domino(Defender[i].first, Defender[i].second);
    }
    
    show();
}
 
int main(){
    fasti
    input();
    solve();
    
    return 0;
}
 
Colored by Color Scripter
cs

 

'Algorithm > BOJ' 카테고리의 다른 글

[백준 1774] 우주신과의 교감 C++  (0) 2021.07.23
[백준 1602] 도망자 원숭이 C++  (0) 2021.07.23
[백준 16681] 등산 C++  (0) 2021.07.21
[백준 1890] 점프 C++  (0) 2021.07.21
[백준 2573] 빙산 C++  (0) 2021.07.21
    'Algorithm/BOJ' 카테고리의 다른 글
    • [백준 1774] 우주신과의 교감 C++
    • [백준 1602] 도망자 원숭이 C++
    • [백준 16681] 등산 C++
    • [백준 1890] 점프 C++

    티스토리툴바