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

최주은 / 16주차 #23

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5f01b7a
[BOJ] 예산 / 실버3 / 30분
jee-woo Mar 29, 2023
daf04d1
[BOJ] 나무 자르기 / 실버2 / 15분
jee-woo Mar 29, 2023
48e89f2
[BOJ] 랜선 자르기 / 실버2 / 1시간
jee-woo Mar 29, 2023
44a4272
IF문 좀 대신 써줘 / 실버3 / 1시간
jee-woo Mar 29, 2023
5a5e007
용돈 관리 / 실버2 / 1시간
jee-woo Mar 29, 2023
2f6ea9a
[BOJ] 안전 영역 / 실버1 / 20분
jee-woo Apr 5, 2023
5ee1503
[BOJ] 유기농 배추 / 실버2 / 1시간
jee-woo Apr 5, 2023
025d226
[BOJ] 연결 요소의 개수 / 실버2 / 1시간
jee-woo Apr 5, 2023
65bf5ad
[BOJ] 경로 찾기 / 실버1 / 1시간
jee-woo Apr 5, 2023
e7101e5
[BOJ] DOM / 실버2 / 40분
jee-woo Apr 5, 2023
f657d4c
[BOJ] DFS와 BFS / 실버2 / 1시간
jee-woo Apr 11, 2023
5478484
[BOJ] 유기농 배추 / 실버2 / 30분
jee-woo Apr 26, 2023
e7ca103
[BOJ] 촌수 계산 / 실버2 / 1시간
jee-woo Apr 26, 2023
49217fb
[BOJ] 미로 탐색 / 실버1 / 30분~1시간
jee-woo Apr 26, 2023
f640652
[BOJ] 나이트의 이동 / 실버1 / 30분
jee-woo Apr 26, 2023
dd55f3d
[BOJ] 2xn 타일링 / 실버3 / 15분
jee-woo May 3, 2023
5b9ddcd
[BOJ] 01타일 / 실버3 / 25분
jee-woo May 3, 2023
536a159
[BOJ] 돌 게임 / 실버5 / 20분
jee-woo May 3, 2023
c0de78d
[BOJ] 이친수 / 실버3 / 20분
jee-woo May 3, 2023
c8830d4
[BOJ] 1로 만들기 / 실버3 / 20분
jee-woo May 3, 2023
6473362
[BOJ] 진우의 달 여행 (Small) / 실버3 / 1시간 이내
jee-woo May 10, 2023
9566e70
[BOJ] 연속합 / 실버2 / 30분
jee-woo May 10, 2023
972914b
[BOJ] 부분수열의 합 / 실버2 / 30분 이상
jee-woo May 10, 2023
db5c204
[BOJ] 사탕 게임 / 실버2 / 1시간 이내 (레퍼런스 참고)
jee-woo May 10, 2023
dee1a5a
[BOJ] 숫자 야구 / 실버3 / 1시간 이상
jee-woo May 17, 2023
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
51 changes: 51 additions & 0 deletions jueun/week16/1654.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// const input = require("fs")
// .readFileSync("/dev/stdin")
// .toString()
// .trim()
// .split("\n");

const input = ["4 11", "802", "743", "457", "539"];
// const input = ["1 1", "5"];

const [[K, N], lanLines] = [
input[0].split(" ").map(BigInt),
input.slice(1).map(BigInt),
];

const solution = (lanLines, n) => {
let mid = bigIntMax(...lanLines);
let low = 0n,
high = mid;
let newMid;
let maxLength = 0n;
let nowCount;

while (true) {
nowCount = getNowCount(lanLines, mid);

if (nowCount < n) {
high = mid;
} else if (nowCount >= n) {
low = mid;
maxLength = bigIntMax(maxLength, mid);
}

newMid = BigInt(BigInt(low) + BigInt(high)) / 2n;

if (newMid === mid || newMid === low || newMid === high) break;
mid = newMid;
}

return maxLength;
};

const bigIntMin = (...args) =>
args.reduce((prev, cur) => (cur < prev ? cur : prev));

const bigIntMax = (...args) =>
args.reduce((prev, cur) => (cur > prev ? cur : prev));

const getNowCount = (lanLines, mid) =>
lanLines.reduce((prev, cur) => prev + cur / mid, 0n);

console.log(String(solution(lanLines, N)));
54 changes: 54 additions & 0 deletions jueun/week16/19637.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// const input = require("fs")
// .readFileSync("/dev/stdin")
// .toString()
// .trim()
// .split("\n");

const input = [
"3 8",
"WEAK 10000",
"NORMAL 100000",
"STRONG 1000000",
"0",
"9999",
"10000",
"10001",
"50000",
"100000",
"500000",
"1000000",
];

const [N, M] = input[0].split(" ").map(Number);
const [ranges, numbers] = [
input
.slice(1, N + 1)
.map((el) => el.split(" ").map((e) => (isNaN(e) ? e : +e))),
input.slice(N + 1).map(Number),
];

const solution = (n, m, ranges, numbers) => {
let answer = "";
for (let i = 0; i < m; i++) {
answer += ranges[findRangeIdx(numbers[i], n, ranges)][0] + "\n";
}
return answer;
};

const findRangeIdx = (target, n, ranges) => {
let mid = 0,
low = 0,
high = n - 1;
while (low <= high) {
mid = Math.floor((low + high) / 2);
if (target <= ranges[mid][1]) {
high = mid - 1;
} else {
low = mid + 1;
}
}
if (target > ranges[mid][1]) return mid + 1;
else return mid;
};

console.log(solution(N, M, ranges, numbers));
46 changes: 46 additions & 0 deletions jueun/week16/2512.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// const input = require("fs")
// .readFileSync("/dev/stdin")
// .toString()
// .trim()
// .split("\n")

// const input = ["4", "120 110 140 150", "485"];
const input = ["5", "70 80 30 40 100", "450"];

const [N, requests, M] = [
+input[0],
input[1].split(" ").map(Number),
+input[2],
];

const solution = (requests, m) => {
let mid = Math.max(...requests);
let newMid;
let high = mid,
low = 0;
let sum,
maxSum = 0;

while (true) {
sum = requests.reduce((prev, cur) => {
if (cur > mid) return prev + mid;
else return prev + cur;
}, 0);

if (sum > m) {
high = mid;
} else if (sum < m) {
low = mid;
maxSum = Math.max(sum, maxSum);
} else {
break;
}
newMid = Math.floor((low + high) / 2);
if (newMid === mid) break;
else mid = newMid;
}

return mid;
};

console.log(solution(requests, M));
46 changes: 46 additions & 0 deletions jueun/week16/2805.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// const input = require("fs")
// .readFileSync("/dev/stdin")
// .toString()
// .trim()
// .split("\n")

// const input = ["4 7", "20 15 10 17"];
const input = ["5 20", "4 42 40 26 46"];

const [[N, M], trees] = [
input[0].split(" ").map(Number),
input[1].split(" ").map(Number),
];

const solution = (trees, m) => {
const treeSum = trees.reduce((prev, cur) => prev + cur) - m;
let mid = Math.max(...trees);
let newMid;
let high = mid,
low = 0;
let sum,
maxSum = 0;

while (true) {
sum = trees.reduce((prev, cur) => {
if (cur > mid) return prev + mid;
else return prev + cur;
}, 0);

if (sum > treeSum) {
high = mid;
} else if (sum < treeSum) {
low = mid;
maxSum = Math.max(sum, maxSum);
} else {
break;
}
newMid = Math.floor((low + high) / 2);
if (newMid === mid) break;
else mid = newMid;
}

return mid;
};

console.log(solution(trees, M));
49 changes: 49 additions & 0 deletions jueun/week16/6236.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// const input = require("fs")
// .readFileSync("/dev/stdin")
// .toString()
// .trim()
// .split("\n");

const input = ["7 5", "100", "400", "300", "100", "500", "101", "400"];

const [[N, M], moneys] = [
input[0].split(" ").map(Number),
input.slice(1).map(Number),
];

const solution = (n, m, moneys) => {
let minMoney = moneys.reduce((prev, cur) => prev + cur);
let low = Math.max(...moneys),
high = minMoney;
let mid = high;
let count;

while (low <= high) {
count = getCount(n, mid, moneys);

if (count > m) {
low = mid + 1;
} else {
minMoney = mid;
high = mid - 1;
}
mid = Math.floor((low + high) / 2);
}

return minMoney;
};

const getCount = (n, mid, moneys) => {
let count = 0,
remain = 0;

for (let i = 0; i < n; i++) {
if (remain < moneys[i]) {
count++;
remain = mid - moneys[i];
} else remain -= moneys[i];
}
return count++;
};

console.log(solution(N, M, moneys));
52 changes: 52 additions & 0 deletions jueun/week17/2468.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const fs = require("fs");
const input = fs
.readFileSync(
process.platform === "linux" ? "/dev/stdin" : __dirname + "/2468.txt"
)
.toString()
.split("\n")
.map((el) => el.split(" ").map(Number));

const N = input[0][0];
const map = input.slice(1);

const solution = (n, map) => {
let maxCount = 0;

let visited = new Array(n);
for (let i = 0; i < n; i++) visited[i] = new Array(n).fill(false);

const dfs = (i, j, height) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 각 방향마다 dfs 함수를 호출하는 방법도 있네요

visited[i][j] = true;
if (map[i - 1]?.[j] >= height && !visited[i - 1]?.[j])
dfs(i - 1, j, height);
if (map[i + 1]?.[j] >= height && !visited[i + 1]?.[j])
dfs(i + 1, j, height);
if (map[i]?.[j - 1] >= height && !visited[i]?.[j - 1])
dfs(i, j - 1, height);
if (map[i]?.[j + 1] >= height && !visited[i]?.[j + 1])
dfs(i, j + 1, height);
};

let count;
for (let rainfall = 1; rainfall <= 100; rainfall++) {
count = 0;
visited = new Array(n);
for (let i = 0; i < n; i++) visited[i] = new Array(n).fill(false);

for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (map[i][j] >= rainfall && !visited[i][j]) {
dfs(i, j, rainfall);
count++;
}
}
}
maxCount = Math.max(maxCount, count);
if (count === 0) break;
}

return maxCount;
};

console.log(solution(N, map));