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

[Week24] 스밈 알고리즘 24주차 제출 #56

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
67 changes: 67 additions & 0 deletions sohyeon/src/week24/boj16928.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package week24;

import java.io.*;
import java.util.*;

public class boj16928 {

static int N, M;
static int[] visited = new int[101];
static int[] board = new int[101];

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

for (int i = 1; i <= 100; i++) {
board[i] = i;
}

for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
board[x] = y;
}

for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
int u = Integer.parseInt(st.nextToken());
int v = Integer.parseInt(st.nextToken());
board[u] = v;
}

System.out.println(bfs());

}

private static int bfs() {
Queue<Integer> queue = new LinkedList<>();
queue.add(1);

while (!queue.isEmpty()) {
int now = queue.poll();

if (board[now] == 100) {
return visited[100];
}

for (int i = 1; i <= 6; i++) {
int next = now + i;
if (next > 100)
continue;
next = board[next];
if (visited[next] == 0) {
visited[next] = visited[now] + 1;
queue.add(next);
}
}
}

return -1;

}
}
35 changes: 35 additions & 0 deletions sohyeon/src/week24/boj17219.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package week24;

import java.io.*;
import java.util.*;

public class boj17219 {

static int N, M;

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

HashMap<String, String> map = new HashMap<>();

for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
String site = st.nextToken();
String password = st.nextToken();
map.put(site, password);
}

StringBuilder sb = new StringBuilder();
for (int i = 0; i < M; i++) {
String site = br.readLine();
sb.append(map.get(site)).append("\n");
}

System.out.println(sb);

}
}
28 changes: 28 additions & 0 deletions sohyeon/src/week24/boj17626.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package week24;

import java.io.*;
import java.util.*;

public class boj17626 {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());

int[] dp = new int[num + 1];
dp[1] = 1;

int min;
for (int i = 2; i <= num; i++) {
min = Integer.MAX_VALUE;
for (int j = 1; j * j <= i; j++) {
int temp = i - j * j;
min = Math.min(min, dp[temp]);
}
dp[i] = min + 1;
}

System.out.println(dp[num]);

}
}