From 42c996ddf3a29d361689968f6aac42a1b6b4cffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=ED=98=84?= Date: Sat, 13 Jul 2024 10:44:52 +0900 Subject: [PATCH 1/9] =?UTF-8?q?2024-07-13=20=ED=94=8C=EB=A1=9C=EC=9D=B4?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suhyun113/README.md | 3 +- .../10-suhyun113.py" | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 "suhyun113/\355\224\214\353\241\234\354\235\264\353\223\234-\354\233\214\354\205\234/10-suhyun113.py" diff --git a/suhyun113/README.md b/suhyun113/README.md index 163899f..a359954 100644 --- a/suhyun113/README.md +++ b/suhyun113/README.md @@ -10,4 +10,5 @@ | 6차시 | 2024.04.14 | 스택 | [컨트롤 제트](https://school.programmers.co.kr/learn/courses/30/lessons/120853) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/21) | | 7차시 | 2024.05.09 | 트리 | [원숭이 매달기](https://www.acmicpc.net/problem/2716) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/31) | | 8차시 | 2024.05.14 | 수학 | [어린 왕자](https://www.acmicpc.net/problem/1004) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/32) | -| 9차시 | 2024.05.28 | 다익스트라 | [최소비용 구하기](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) | \ No newline at end of file +| 9차시 | 2024.05.28 | 다익스트라 | [최소비용 구하기](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) | +| 10차시 | 2024.07.13 | 플로이드-워셜 | [플로이드](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) | \ No newline at end of file diff --git "a/suhyun113/\355\224\214\353\241\234\354\235\264\353\223\234-\354\233\214\354\205\234/10-suhyun113.py" "b/suhyun113/\355\224\214\353\241\234\354\235\264\353\223\234-\354\233\214\354\205\234/10-suhyun113.py" new file mode 100644 index 0000000..d856392 --- /dev/null +++ "b/suhyun113/\355\224\214\353\241\234\354\235\264\353\223\234-\354\233\214\354\205\234/10-suhyun113.py" @@ -0,0 +1,41 @@ +# 11404 : 플로이드 +import sys + +input = sys.stdin.readline +INF = float('inf') # 최대값 정의 + +# 노드의 개수(n)과 간선의 개수(m) 입력 +n = int(input()) # 도시의 개수 n +m = int(input()) # 버스의 개수 m + +# 2차원 리스트 (그래프 표현) 만들고, 무한대로 초기화(플로이드-워셜 = 이차원 배열) +graph = [[INF] * (n + 1) for _ in range(n + 1)] + +# i에서 j로 갈 수 없는 경우, +# 자기 자신에서 자기 자신으로 가는 비용은 0으로 초기화(대각선에 해당하는 부분)) +for i in range(1, n + 1): + for j in range(1, n + 1): + if i == j: + graph[i][j] = 0 + +# 각 간선에 대한 정보를 입력받아, 그 값으로 초기화 +for _ in range(m): + # A -> B로 가는 비용을 C라고 설정 + i, j, cost = map(int, input().split()) + if graph[i][j] > cost: # 시작 도시와 도착 도시 연결하는 노선 하나가 x + graph[i][j] = cost + +# 점화식에 따라 플로이드 워셜 알고리즘을 수행(3중 for문) +for k in range(1, n + 1): + for i in range(1, n + 1): + for j in range(1, n + 1): + graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]) + +# 수행된 결과를 출력 +for i in range(1, n + 1): + for j in range(1, n + 1): + if graph[i][j] == INF: + print(0, end=' ') + else: + print(graph[i][j], end=' ') + print() \ No newline at end of file From baafbd2d89e45ad08ff8e691d3f144f0f4f18787 Mon Sep 17 00:00:00 2001 From: pu2rile <3o920@naver.com> Date: Sat, 13 Jul 2024 22:42:04 +0900 Subject: [PATCH 2/9] 2024-07-13 --- pu2rile/.DS_Store | Bin 0 -> 8196 bytes pu2rile/README.md | 5 +++- .../\352\260\225\354\235\230\354\213\244.py" | 25 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 pu2rile/.DS_Store create mode 100644 "pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" diff --git a/pu2rile/.DS_Store b/pu2rile/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f49701967e665ac85e44e80dc980ac6055b76eef GIT binary patch literal 8196 zcmeHM&1(}u6n~RMyD=2AP$3s##A~Q&T55|P(wH6!dTB%tR$|hGHn`b|`7no2$XPEQ zd-9|w8$5{Eq6ZOL+gmOcJP7^;o;=i(zWK0hHXqnhjKp~`?>E_bzuleR?9A-j004Gp4h6_ASRK*&fL1^&pcT*xXa%$a|AGRz zXLB=p?EA7+d#!+0;J;LWuMZRp$C$!~M6qOKI zL{W)KF^HsNJLTbsF@+6@k`6@Dfv77Jm7x%Eb>vYI4kRW~d#!+0pi=>!yZd1g^Y%GN zIP-V5oUvF2TX8~>ABf{Wg^5#)ngP=`{btU5f!;u9`&S}Hhp zjoFoS-p-W-A)n1*$kOe+on^H+tJ>MJ;3j2*;WzxLV5nY?MyA3vdUF`(PmH@;LpEPkB<1kYjYw`eMi6CI=%Y5i+lPf z-{w;D;LZBG(RQ84dACmP_+in>-7l9;-nTO!pKO0`SI5I=obxI2e0bLS(jG(j+S3s; zc-2m3=JEczlsdDM*!2NzwchXboPB&Xa_&A|IYXjR*S@(lLpdDgmGuzM|L1#u|93ES zRV$zs7&ZlnFOf{du~+=1uAA{(n_{_#g&U7+NE8%wA{|E*={VxyABI?`7|J;@g$;># p1nsYX2pDX3VCen-7&(=A-*N3_UH7~8cOuMb_5Sb7*u;#J?ian1G%^4H literal 0 HcmV?d00001 diff --git a/pu2rile/README.md b/pu2rile/README.md index 70f15e8..bda1441 100644 --- a/pu2rile/README.md +++ b/pu2rile/README.md @@ -9,4 +9,7 @@ | 5차시 | 2024.04.10 | 그리디 알고리즘 | [국회의원 선거](https://www.acmicpc.net/problem/1417) | [#18](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/18#issue-2235862658) | 6차시 | 2024.05.10 | 그리디 알고리즘 | [ATM](https://www.acmicpc.net/problem/11399) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909) | 7차시 | 2024.05.10 | 완전 탐색 알고리즘 | [영화감독 숌](https://www.acmicpc.net/problem/1436) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909) -| 8차시 | 2024.05.14 | 그리디 알고리즘 | [팔](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384) \ No newline at end of file +| 8차시 | 2024.05.14 | 그리디 알고리즘 | [팔](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384) +| 9차시 | 2024.05.27 | 구현 | [오늘도 졌다](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288) +| 10차시 | 2024.07.11 | 스택 | [화학식량](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169) +| 11차시 | 2024.07.13 | 우선순위 큐 | [강의실](https://www.acmicpc.net/problem/1374) | [#37]() diff --git "a/pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" "b/pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" new file mode 100644 index 0000000..c3c54cd --- /dev/null +++ "b/pu2rile/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/\352\260\225\354\235\230\354\213\244.py" @@ -0,0 +1,25 @@ +import heapq +import sys + +n = int(sys.stdin.readline()) + +heap = [] # 모든 강의의 시작 시간과 종료 시간을 저장할 최소 힙 +q = [] # 현재 사용 중인 강의실의 종료 시간을 저장할 최소 힙 + +# 주어진 강의 수만큼 반복하면서 강의 정보를 입력받아 최소 힙에 저장 +for _ in range(n): + num, start, end = map(int, sys.stdin.readline().split()) + heapq.heappush(heap, [start, end, num]) + +# 첫 번째 강의를 최소 힙에서 꺼내서 해당 강의의 종료 시간을 다른 힙에 저장 +start, end, num = heapq.heappop(heap) +heapq.heappush(q, end) + +while heap: + start, end, num = heapq.heappop(heap) + # 가장 빨리 끝나는 강의실의 종료 시간이 현재 강의의 시작 시간보다 작거나 같으면 종료 시간을 최소 힙에서 제거 + if q[0] <= start: + heapq.heappop(q) + heapq.heappush(q, end) # 현재 강의의 종료 시간을 최소 힙에 추가 + +print(len(q)) # 최소 힙 q의 크기가 필요한 강의실의 수 From 2faf08372b78c893f8199575bc9a2670703147a0 Mon Sep 17 00:00:00 2001 From: pu2rile <3o920@naver.com> Date: Sat, 13 Jul 2024 22:46:45 +0900 Subject: [PATCH 3/9] 2024-07-13 --- pu2rile/.DS_Store | Bin 8196 -> 8196 bytes pu2rile/README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pu2rile/.DS_Store b/pu2rile/.DS_Store index f49701967e665ac85e44e80dc980ac6055b76eef..66ea887eecff06286241ccbb4ee95a1af05348bd 100644 GIT binary patch delta 433 zcmZp1XmQx!D6rXGXcH?h+p!G?6%NT9XJJsd5HLALKpst`K&WXlpNMNcin^S1!{Frn z+yVv!K#|YQcX3I|$xi}GbJ)CFnj52d%n`^&Q Date: Thu, 18 Jul 2024 19:40:27 +0900 Subject: [PATCH 4/9] =?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 5/9] 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 6/9] =?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 7/9] =?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 8/9] 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 +} From b9621c61e55e62c26afdaf325c91fedcdfd627bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=ED=98=84?= Date: Sun, 21 Jul 2024 04:34:18 +0900 Subject: [PATCH 9/9] =?UTF-8?q?2024-07-16=20=EC=97=B0=EA=B5=AC=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suhyun113/README.md | 3 +- .../11-suhyun113.cpp" | 106 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 "suhyun113/\352\265\254\355\230\204/11-suhyun113.cpp" diff --git a/suhyun113/README.md b/suhyun113/README.md index a359954..59a2688 100644 --- a/suhyun113/README.md +++ b/suhyun113/README.md @@ -11,4 +11,5 @@ | 7차시 | 2024.05.09 | 트리 | [원숭이 매달기](https://www.acmicpc.net/problem/2716) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/31) | | 8차시 | 2024.05.14 | 수학 | [어린 왕자](https://www.acmicpc.net/problem/1004) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/32) | | 9차시 | 2024.05.28 | 다익스트라 | [최소비용 구하기](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) | -| 10차시 | 2024.07.13 | 플로이드-워셜 | [플로이드](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) | \ No newline at end of file +| 10차시 | 2024.07.13 | 플로이드-워셜 | [플로이드](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) | +| 11차시 | 2024.07.16 | BFS | [연구소](https://www.acmicpc.net/problem/14502) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/39) | \ No newline at end of file diff --git "a/suhyun113/\352\265\254\355\230\204/11-suhyun113.cpp" "b/suhyun113/\352\265\254\355\230\204/11-suhyun113.cpp" new file mode 100644 index 0000000..e4c2e43 --- /dev/null +++ "b/suhyun113/\352\265\254\355\230\204/11-suhyun113.cpp" @@ -0,0 +1,106 @@ +//14502 : 연구소 + +#include +#include +#include +#include +using namespace std; + +// 메크로 설정 +#define BLANK 0 +#define WALL 1 +#define VIRUS 2 + +int N, M; // 지도의 세로 크기, 가로 크기 +vector> initial_map; // 초기 지도 +vector> blank_map; // 빈 칸 +int directions[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; // 방향 + +// 가능한 모든 벽 세우기 조합 구하기 +vector>> building_walls() { + vector>> combinations; + int size = blank_map.size(); // 빈 칸 크기 + for (int i = 0; i < size; i++) { + for (int j = i + 1; j < size; j++) { + for (int k = j + 1; k < size; k++) { + // 빈 칸에 벽 3개 세우기 + combinations.push_back({blank_map[i], blank_map[j], blank_map[k]}); + } + } + } + return combinations; +} + +// 너비 우선 탐색(바이러스인 칸 큐에 저장 후, +// 바이러스 칸 주변 칸이 바이러스 아닌 빈 칸이라면, +// 주변 칸을 바이러스로 바꾸기) +void bfs(vector>& map_copy) { + queue> q; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (map_copy[i][j] == VIRUS) { + q.push({i, j}); + } + } + } + // 바이러스인 칸이 아니고 빈 칸이라면, + while (!q.empty()) { + int x = q.front().first; + int y = q.front().second; + q.pop(); + for (int d = 0; d < 4; d++) { // 방향 탐색 + int nx = x + directions[d][0]; + int ny = y + directions[d][1]; + if (nx >= 0 && nx < N && ny >= 0 && ny < M && map_copy[nx][ny] == 0) { + map_copy[nx][ny] = VIRUS; // 빈 칸을 바이러스로 바꾸기 + q.push({nx, ny}); + } + } + } +} + +// 안전 영역 크기 계산 함수 +int calculate_safe_area(vector>& map_copy) { + int safe_area = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (map_copy[i][j] == BLANK) { // 빈 칸의 개수 + safe_area++; + } + } + } + return safe_area; +} + +int main() { + cin >> N >> M; + initial_map.resize(N, vector(M)); + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + cin >> initial_map[i][j]; + if (initial_map[i][j] == BLANK) { + blank_map.push_back({ i, j }); // 빈 칸 지도 생성 + } + } + } + + vector>> wall_combinations = building_walls(); // 빈 칸에 벽 세우기 + int max_safe_area = 0; // 안전 영역의 최대 크기 + + for (const auto& walls : wall_combinations) { // 벽 3개를 세운 여러 조합 반복 + // 초기 맵 복사해서 그 맵에 벽 3개 세우는 여러 조합 중 한 경우 적용 + vector> map_copy = initial_map; + for (const auto& wall : walls) { // 한 경우에서 세운 벽 3개의 각각 위치에 벽 세우기 + map_copy[wall.first][wall.second] = WALL; // 벽 세우기 + } + + bfs(map_copy); // 바이러스 주변 칸 빈 칸이라면 바이러스 번짐 + + int safe_area = calculate_safe_area(map_copy); // 안전영역 크기 계산 + max_safe_area = max(max_safe_area, safe_area); + } + + cout << max_safe_area << endl; + return 0; +} \ No newline at end of file