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

14-jung0115 #165

Merged
merged 15 commits into from
Nov 21, 2024
Merged
36 changes: 0 additions & 36 deletions janghw0126/브루트 포스/퇴사.py

This file was deleted.

3 changes: 2 additions & 1 deletion jung0115/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.jars
*.jar
*.jar
*.class
11 changes: 10 additions & 1 deletion jung0115/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
| 2차시 | 2024.07.20.토 | 백트래킹 | [우주 탐사선(17182)](https://www.acmicpc.net/problem/17182) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/125 |
| 3차시 | 2024.07.24.수 | 이분 탐색 | [휴게소 세우기(1477)](https://www.acmicpc.net/problem/1477) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/129 |
| 4차시 | 2024.07.27.토 | 트리 / 트라이 | [개미굴(14725)](https://www.acmicpc.net/problem/14725) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/134 |
| 5차시 | 2024.07.31.수 | 트리 / MST | [1251. [S/W 문제해결 응용] 4일차 - 하나로](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15StKqAQkCFAYD) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/137 |
| 5차시 | 2024.07.31.수 | 트리 / MST | [1251. [S/W 문제해결 응용] 4일차 - 하나로](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15StKqAQkCFAYD) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/137 |
| 6차시 | 2024.08.03.토 | 트리 / 트라이 | [디스크 트리(7432)](https://www.acmicpc.net/problem/7432) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/142 |
| 7차시 | 2024.08.07.수 | 다익스트라 | [지형 이동(Lv.4)](https://school.programmers.co.kr/learn/courses/30/lessons/62050) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/144 |
| 8차시 | 2024.08.19.월 | 이분 탐색 | [입국심사(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/43238) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/148 |
| 9차시 | 2024.08.27.화 | 수학 | [음식 평론가(1188)](https://www.acmicpc.net/problem/1188) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/150 |
| 10차시 | 2024.08.28.수 | 브루트포스 | [램프(1034)](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/151 |
| 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 |
| 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 |
| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 |
| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 |
66 changes: 66 additions & 0 deletions jung0115/그리디알고리즘/Baekjoon_1781.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 14차시 2024.09.25.수 : 백준 - 컵라면(1781)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Baekjoon_1781 {
static class CupNoodle implements Comparable<CupNoodle> {
int deadLine;
int count;

public CupNoodle(int deadLine, int count) {
this.deadLine = deadLine;
this.count = count;
}

@Override
public int compareTo(CupNoodle o) {
// 데드라인을 기준으로 오름차순 정렬
return this.deadLine - o.deadLine;
}
}

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

int N = Integer.parseInt(br.readLine());

CupNoodle[] cupNoodles = new CupNoodle[N];

for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());

int deadLine = Integer.parseInt(st.nextToken()); // 데드라인
int count = Integer.parseInt(st.nextToken()); // 맞힐 때 받는 컵라면 수

cupNoodles[i] = new CupNoodle(deadLine, count);
}

// 데드라인을 기준으로 정렬 (오름차순)
Arrays.sort(cupNoodles);

PriorityQueue<Integer> pq = new PriorityQueue<>();

for (CupNoodle cn : cupNoodles) {
// 만약 현재 데드라인 내에 풀 수 있는 문제라면 큐에 추가
pq.offer(cn.count);

// 큐의 크기가 데드라인을 초과하면 가장 적은 컵라면 수를 제거
if (pq.size() > cn.deadLine) {
pq.poll();
}
}

int answer = 0;

// 큐에 남아 있는 컵라면의 총합을 구함
while (!pq.isEmpty()) {
answer += pq.poll();
}

System.out.println(answer);
}
}
37 changes: 37 additions & 0 deletions jung0115/그리디알고리즘/Baekjoon_1781_fail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 14차시 2024.09.25.수 : 백준 - 컵라면(1781)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.Iterator;

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

int N = Integer.parseInt(br.readLine());

HashMap<Integer, Integer> cupNoodles = new HashMap<Integer, Integer>();

for(int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());

int deadLine = Integer.parseInt(st.nextToken()); // 데드라인
int count = Integer.parseInt(st.nextToken()); // 맞힐 때 받는 컵라면 수

int current = cupNoodles.getOrDefault(deadLine, 0);
if(current < count) cupNoodles.put(deadLine, count);
}

int answer = 0;

Iterator<Integer> keys = cupNoodles.keySet().iterator();
while(keys.hasNext()){
int key = keys.next();
answer += cupNoodles.get(key);
}

System.out.print(answer);
}
}
55 changes: 55 additions & 0 deletions jung0115/다이나믹프로그래밍/Baekjoon_1256.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package jung0115.다이나믹프로그래밍;
// 13차시 2024.09.23.월 : 백준 - 사전(1256)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

int N = Integer.parseInt(st.nextToken()); // a의 개수
int M = Integer.parseInt(st.nextToken()); // z의 개수
int K = Integer.parseInt(st.nextToken()); // 몇 번째 문자열을 찾아야 하는지

StringBuilder answer = new StringBuilder();

long[][] dp = new long[ N + M + 1 ][ N + M + 1 ];
dp[0][0] = 1;

for(int i = 1;i <= N + M; i++){
dp[i][0] = 1;
dp[i][i] = 1;
for(int j = 1; j < i; j++){
dp[i][j] = dp[i-1][j-1] + dp[i-1][j];

if(dp[i][j] > 1000000000)
dp[i][j] = 1000000001;
}
}

// 사전에 수록되어 있는 문자열의 개수가 K보다 작을 경우
if(dp[N + M][M] < K) {
answer.append("-1");
}
else {
while (N != 0 || M != 0) {
if(dp[N + M - 1][M] >= K) {
answer.append("a");
N--;
}
else {
answer.append("z");
K -= dp[N + M - 1][M];
M--;
}
}
}

System.out.print(answer);

}
}
37 changes: 37 additions & 0 deletions jung0115/다이나믹프로그래밍/Baekjoon_1563.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 12차시 2024.09.07.토 : 백준 - 개근상(1563)
import java.io.BufferedReader
import java.io.InputStreamReader


fun main() {
// ✅ Input
val br = BufferedReader(InputStreamReader(System.`in`))

val N = br.readLine().toInt()

// ✅ Solve
// 출석 일수, 지각 일수, 연속 결석 일수
val dp = Array(N + 1, {Array(2, {Array(3, {0})})})

dp[1][0][0] = 1
dp[1][1][0] = 1
dp[1][0][1] = 1

for(i: Int in 2..N) {
dp[i][0][0] = (dp[i-1][0][0] + dp[i-1][0][1] + dp[i-1][0][2]) % 1000000;
dp[i][0][1] = dp[i-1][0][0] % 1000000;
dp[i][0][2] = dp[i-1][0][1] % 1000000;
dp[i][1][0] = (dp[i][0][0] + dp[i-1][1][0] + dp[i-1][1][1] + dp[i-1][1][2]) % 1000000;
dp[i][1][1] = dp[i-1][1][0] % 1000000;
dp[i][1][2] = dp[i-1][1][1] % 1000000;
}

var answer = 0
for(i: Int in 0..1) {
for(j: Int in 0..2) {
answer += dp[N][i][j]
}
}

print(answer % 1000000)
}
72 changes: 72 additions & 0 deletions jung0115/다익스트라/Programmers_62050.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 7차시 2024.08.07.수 : 프로그래머스 - 지형 이동(Lv.4)
import java.util.PriorityQueue;
import java.util.Queue;

class Solution {
public int solution(int[][] land, int height) {
int answer = 0;
int N = land.length;

int[] dx = {1, 0, -1, 0};
int[] dy = {0, 1, 0, -1};

boolean[][] visited = new boolean[N][N];

// 우선순위 큐
Queue<Point> queue = new PriorityQueue<>();
queue.add(new Point(0, 0, 0));

while (!queue.isEmpty()) {
Point current = queue.poll();

// 이미 방문한 곳
if (visited[current.x][current.y]) continue;

// 방문 표시, 비용 추가
visited[current.x][current.y] = true;
answer += current.cost;

// 상하좌우 이동
for (int i = 0; i < 4; i++) {
int moveX = current.x + dx[i];
int moveY = current.y + dy[i];

// 범위를 벗어나는 경우
if (moveX < 0 || moveY < 0 || moveX >= N || moveY >= N) continue;

// 높이 차이
int cost = Math.abs(land[current.x][current.y] - land[moveX][moveY]);

// 사다리가 필요한 경우
if (cost > height) {
queue.add(new Point(moveX, moveY, cost));
continue;
}

// 사다리가 필요없는 경우
queue.add(new Point(moveX, moveY, 0));
}
}


return answer;
}

class Point implements Comparable<Point> {
int x;
int y;
int cost;

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

// 우선순위: 비용이 작은 순
@Override
public int compareTo(Point o) {
return this.cost - o.cost;
}
}
}
49 changes: 49 additions & 0 deletions jung0115/브루트포스/Baekjoon_1034.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 10차시 2024.08.28.수 : 백준 - 램프(1034)
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import kotlin.math.max

fun main() {
// ✅ Input
val br = BufferedReader(InputStreamReader(System.`in`))
var st = StringTokenizer(br.readLine())

val N = st.nextToken().toInt()
val M = st.nextToken().toInt()

val lamp = mutableListOf<String>()
for(i: Int in 1..N) {
lamp.add(br.readLine())
}

val K = br.readLine().toInt()

var answer = 0
for(i: Int in 0..N-1) {
// 꺼져있는 램프 수
var zeroCount = 0
for(j: Int in 0..M-1) {
if(lamp[i][j] == '0') zeroCount++
}

// 불이 다 켜진 행의 수
var rowCount = 0
if(zeroCount <= K && zeroCount % 2 == K % 2) {
for(j: Int in 0..N-1) {
var isEqual = true
for(k: Int in 0..M-1) {
if(lamp[i][k] != lamp[j][k]) {
isEqual = false
break
}
}
if(isEqual) rowCount++
}

answer = max(answer, rowCount)
}
}

print(answer)
}
Loading