Skip to content
Open
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
42 changes: 42 additions & 0 deletions 0512/BOJ/P1931/P1931_ko.java
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
import java.util.Arrays;
import java.util.Scanner;

public class P1931_ko {
static class Meet implements Comparable<Meet> {
int s;
int f;

public Meet(int s, int f) {
this.s = s;
this.f = f;
}

@Override
public int compareTo(Meet o) {
if (this.f == o.f) // 끝나는 시간 같으면
return this.s - o.s; // 시작하는 시간 기준 정렬
return this.f - o.f;
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ans = 1; // 최소 회의 1개 가능
int N = sc.nextInt();
Meet[] mList = new Meet[N];

for (int i = 0; i < N; i++)
mList[i] = new Meet(sc.nextInt(), sc.nextInt());

Arrays.sort(mList); // 정렬

int nF = mList[0].f; // 앞 회의 끝나는 시간은 맨 앞 회의로 초기화
for (int i = 1; i < N; i++)
if (mList[i].s >= nF) { // 가능한 회의
nF = mList[i].f; // 끝나는 시간 변경
ans++;
}

System.out.print(ans);
}

}
38 changes: 38 additions & 0 deletions 0512/BOJ/P1992/P1992_ko.java
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
import java.util.Scanner;

public class P1992_ko {
static String[][] pic;
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
pic = new String[N][N];
for (int i = 0; i < N; i++)
pic[i] = sc.next().split("");

slice(0, 0, N);

System.out.print(sb);
}

static boolean check(int x, int y, int w) { // 너비 w만큼 같은 값인지 확인
for (int i = x; i < x + w; i++)
for (int j = y; j < y + w; j++)
if (!pic[x][y].equals(pic[i][j])) // 하나라도 아니면 false
return false;
return true;
}

static void slice(int x, int y, int w) {
if (check(x, y, w)) { // 시작점에서 너비 w만큼 같은 값인 경우
sb.append(pic[x][y]);
return;
}
sb.append("(");
for (int i = x; i < x + w; i += w / 2) // 4분의 1로 쪼개기
for (int j = y; j < y + w; j += w / 2)
slice(i, j, w / 2);
sb.append(")");
}

}
60 changes: 60 additions & 0 deletions 0512/BOJ/P2178/P2178_ko.java
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class P2178_ko {
static int[] dx = { -1, 1, 0, 0 }; // 상하좌우
static int[] dy = { 0, 0, -1, 1 };
static int[][] maze;
static int N;
static int M;

static class Point {
int x;
int y;

public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
maze = new int[N][M];

for (int i = 0; i < N; i++) {
String now = sc.next();
for (int j = 0; j < M; j++)
maze[i][j] = now.charAt(j) - '0';
}

System.out.print(bfs(new Point(0, 0)));
}

static int bfs(Point s) {
Queue<Point> q = new LinkedList<>();
q.add(s);
while (!q.isEmpty()) {
Point now = q.poll();
int x = now.x;
int y = now.y;
for (int d = 0; d < 4; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
if (nx < 0 || nx >= N || ny < 0 || ny >= M || (nx == 0 && ny == 0))
continue;
if (maze[nx][ny] == 1) { // 아직 방문하지 않은 경우
q.add(new Point(nx, ny));
maze[nx][ny] = maze[x][y] + 1;
}
}

}

return maze[N - 1][M - 1];
}

}