Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18-kokeunho #73

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified kokeunho/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
| 15์ฐจ์‹œ | 2025.01.12 | ์กฐํ•ฉ๋ก  | [๊ฒฉ์ž์ƒ์˜ ๊ฒฝ๋กœ](https://www.acmicpc.net/problem/10164) | [#58](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/58) |
| 16์ฐจ์‹œ | 2025.01.19 | ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰ | [DFS์™€ BFS](https://www.acmicpc.net/problem/1260) | [#63](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/63) |
| 17์ฐจ์‹œ | 2025.01.20 | ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰ | [์•ˆ์ „ ์˜์—ญ](https://www.acmicpc.net/problem/2468) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/64) |
| 18์ฐจ์‹œ | 2025.02.11 | ๊ตฌํ˜„ | [๋กœ๋ด‡ ์ฒญ์†Œ๊ธฐ](https://www.acmicpc.net/problem/14503) | [#73](github.com/AlgoLeadMe/AlgoLeadMe-12/pull/72) |
---
75 changes: 75 additions & 0 deletions kokeunho/๊ตฌํ˜„/18-kokeunho.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.util.*;

public class Main {
static int n, m;
static int r, c, d;
static int[][] map;
static boolean[][] cleaned;
static int[] dx = {-1, 0, 1, 0};
static int[] dy = {0, 1, 0, -1};

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

n = sc.nextInt();
m = sc.nextInt();
r = sc.nextInt();
c = sc.nextInt();
d = sc.nextInt();

map = new int[n][m];
cleaned = new boolean[n][m];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ทผํ˜ธ๋‹˜ ์ฝ”๋“œ์—์„œ ๋ฐ”๋กœ ์ ์šฉ๊ฐ€๋Šฅํ•œ์ง€๋Š” ๋ชจ๋ฅด๊ฐฐ์ง€๋งŒ,
์ด๋ ‡๊ฒŒ ๋ถˆ๋ฆฌ์–ธ ๋ฐฐ์—ด์„ ๋”ฐ๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ , map ๋ฐฐ์—ด ์•ˆ์˜ ๊ฐ’์„ ์ˆ˜์ •ํ•ด์„œ ๋ฐฉ๋ฌธ ํ‘œ์‹œ๋ฅผ ํ•  ์ˆ˜ ๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜น ๋‹ค์Œ ๋น„์Šทํ•œ ์œ ํ˜• ํ’€์–ด๋ณผ ๋•Œ ์ ์šฉ์‹œ์ผœ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!


for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
map[i][j] = sc.nextInt();
}
}

int result = start(r, c);
System.out.println(result);
}
public static void turnLeft() {
d = (d + 3) % 4;
}
Comment on lines +32 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด์ง€๋งŒ ํ•จ์ˆ˜๋ถ„๋ฆฌ๋ฅผ ์ž˜ํ•ด์„œ ๋ณด๊ธฐ ํŽธํ•œ ๊ฒƒ ๊ฐ™์•„์„œ ์ข‹๋„ค์š”!

public static int start(int startX, int startY) {
int count = 0;

while (true) {
if (!cleaned[startX][startY]) {
cleaned[startX][startY] = true;
count++;
}

boolean moved = false;

for (int i = 0; i < 4; i++) {
turnLeft();
int nx = startX + dx[d];
int ny = startY + dy[d];

if (nx >= 0 && nx < n && ny >= 0 && ny < m
&& map[nx][ny] == 0 && !cleaned[nx][ny]) {
startX = nx;
startY = ny;
moved = true;
break;
}
}

if (!moved) {
int bx = startX - dx[d];
int by = startY - dy[d];

if (bx >= 0 && bx < n && by >= 0 && by <m && map[bx][by] == 0) {
startX = bx;
startY = by;
} else {
break;
}
}
}
return count;
}

}