-
Notifications
You must be signed in to change notification settings - Fork 9
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
김현정 / 17주차 #25
Open
sena-22
wants to merge
27
commits into
algorithm-tear-up-20b:main
Choose a base branch
from
sena-22:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
김현정 / 17주차 #25
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8189665
[BOJ] 예산 / 실버3 / 1시간
sena-22 20ee6e0
[BOJ] 나무자르기 / 실버2 / ?
sena-22 6d1d911
[BOJ] 용돈관리 / 실버2 / 1시간
sena-22 f44974a
[BOJ] 연결요소의 개수 / 실버2
sena-22 285637c
[BOJ] 유기농 배추 / 실버2
sena-22 30bceb2
[BOJ] 경로 찾기 / 실버1
sena-22 133b1c7
[BOJ] 안전영역 / 실버1
sena-22 810b2a2
[BOJ] DOM / 실버2
sena-22 841fe3e
[BOJ] DOM / 실버 2
sena-22 e3d47a2
[BOJ] 미로 탐색 / 실버1 / 1시간
sena-22 22c00da
[BOJ] 유기농 배추 / 실버2 / 40분
sena-22 c91ed11
[BOJ] DFS와 BFS / 실버2 / Error
sena-22 a0e615e
[BOJ] 돌게임/ 실버5 / 40분
sena-22 351fa85
[BOJ] 1로 만들기 / 실버3 / 40분
sena-22 3a76470
[BOJ] 이친수 / 실버3 / 80분
sena-22 e1dd991
[BOJ] 촌수계산 / 실버2 / 1시간
sena-22 603462e
[BOJ] 01타일 / 실버3 / 40분
sena-22 95ecb29
[BOJ] 2xn 타일링 / 실버 3 / 20분
sena-22 6e7d52b
[BOJ] 사탕게임 / 실버3 / 80분
sena-22 fc58bce
[BOJ] 부분수열의 합 / 실버2 / 40분
sena-22 fbea347
[BOJ] 연속합 / 실버 2 / 1시간
sena-22 0bc9785
[BOJ] 진우의 달 여행 / 실버4 / 2시간?
sena-22 a1dad2a
[BOJ] 부분합 / 골드4 / 1시간
sena-22 6ecfd55
[BOJ] 좋다 / 골드4 / 1시간
sena-22 9709d2d
[BOJ] 숫자야구 / 실버3 / ?
sena-22 cf60447
[BOJ] List of Unique Numbers / 골드5 / 시간 초과
sena-22 0e2cb5f
[BOJ] List of Unique Numbers / 골드5 / ?
sena-22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
|
||
const [n, m] = input[0].split(" ").map(Number) | ||
const arr = input[1].split(" ").map(Number) | ||
|
||
function solution(n, m, trees) { | ||
arr.sort((a, b) => a - b) | ||
let height = 0 | ||
start = 0 | ||
end = Math.max(...trees) | ||
|
||
for (let i = 0; i < n; i++) { | ||
while (start <= end) { | ||
let mid = Math.floor((start + end) / 2) | ||
let woodSum = 0 | ||
trees.forEach((tree) => { | ||
let wood = tree - mid | ||
if (wood > 0) woodSum += wood | ||
}) | ||
if (woodSum >= m) { | ||
if (mid > height) height = mid | ||
start = mid + 1 | ||
} else { | ||
end = mid - 1 | ||
} | ||
} | ||
} | ||
return height | ||
} | ||
//제출 | ||
const answer = solution(n, m, arr) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
|
||
let [n, arr, budget] = [+input[0], input[1].split(" ").map(Number), +input[2]] | ||
|
||
const solution = (n, arr, budget) => { | ||
arr = arr.sort((a, b) => a - b) | ||
|
||
let start = 0 | ||
let end = arr.at(-1) | ||
|
||
while (start <= end) { | ||
let mid = parseInt((start + end) / 2) | ||
let sum = 0 | ||
for (let i = 0; i < n; i++) { | ||
if (arr[i] > mid) { | ||
//요청금액 > 상한액 | ||
sum += mid //상한액 더하기 | ||
} else { | ||
//요청금액 < 상한액 | ||
sum += arr[i] //요청금액 더하기 | ||
} | ||
} | ||
sum <= budget ? (start = mid + 1) : (end = mid - 1) //총액이 예산보다 작으면 최소금액 증가, 크면 최소금액 감소 | ||
} | ||
return end | ||
} | ||
|
||
const answer = solution(n, arr, budget) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
|
||
let [n, m] = input[0].split(" ") | ||
const arr = input.slice(1).map(Number) | ||
|
||
n = +n | ||
m = +m | ||
|
||
const solution = (days, withdrawal, A) => { | ||
let start = Math.min(...A) | ||
let end = A.reduce((a, c) => a + c, 0) | ||
let K = Infinity | ||
|
||
while (start <= end) { | ||
let min = 0 | ||
let mid = Math.floor((start + end) / 2) | ||
let sum = mid | ||
let cnt = 0 | ||
|
||
for (let i = 0; i < days; i++) { | ||
if (sum - A[i] >= 0) { | ||
sum -= A[i] | ||
} else { | ||
cnt++ | ||
sum = mid - A[i] | ||
if (sum < 0) { | ||
min = A[i] | ||
break | ||
} | ||
} | ||
} | ||
if (min > 0) { | ||
start = min | ||
continue | ||
} | ||
|
||
if (sum < mid) cnt++ | ||
if (cnt <= withdrawal) { | ||
if (K > mid) { | ||
K = mid | ||
} | ||
end = mid - 1 | ||
} else { | ||
start = mid + 1 | ||
} | ||
} | ||
return K | ||
} | ||
|
||
// 제출 | ||
const answer = solution(n, m, arr) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//시간 초과 | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
const [n, m, p] = input[0].split(" ").map(Number) | ||
const channels = input.slice(1).map((el) => el.split(" ").map(Number)) | ||
|
||
const solution = (n, m, p, channels) => { | ||
let curChannel = p | ||
let cnt = 0 | ||
let searched = new Array(m + 1).fill(false) | ||
|
||
const changeChannel = (channels, curChannel) => { | ||
if (searched[curChannel]) { | ||
return (cnt = -1) | ||
} | ||
searched[curChannel] = true | ||
|
||
for (let i = 0; i < channels.length; i++) { | ||
if (channels[i][1] === curChannel) { | ||
//현재 채널이 싫어하는 채널이면 | ||
curChannel = channels[i][0] //좋아하는 채널로 변경 | ||
|
||
if (searched[curChannel]) { | ||
// 변경한 채널이 검색한 채널이면 리턴 | ||
return (cnt = -1) | ||
} else { | ||
cnt++ | ||
return changeChannel(channels, curChannel) | ||
} | ||
} | ||
} | ||
} | ||
|
||
changeChannel(channels, curChannel) | ||
|
||
return cnt | ||
} | ||
|
||
//제출 | ||
const answer = solution(n, m, p, channels) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
const [n, m, p] = input[0].split(" ").map(Number) | ||
const channels = input.slice(1).map((el) => el.split(" ").map(Number)) | ||
|
||
const solution = (n, m, first, channels) => { | ||
let A = [] | ||
let cnt = 0 | ||
|
||
let visited = [...Array(m + 1)].fill(false) | ||
for (let i = 1; i <= m; i++) { | ||
A[i] = [] | ||
} | ||
|
||
for (let i = 0; i < n; i++) { | ||
let [like, hate] = channels[i] | ||
if (A[hate].length === 0) A[hate] = like | ||
} | ||
|
||
const DFS = (node) => { | ||
if (visited[node]) return -1 | ||
visited[node] = true | ||
for (let i = 1; i <= m; i++) { | ||
if (A[node] === i) { | ||
cnt++ | ||
return DFS(i) | ||
} | ||
} | ||
} | ||
|
||
if (DFS(first) === -1) return -1 | ||
return cnt | ||
} | ||
|
||
const answer = solution(n, m, p, channels) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
let n = input[0] | ||
n = +n | ||
const graph = input.slice(1).map((el) => el.split(" ").map(Number)) | ||
|
||
const solution = (n, graph) => { | ||
const result = [...Array(n)].map(() => Array(n).fill(0)) // 답을 저장할 2차원 배열 | ||
|
||
const DFS = (edge, line, visited) => { | ||
for (let i = 0; i < n; i++) { | ||
if (graph[edge][i] && !visited[i]) { | ||
visited[i] = true | ||
result[line][i] = 1 | ||
DFS(i, line, visited) //line은 계속 고정 | ||
} | ||
} | ||
} | ||
|
||
for (let i = 0; i < n; i++) { | ||
const visited = new Array(n).fill(false) | ||
DFS(i, i, visited) | ||
} | ||
return result.map((v) => v.join(" ")).join("\n") | ||
} | ||
|
||
const answer = solution(n, graph) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
let n = input[0] | ||
n = +n | ||
const map = input.slice(1).map((el) => el.split(" ").map(Number)) | ||
|
||
const solution = (n, area) => { | ||
let max = 0 | ||
|
||
const DFS = (row, col, h, visited) => { | ||
let dx = [0, 1, 0, -1] | ||
let dy = [1, 0, -1, 0] | ||
|
||
for (let i = 0; i < 4; i++) { | ||
let ax = row + dx[i], | ||
ay = col + dy[i] | ||
if (ax >= 0 && ay >= 0 && ax < n && ay < n) { | ||
if (!visited[ax][ay]) { | ||
visited[ax][ay] = true | ||
DFS(ax, ay, h, visited) | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (let h = 0; h <= 100; h++) { | ||
let cnt = 0 | ||
const visited = [...Array(n)].map((_, x) => | ||
[...Array(n)].map((_, y) => area[x][y] <= h) | ||
) | ||
for (let row = 0; row < n; row++) { | ||
for (let col = 0; col < n; col++) { | ||
if (!visited[row][col]) { | ||
visited[row][col] = true | ||
DFS(row, col, h, visited) | ||
cnt++ | ||
} | ||
} | ||
} | ||
max = Math.max(max, cnt) | ||
} | ||
|
||
return max | ||
} | ||
|
||
const answer = solution(n, map) | ||
console.log(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require("fs") | ||
const readFileSyncAddress = "/dev/stdin" | ||
const input = fs.readFileSync(readFileSyncAddress).toString().trim().split("\n") | ||
const [n, m] = input[0].split(" ").map(Number) | ||
|
||
const solution = (n, m, input) => { | ||
let A = [] | ||
let cnt = 0 | ||
let visited = new Array(n + 1).fill(false) | ||
|
||
for (let i = 1; i < n + 1; i++) { | ||
A[i] = [] | ||
} | ||
|
||
//A 인접 리스트에 그래프 데이터 저장하기 | ||
for (let i = 0; i < m; i++) { | ||
let [from, to] = input[i + 1].split(" ").map(Number) | ||
A[from].push(to) | ||
A[to].push(from) | ||
} | ||
|
||
const DFS = (start) => { | ||
if (visited[start]) return | ||
visited[start] = true //방문처리 | ||
|
||
for (let i = 0; i < A[start].length; i++) { | ||
const next = A[start][i] | ||
if (!visited[next]) { | ||
DFS(next) //방문하지 않은 노드만 탐색 | ||
} | ||
} | ||
} | ||
|
||
for (let i = 1; i <= n; i++) { | ||
if (!visited[i]) { | ||
DFS(i) //방문하지 않은 노드가 있으면 dfs실행 | ||
cnt++ //연결 요소 개수++ | ||
} | ||
} | ||
|
||
return cnt | ||
} | ||
|
||
//제출 | ||
const answer = solution(n, m, input) | ||
console.log(answer) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런식으로 2차원 배열을 생성할 수 있군요...!