Skip to content
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
53 changes: 53 additions & 0 deletions 12월/4주차/[BOJ] 세 번 이내에 사과를 먹자/Mun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.io.*;

public class Mun {
static boolean[][] checked = new boolean[5][5];
static int[][] board = new int[5][5];
static boolean eatApple = false;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<5;i++) {
String[] input = br.readLine().split(" ");
for(int j=0;j<5;j++) {
board[i][j] = Integer.parseInt(input[j]);
}
}
String[] loc = br.readLine().split(" ");
int r = Integer.parseInt(loc[0]);
int c = Integer.parseInt(loc[1]);
checked[r][c] = true;
findRoot(r, c, 0, 0);
System.out.print((eatApple) ? 1 : 0);

}
static int[][] dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

private static void findRoot(int r, int c, int move, int appleCount) {
if(eatApple) {
return;
}
if(board[r][c] == 1) {
appleCount++;
}
if(move == 3) {
eatApple = appleCount >= 2;
return;
}
for(int[] d : dir) {
int nr = r + d[0];
int nc = c + d[1];
if(outOfRange(nr, nc) || checked[nr][nc] || board[nr][nc] == -1) {
continue;
}
checked[nr][nc] = true;
findRoot(nr, nc, move + 1, appleCount);
checked[nr][nc] = false;
}

}

private static boolean outOfRange(int nr, int nc) {
return (nr >= 5 || nr < 0 || nc >= 5 || nc < 0);
}
}
40 changes: 40 additions & 0 deletions 12월/4주차/[BOJ] 스피카/Mun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import java.util.*;

public class Mun {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer>[] line = new ArrayList[13];
for(int i=1;i<=12;i++) {
line[i] = new ArrayList<>();
}
for(int i=0;i<12;i++) {
String[] input = br.readLine().split(" ");
int x = Integer.parseInt(input[0]);
int y = Integer.parseInt(input[1]);
line[x].add(y);
line[y].add(x);
}
int Spika = -1;
for(int i=1;i<=12;i++) {
if(line[i].size() != 1) {
continue;
}
int sCandidate = line[i].get(0);
if(line[sCandidate].size() != 3) {
continue;
}
for(int star : line[sCandidate]) {
if(line[star].size() == 2) {
Spika = sCandidate;
break;
}
}
if(Spika > 0) {
break;
}
}
System.out.print(Spika);
}

}
46 changes: 46 additions & 0 deletions 12월/4주차/[BOJ] 주난의 난/Mun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io.*;
import java.util.*;

public class Mun {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int N = Integer.parseInt(input[0]);
int M = Integer.parseInt(input[1]);
String[] loc = br.readLine().split(" ");
int x1 = Integer.parseInt(loc[0]) - 1;
int y1 = Integer.parseInt(loc[1]) - 1;
int x2 = Integer.parseInt(loc[2]) - 1;
int y2 = Integer.parseInt(loc[3]) - 1;
char[][] map = new char[N][M];
int[][] distance = new int[N][M];
for(int i=0;i<N;i++) {
map[i] = br.readLine().toCharArray();
}
distance[x1][y1] = 1;
int[][] dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
Queue<int[]> que = new LinkedList<>();
que.add(new int[]{x1, y1, 1});
while(que.size() > 0 ) {
int[] now = que.poll();
for(int[] d : dir) {
int nx = now[0] + d[0];
int ny = now[1] + d[1];
if(nx < 0 || nx >= N || ny < 0 || ny >= M)
continue;

int olddis = distance[nx][ny];
int newdis = now[2] + ((map[nx][ny] == '1') ? 1 : 0);
if(olddis == 0 || olddis > newdis) {
distance[nx][ny] = newdis;
if(map[nx][ny] == '#') {
continue;
}
que.add(new int[]{nx, ny, newdis});
}
}
}
System.out.print(distance[x2][y2]);
}
}