8000 Update 23288.cpp · REDICALED/basic-algo-lecture@fba5449 · GitHub
[go: up one dir, main page]

Skip to content

Commit fba5449

Browse files
Update 23288.cpp
1 parent e540462 commit fba5449

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

0x0D/solutions/23288.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
11
// Authored by : HJPark
2-
// http://boj.kr/cc1b19ec95a54e04943a8204a5b34022
3-
2+
// Co-authored by : BaaaaaaaaaaarkingDog
3+
// http://boj.kr/0b99159aaaba43379606d5aefce0b753
44
#include <bits/stdc++.h>
55
using namespace std;
66

77
int n, m, k;
88
int board[22][22];
9-
int dxs[4] = {0, 1, 0, -1};
10-
int dys[4] = {1, 0, -1, 0};
9+
int dx[4] = {0, 1, 0, -1};
10+
int dy[4] = {1, 0, -1, 0};
1111
int dir = 0; // 동 남 서 북
1212
int cur_r = 1, cur_c = 1; // 현 위치
1313
int dice[6] = {1, 2, 3, 4, 5, 6};
1414
int ans = 0;
1515

16-
bool inbound(int r, int c) {
17-
if ((r > 0) && (r <= n) && (c > 0) && (c <= m))
18-
return true;
19-
else
20-
return false;
16+
bool OOB(int r, int c) {
17+
return r <= 0 || r > n || c <= 0 || c > m;
2118
}
2219

2320
void next_dir() {
2421
int dice_bottom = dice[5];
25-
2622
if (board[cur_r][cur_c] < dice_bottom)
2723
dir = (dir + 1) % 4;
2824
else if (board[cur_r][cur_c] > dice_bottom)
2925
dir = (dir + 3) % 4;
30-
if (!inbound(cur_r + dxs[dir], cur_c + dys[dir]))
26+
27+
if (OOB(cur_r + dx[dir], cur_c + dy[dir]))
3128
dir = (dir + 2) % 4;
3229
}
3330

34< 8000 code>31
void get_score() {
3532
int tile = 1;
36-
bool vis[22][22];
37-
fill(&vis[0][0], &vis[22][22], 0);
33+
bool vis[22][22] = {};
3834
queue<pair<int, int>> q;
3935
q.push({cur_r, cur_c});
4036
vis[cur_r][cur_c] = 1;
@@ -43,9 +39,9 @@ void get_score() {
4339
pair<int, int> pos = q.front();
4440
q.pop();
4541
for (int i = 0; i < 4; i++) {
46-
int nxt_r = pos.first + dxs[i];
47-
int nxt_c = pos.second + dys[i];
48-
if (inbound(nxt_r, nxt_c) && !vis[nxt_r][nxt_c] && board[nxt_r][nxt_c] == board[cur_r][cur_c]) {
42+
int nxt_r = pos.first + dx[i];
43+
int nxt_c = pos.second + dy[i];
44+
if (!OOB(nxt_r, nxt_c) && !vis[nxt_r][nxt_c] && board[nxt_r][nxt_c] == board[cur_r][cur_c]) {
4945
q.push({nxt_r, nxt_c});
5046
vis[nxt_r][nxt_c] = 1;
5147
tile++;
@@ -82,8 +78,8 @@ void move() {
8278
dice[1] = tmp[0];
8379
}
8480

85-
cur_r += dxs[dir];
86-
cur_c += dys[dir];
81+
cur_r += dx[dir];
82+
cur_c += dy[dir];
8783
}
8884

8985
int main(void) {

0 commit comments

Comments
 (0)
0