Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[21주차] 이지영 #292

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

Merged
yeongleej merged 4 commits into GreatAlgorithm-Study:main from yeongleej:main
Feb 5, 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
84 changes: 84 additions & 0 deletions BOJ/1000-5000번/JY_1939.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import java.io.*;
import java.util.*;

public class JY_1939 {

static int N, M;
static List<int[]>[] g;
static boolean[] visited;
static int ea, eb;
static boolean isOk;

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

N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

g = new ArrayList[N+1];
for(int i=1; i<N+1; i++) {
g[i] = new ArrayList<>();
}

int mc = 0;
for(int i=0; i<M; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());

g[a].add(new int[] {b, c});
g[b].add(new int[] {a, c});

if(mc < c) {
mc = c;
}
}

st = new StringTokenizer(br.readLine());
ea = Integer.parseInt(st.nextToken());
eb = Integer.parseInt(st.nextToken());


// 0~최대 중량 제한 중 최대값 찾기
int s = 0;
int e = mc;
int ans = 0;
while(s <= e) {
int mid = (s + e) / 2;

visited = new boolean[N+1];
isOk = false;

// 현제 중량제한 값(mid)으로 ea->eb로 갈 수 있는지 탐색
canGo(ea, mid);
if(isOk) {
ans = mid;
s = mid + 1;
} else {
e = mid - 1;
}

}

System.out.println(ans);
}
public static void canGo(int now, int cost) {
if(now == eb) {
isOk = true;
return;
}

visited[now] = true;

for(int[] next : g[now]) {
if(visited[next[0]]) continue;
if(next[1] < cost) continue;

canGo(next[0], cost);
}

}

}
59 changes: 59 additions & 0 deletions BOJ/1000-5000번/JY_2169.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import java.io.*;
import java.util.*;
public class JY_2169 {

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

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] g = new int[N+1][M+1];
int[][] dp = new int[N+1][M+1];
for(int i=1; i<N+1; i++) {
st = new StringTokenizer(br.readLine());
for(int j=1; j<M+1; j++) {
g[i][j] = Integer.parseInt(st.nextToken());
}
}


// 첫행만 오른쪽으로 누적
for(int j=1; j<M+1; j++) {
dp[1][j] = dp[1][j-1] + g[1][j];
}


for(int i=2; i<N+1; i++) {
// t1: 왼->오
int[] t1 = new int[M+1];
// t2: 오-> 왼
int[] t2 = new int[M+1];

t1[1] = dp[i-1][1] + g[i][1];
for(int j=2; j<M+1; j++) {
t1[j] = Math.max(dp[i-1][j], t1[j-1]) + g[i][j];
}

t2[M] = dp[i-1][M] + g[i][M];
for(int j=M-1; j>=0; j--) {
t2[j] = Math.max(dp[i-1][j], t2[j+1]) + g[i][j];
}

// dp에 반영
for(int j=1; j<M+1; j++) {
dp[i][j] = Math.max(t1[j], t2[j]);
}

}


System.out.println(dp[N][M]);





}

}
143 changes: 143 additions & 0 deletions CodeTree/2015-2016년/JY_2개의_사탕.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import java.io.*;
import java.util.*;
public class JY_2개의_사탕 {

static int N, M;
static char[][] g;
// 상 하 좌 우
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};
static class Candy {
int x, y;

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

@Override
public String toString() {
return "Candy [x=" + x + ", y=" + y + "]";
}

}
static int ans;

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

N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

g = new char[N][M];
Candy red = new Candy(-1, -1);
Candy blue = new Candy(-1, -1);

for(int i=0; i<N; i++) {
String line = br.readLine();
for(int j=0; j<M; j++) {
g[i][j] = line.charAt(j);
if(g[i][j] == 'R') {
red.x = i;
red.y = j;
g[i][j] = '.';
} else if(g[i][j] == 'B') {
blue.x = i;
blue.y = j;
g[i][j] = '.';
}
}
}

ans = Integer.MAX_VALUE;
exit(red, blue, 0);

if(ans > 10) System.out.println(-1);
else System.out.println(ans);


}
public static void printG() {
for(int i=0; i<N; i++) {
System.out.println(Arrays.toString(g[i]));
}
System.out.println();
}
public static void exit(Candy r, Candy b, int cnt) {
// 파란 캔디가 먼저 도착점에 도달
if(g[b.x][b.y] == 'O') return;
// 빨간 캔디가 도착점에 도달
if(g[r.x][r.y] == 'O') {
ans = Math.min(ans, cnt);
return;
}
if(cnt > 10) return;
// 이미 구해진 값보다 많다면 중단
if(cnt > ans) return;

for(int i=0; i<4; i++) {
Candy nr = move(r, i);
Candy nb = move(b, i);

// 둘 위치가 같음 -> 위치 재조정
if(nr.x == nb.x && nr.y == nb.y) {
// 같은 위치가 도착점이면 X
if(g[nr.x][nr.y] == 'O') continue;
// 상
if(i == 0) {
if(r.x < b.x) {
nb.x += 1;
} else {
nr.x += 1;
}
}
// 하
else if(i == 1) {
if(r.x > b.x) {
nb.x -= 1;
} else {
nr.x -= 1;
}
}
// 좌
else if(i == 2) {
if(r.y < b.y) {
nb.y += 1;
} else {
nr.y += 1;
}
}
// 우
else {
if(r.y > b.y) {
nb.y -= 1;
} else {
nr.y -= 1;
}
}
}
if(r.x == nr.x && r.y == nr.y && b.x == nb.x && b.y == nb.y) continue;
exit(nr, nb, cnt+1);


}
}
public static Candy move(Candy c, int dir) {
Candy nc = new Candy(c.x, c.y);
while(true) {
// 현제 위치가 도착점이면 중단
if(g[nc.x][nc.y] == 'O') break;
int nx = nc.x + dx[dir];
int ny = nc.y + dy[dir];

// 다음이 벽이면 중단
if(g[nx][ny] == '#') break;
nc.x = nx;
nc.y = ny;
}
return nc;
}

}

AltStyle によって変換されたページ (->オリジナル) /