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

[6주차] 이지영 #79

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
jewan100 merged 10 commits into GreatAlgorithm-Study:main from yeongleej:main
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit Hold shift + click to select a range
7eccea3
이지영: [CT] 테트리스 블럭 안의 합 최대화 하기_241014
yeongleej Oct 14, 2024
eff4a95
이지영: [BOJ] 2805 나무 자르기_241015
yeongleej Oct 15, 2024
98a4ede
이지영: [BOJ] 2110 공유기 설치_241015
yeongleej Oct 15, 2024
92c2344
이지영: [BOJ] 7579 앱_241016
yeongleej Oct 16, 2024
9f0ae35
이지영: [BOJ] 9084 동전_241016
yeongleej Oct 16, 2024
7627188
이지영: [PG] 43238 입국심사_241017
yeongleej Oct 17, 2024
6356a27
이지영: [SQL] 대장균들의 자식의 수 구하기_241015
yeongleej Oct 17, 2024
4d78dde
이지영: [SQL] 재구매가 일어난 상품과 회원 리스트 구하기_241017
yeongleej Oct 17, 2024
a4bb43b
이지영: [SQL] 주문량이 많은 아이스크림들 조회하기_241017
yeongleej Oct 17, 2024
92855e8
이지영: [PG] 42861 섬 연결하기_241018
yeongleej Oct 18, 2024
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
55 changes: 55 additions & 0 deletions BOJ/1000-5000번/JY_2110.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package day1015;

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

public class JY_2110 {

static int N, C;
static long[] wrr;

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());
C = Integer.parseInt(st.nextToken());

wrr = new long[N];
for(int i=0; i<N; i++) {
wrr[i] = Long.parseLong(br.readLine());
}

// 집위치 정렬
Arrays.sort(wrr);

long s = 0;
long e = (wrr[N-1] - wrr[0]);
while(s < e) {
// 인접한 두 공유기 사이의 거리
long mid = (s + e) / 2;

long nextPos = 0;
int cnt = 0;
for(int i=0; i<N; i++) {
// 공유기 새로 설치해야 함
if(wrr[i] >= nextPos) {
nextPos = wrr[i] + mid;
cnt++;
}
}

// 필요한 공유기수가 더 많거나 같으면 거리를 늘릴 수 있음
if(cnt >= C) {
s = mid + 1;
}
// 필요한 공유기수가 더 작으면 거리를 좁혀야 함
else {
e = mid;
}
}

System.out.println(e);
}

}
48 changes: 48 additions & 0 deletions BOJ/1000-5000번/JY_2805.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package day1015;

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

public class JY_2805 {

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[] trr = new int[N];
int maxH = Integer.MIN_VALUE;
st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++) {
trr[i] = Integer.parseInt(st.nextToken());
maxH = Math.max(maxH, trr[i]);
}


int s = 0;
int e = maxH;
int ans = 0;
while(s <= e) {
int mid = (s + e) / 2;

long total = 0;
for(int i=0; i<N; i++) {
if(trr[i] > mid) total += (trr[i]-mid);
}

// 자른길이가 M보다 작다면 높이를 더 낮게 설정해서 자른길이의 합을 늘려야 함
if(total < M) {
e = mid - 1;
} else {
ans = mid;
s = mid + 1;
}
}

System.out.println(ans);

}

}
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package day1014;

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

public class JY_테트리스_블럭_안의_합_최대화_하기 {

static int N, M;
static int[][] g;
static boolean[][] visited;
static int ans;
// 현재 그래프 값 중 가장 큰 것
static int maxValue;
static int[] dx = {0, 0, -1, 1};
static int[] dy = {-1, 1, 0, 0};


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 int[N][M];
maxValue = Integer.MIN_VALUE;
for(int i=0; i<N; i++) {
st = new StringTokenizer(br.readLine());
for(int j=0; j<M; j++) {
g[i][j] = Integer.parseInt(st.nextToken());
maxValue = Math.max(maxValue, g[i][j]);
}
}

visited = new boolean[N][M];
ans = Integer.MIN_VALUE;
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
visited[i][j] = true;
dfs(i, j, 1, g[i][j]);
visited[i][j] = false;
}
}

System.out.println(ans);

}
public static boolean inRange(int x, int y) {
return x>=0 && x<N && y>=0 && y<M;
}
public static void dfs(int x, int y, int depth, int total) {
// 4개의 블록 모두 탐색
if(depth == 4) {
ans = Math.max(ans, total);
return;
}
// 가지치기
// 현재까지 탐색한 결과에 앞으로 최댓값만 추가한다고 해도 ans값보다 작으면 탐색X
if(ans >= total+maxValue*(4-depth)) return;

for(int i=0; i<4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(!inRange(nx, ny)) continue;
if(visited[nx][ny]) continue;
// 2번째 블럭인 경우, ᅡ ᅥ ᅩ ᅮ 처럼 2번째 블록에서 연결된 2개의 블록을 찾아야한다.
if(depth == 2) {
visited[nx][ny] = true;
dfs(x, y, depth+1, total+g[nx][ny]);
visited[nx][ny] = false;
}

// 2번쨰 블록 이외에는 일반탐색
visited[nx][ny] = true;
dfs(nx, ny, depth+1, total+g[nx][ny]);
visited[nx][ny] = false;

}
}

}

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