From 3aef1ba82f8735632a8b9eccad89520adca7c5fc Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 18 Jul 2024 19:40:27 +0900 Subject: [PATCH 1/5] =?UTF-8?q?2024-07-18=20=EB=9E=9C=EC=84=A0=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 6 ++-- .../1654.cpp" | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 "oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" diff --git a/oesnuj/README.md b/oesnuj/README.md index f16f53f..40d165d 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -6,9 +6,11 @@ | 2차시 | 2024.03.29 | 연결리스트 | [에디터](https://www.acmicpc.net/problem/1406) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/8) | | 3차시 | 2024.04.02 | 덱 | [카드 놓기](https://www.acmicpc.net/problem/18115) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/11) | | 4차시 | 2024.04.06 | 스택 | [옥상 정원 꾸미기](https://www.acmicpc.net/problem/6198) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/14) | -| 5차시 | 2024.04.13 | 이분탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) | -| 6차시 | 2024.05.06 | 기하학 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) | +| 5차시 | 2024.04.13 | 이분 탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) | +| 6차시 | 2024.05.06 | 기하 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) | | 7차시 | 2024.05.08 | 스택, 큐, 덱 | [queuestack](https://www.acmicpc.net/problem/24511) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/24) | | 8차시 | 2024.05.13 | 우선순위 큐 | [카드 정렬하기](https://www.acmicpc.net/problem/1715) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/27) | | 9차시 | 2024.05.30 | 구현 | [빙고](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) | +| 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) | +| 11차시 | 2024.07.18 | 매개 변수 탐색 | [랜선 자르기](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) | --- diff --git "a/oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" "b/oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" new file mode 100644 index 0000000..5ced40d --- /dev/null +++ "b/oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" @@ -0,0 +1,35 @@ +#include +#include +using namespace std; + +bool check(vector & v, int n, long long length); +int binary_serach(vector & v, int n); + +int main() { + int k, n; + cin >> k >> n; + vector trees(k); + for (auto& i : trees) { + cin >> i; + } + cout << binary_serach(trees, n); + return 0; +} + +bool check(vector & v, int n, long long length) { + int cnt = 0; + for (const auto& i : v) { + cnt += i / length; + } + return cnt >= n; +} + +int binary_serach(vector & v, int n) { + long long lo = 1, hi = 2147483648; //자를 수 있는 랜선의 범위 + while (lo + 1 < hi) { + long long mid = (lo + hi) / 2; + if (check(v, n, mid)) lo = mid; + else hi = mid; + } + return lo; +} \ No newline at end of file From 304cf753b79b9d8194c1f999b0fab973ee9c7f63 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 18 Jul 2024 19:42:47 +0900 Subject: [PATCH 2/5] Create 21608.js --- "oesnuj/\352\265\254\355\230\204/21608.js" | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "oesnuj/\352\265\254\355\230\204/21608.js" diff --git "a/oesnuj/\352\265\254\355\230\204/21608.js" "b/oesnuj/\352\265\254\355\230\204/21608.js" new file mode 100644 index 0000000..f2d2375 --- /dev/null +++ "b/oesnuj/\352\265\254\355\230\204/21608.js" @@ -0,0 +1,77 @@ +const fs = require('fs'); +const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; +const input = fs.readFileSync(filepath).toString().trim().split('\n'); +//입력 데이터 정리 +const N = +input.shift(); +const students = input.map(x => { + const [num, ...likes] = x.trim().split(' ').map(Number); + return { num, likes }; +}); + +let board = Array.from({ length: N }, () => Array(N).fill(0)); + +const dr = [-1, 1, 0, 0]; +const dc = [0, 0, -1, 1]; + +main(); + +function main(){ + for(let i=0; i< N**2; i++){ + if(i == 0){ + board[1][1] = students[i].num; //첫학생은 1,1에 무조건 앉는다. + continue; + } + choiceSeat(students[i].num); //학생을 조건에 맞게 앉히기 + } + console.log(calcSatisfy()); //모두 앉은 후 만족도 계산하기 +} + +// 최적의 자리 선택 및 학생 배치 함수 +function choiceSeat(studentNum){ + const neighborInfos = []; //인접 자리 정보를 모으는 배열 + for(let i = 0; i { + if (a.match !== b.match) { + return b.match - a.match; // match 기준 내림차순 정렬 + } else if (a.empty !== b.empty) { + return b.empty - a.empty; // empty 기준 내림차순 정렬 + } else if (a.r !== b.r) { + return a.r - b.r; // r 기준 오름차순 정렬 + } else { + return a.c - b.c; // c 기준 오름차순 정렬 + } + }); + board[neighborInfos[0].r][neighborInfos[0].c] = studentNum; //최적의 위치에 앉히기 +} + +// 특정 자리의 인접 정보 계산 함수 +function getSeatInfo(r, c, studentNum){ + let empty = 0; + let match = 0; + // 학생 번호에 맞는 좋아하는 학생들 찾기 + let studentLikes = students.find(student => student.num === studentNum)?.likes || []; + for(let i = 0; i< 4; i++){ + nr = r + dr[i]; + nc= c + dc[i]; + if(nr < 0 || nc < 0 || nr >= N || nc >= N) continue; + if (board[nr][nc] == 0) empty++; + else if(studentLikes.includes(board[nr][nc])) match++ + } + return { r: r, c: c, empty: empty, match: match }; +} + +//만족도 처리 +function calcSatisfy(){ + let result = 0; + for(let i = 0; i Date: Thu, 18 Jul 2024 19:43:49 +0900 Subject: [PATCH 3/5] =?UTF-8?q?2024-07-18=20=EB=9E=9C=EC=84=A0=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1654.cpp" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" => "oesnuj/\353\247\244\352\260\234 \353\263\200\354\210\230 \355\203\220\354\203\211/1654.cpp" (100%) diff --git "a/oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" "b/oesnuj/\353\247\244\352\260\234 \353\263\200\354\210\230 \355\203\220\354\203\211/1654.cpp" similarity index 100% rename from "oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1654.cpp" rename to "oesnuj/\353\247\244\352\260\234 \353\263\200\354\210\230 \355\203\220\354\203\211/1654.cpp" From 988d323d4c01dc63f34c0f253e55d964e61afff4 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Thu, 18 Jul 2024 19:55:58 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EB=A6=AC=EB=93=9C=EB=AF=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 2 +- .../\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" | 0 .../\354\235\264\353\266\204 \355\203\220\354\203\211/1764.cpp" | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename "oesnuj/\353\247\244\352\260\234 \353\263\200\354\210\230 \355\203\220\354\203\211/1654.cpp" => "oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" (100%) rename "oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1764.cpp" => "oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1764.cpp" (100%) diff --git a/oesnuj/README.md b/oesnuj/README.md index 40d165d..1052526 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -12,5 +12,5 @@ | 8차시 | 2024.05.13 | 우선순위 큐 | [카드 정렬하기](https://www.acmicpc.net/problem/1715) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/27) | | 9차시 | 2024.05.30 | 구현 | [빙고](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) | | 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) | -| 11차시 | 2024.07.18 | 매개 변수 탐색 | [랜선 자르기](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) | +| 11차시 | 2024.07.18 | 이분 탐색 | [랜선 자르기](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) | --- diff --git "a/oesnuj/\353\247\244\352\260\234 \353\263\200\354\210\230 \355\203\220\354\203\211/1654.cpp" "b/oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" similarity index 100% rename from "oesnuj/\353\247\244\352\260\234 \353\263\200\354\210\230 \355\203\220\354\203\211/1654.cpp" rename to "oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" diff --git "a/oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1764.cpp" "b/oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1764.cpp" similarity index 100% rename from "oesnuj/\354\235\264\353\266\204\355\203\220\354\203\211/1764.cpp" rename to "oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1764.cpp" From 48b2dd7f4eacce12cbd3849f1dbdd7333861adbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A4=80=EC=84=9C=20Junseo=20Kim?= Date: Sat, 20 Jul 2024 21:31:27 +0900 Subject: [PATCH 5/5] Update 1654.cpp --- .../1654.cpp" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" "b/oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" index 5ced40d..68051b4 100644 --- "a/oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" +++ "b/oesnuj/\354\235\264\353\266\204 \355\203\220\354\203\211/1654.cpp" @@ -8,11 +8,11 @@ int binary_serach(vector & v, int n); int main() { int k, n; cin >> k >> n; - vector trees(k); - for (auto& i : trees) { + vector v(k); + for (auto& i : v) { cin >> i; } - cout << binary_serach(trees, n); + cout << binary_serach(v, n); return 0; } @@ -32,4 +32,4 @@ int binary_serach(vector & v, int n) { else hi = mid; } return lo; -} \ No newline at end of file +}