Skip to content

Commit c4697ff

Browse files
committed
Merge branch 'week14'
2 parents 025f38f + ea4c142 commit c4697ff

4 files changed

+141
-0
lines changed

Diff for: week14/BOJ_1987(알파벳).java

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
private static int R, C;
7+
private static char[][] board;
8+
private static boolean[][] visited;
9+
private static boolean[] check;
10+
private static int[] dh = {-1, 0, 1, 0};
11+
private static int[] dw = {0, 1, 0, -1};
12+
private static int answer = 0;
13+
14+
public static void main(String[] args) throws IOException {
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
R = Integer.parseInt(st.nextToken());
18+
C = Integer.parseInt(st.nextToken());
19+
board = new char[R][C];
20+
visited = new boolean[R][C];
21+
check = new boolean[30];
22+
for(int i=0; i<R; i++) {
23+
String input = br.readLine();
24+
for(int j=0; j<C; j++) {
25+
board[i][j] = input.charAt(j);
26+
}
27+
}
28+
visited[0][0] = true;
29+
check[board[0][0] - 'A'] = true;
30+
dfs(0, 0, 1);
31+
System.out.println(answer);
32+
}
33+
34+
public static void dfs(int h, int w, int depth) {
35+
if(depth > R*C) {
36+
return;
37+
}
38+
answer = Math.max(answer, depth);
39+
40+
for(int i=0; i<4; i++) {
41+
int nextH = h + dh[i];
42+
int nextW = w + dw[i];
43+
if(nextH >= 0 && nextH < R && nextW >=0 && nextW < C) {
44+
int index = board[nextH][nextW] - 'A';
45+
if(!visited[nextH][nextW] & !check[index]) {
46+
check[index] = true;
47+
dfs(nextH, nextW, depth+1);
48+
check[index] = false;
49+
}
50+
}
51+
}
52+
}
53+
}

Diff for: week14/BOJ_19951(태상이의 훈련소 생활).java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int N = Integer.parseInt(st.nextToken());
10+
int M = Integer.parseInt(st.nextToken());
11+
int[] h = new int[N+1];
12+
st = new StringTokenizer(br.readLine());
13+
for(int i=1; i<=N; i++) {
14+
h[i] = Integer.parseInt(st.nextToken());
15+
}
16+
int[] arr = new int[N+2];
17+
for(int i=0; i<M; i++) {
18+
st = new StringTokenizer(br.readLine());
19+
int a = Integer.parseInt(st.nextToken());
20+
int b = Integer.parseInt(st.nextToken());
21+
int k = Integer.parseInt(st.nextToken());
22+
arr[a] += k;
23+
arr[b+1] -= k;
24+
}
25+
for(int i=1; i<=N; i++) {
26+
arr[i] += arr[i-1];
27+
h[i] += arr[i];
28+
}
29+
StringBuilder sb = new StringBuilder();
30+
for(int i=1; i<=N; i++) {
31+
sb.append(h[i]).append(' ');
32+
}
33+
System.out.println(sb);
34+
}
35+
}

Diff for: week14/BOJ_5052(전화번호 목록).java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int t = Integer.parseInt(br.readLine());
9+
StringBuilder sb = new StringBuilder();
10+
while(t-- > 0) {
11+
int n = Integer.parseInt(br.readLine());
12+
String[] str = new String[n];
13+
for(int i=0; i<n; i++) {
14+
str[i] = br.readLine();
15+
}
16+
Arrays.sort(str);
17+
sb.append(check(str) ? "YES" : "NO").append('\n');
18+
}
19+
System.out.print(sb);
20+
}
21+
22+
public static boolean check(String[] str) {
23+
for(int i=1; i<str.length; i++) {
24+
if(str[i].startsWith(str[i-1])) {
25+
return false;
26+
}
27+
}
28+
return true;
29+
}
30+
}

Diff for: week14/Programmers_142085(디펜스 게임).java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int n, int k, int[] enemy) {
5+
int round = 0;
6+
PriorityQueue<Integer> pq = new PriorityQueue<>();
7+
for(int i=0; i<enemy.length; i++) {
8+
round = i+1;
9+
pq.offer(enemy[i]);
10+
if(k-- > 0) {
11+
continue;
12+
}
13+
int knight = pq.poll();
14+
if(n - knight >= 0) {
15+
n -= knight;
16+
}else {
17+
round--;
18+
break;
19+
}
20+
}
21+
return round;
22+
}
23+
}

0 commit comments

Comments
 (0)