From bd73c44ce592438e1f7060aec3dcbd25566eeffc Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:06:18 +0900 Subject: [PATCH 001/822] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d5c86c..d733cba 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # StudyCodes +Study + study for Android Kotlin Application
+- 일정 노션 : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
+## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. - - 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! +- 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 + +## Contents +- [07.21](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.21/%EA%B6%8C%EC%A3%BC%ED%98%84/1110_%EB%8D%94%ED%95%98%EA%B8%B0_%EC%82%AC%EC%9D%B4%ED%81%B4) -- 폴더 경로 : 날짜(MMDD)/사용자이름/문제 From 43063c21958ac06a3de71a0f3e82ba74e8a80413 Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:06:38 +0900 Subject: [PATCH 002/822] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d733cba..584c12a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # StudyCodes -Study +Study study for Android Kotlin Application
- 일정 노션 : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
From ad779f30fca715e7cfd64ba3469ca9f64bd90cfc Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:07:41 +0900 Subject: [PATCH 003/822] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 584c12a..3401b86 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # StudyCodes -Study +Study study for Android Kotlin Application
- 일정 노션 : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
@@ -9,5 +9,5 @@ - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 ## Contents -- [07.21](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.21/%EA%B6%8C%EC%A3%BC%ED%98%84/1110_%EB%8D%94%ED%95%98%EA%B8%B0_%EC%82%AC%EC%9D%B4%ED%81%B4) - +- [07.21](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.21) +- [07.25](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.25) From 1375bbae53e4d908fbf04b976c6f7cd41de407ac Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:08:24 +0900 Subject: [PATCH 004/822] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3401b86..a6ab8ea 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # StudyCodes -Study +Study study for Android Kotlin Application
- 일정 노션 : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
From 22b32f9e39c1cab2b0b18291f46aebb2bda76c7a Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:10:27 +0900 Subject: [PATCH 005/822] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a6ab8ea..10b414b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # StudyCodes -Study - study for Android Kotlin Application
-- 일정 노션 : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
+Study
+- [👉일정 관리용 노션👈](https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f)
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From 75cc62299ed23f182dd259f8bc6a5347c6596a1d Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:11:14 +0900 Subject: [PATCH 006/822] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 10b414b..b7b203e 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,5 @@ - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 ## Contents -- [07.21](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.21) -- [07.25](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.25) +- [07.21.목](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.21) +- [07.25.월](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.25) From c335db29bf1321371fa76d89d76838a05a7944cb Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:21:26 +0900 Subject: [PATCH 007/822] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7b203e..8696be3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # StudyCodes Study
-- [👉일정 관리용 노션👈](https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f)
+- [👉일정 관리용 노션👈][] +[👉일정 관리용 노션👈] : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From b34a209a68dc8b9654639328de24a3c60aaeadaf Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sun, 24 Jul 2022 11:22:25 +0900 Subject: [PATCH 008/822] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 8696be3..ac41e4b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # StudyCodes Study
-- [👉일정 관리용 노션👈][] -[👉일정 관리용 노션👈] : https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f
+- [👉일정 관리용 노션👈]( https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f)
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From b6c140f797a1ac3619872f86d28904caa1976896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 24 Jul 2022 15:25:48 +0900 Subject: [PATCH 009/822] =?UTF-8?q?Create=202422=5F=ED=95=9C=EC=9C=A4?= =?UTF-8?q?=EC=A0=95=EC=9D=B4.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\234\244\354\240\225\354\235\264.java" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" "b/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" new file mode 100644 index 0000000..c54cf70 --- /dev/null +++ "b/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int m = sc.nextInt(); + + int no_mat[][] = new int[n+1][n+1]; + + // count + int count = 0; + for(int i=1; i<= n; i++) { + no_mat[i][i] = 1; + } + for (int i = 1; i <= m; i++) { + int a = sc.nextInt(); + int b = sc.nextInt(); + no_mat[a][b] = 1; + no_mat[b][a] = 1; + } + + + for(int i=1; i<=n; i++) { // 1 + for(int j=i+1; j<=n; j++) { + if(no_mat[i][j] == 1) { // 4 + continue; + } + for(int k=j+1; k<=n; k++) { + if(no_mat[j][k] == 1 || no_mat[i][k] == 1) { // + continue; + } +// System.out.println(i + " " + j + " " + k); + count++; + + } + } + } + System.out.println(count); + } +} From 5d89a6cc813c65ab154631d6548a53850d83b3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 24 Jul 2022 15:36:26 +0900 Subject: [PATCH 010/822] =?UTF-8?q?Create=201476=5F=EB=82=A0=EC=A7=9C?= =?UTF-8?q?=EA=B3=84=EC=82=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\247\234\352\263\204\354\202\260.java" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" "b/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" new file mode 100644 index 0000000..a621b25 --- /dev/null +++ "b/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" @@ -0,0 +1,23 @@ +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int E = sc.nextInt(); + int S = sc.nextInt(); + int M = sc.nextInt(); + + int i=1; + while(true) { + if((i-E)%15 == 0 && + (i-S)%28 == 0 && + (i-M)%28 == 0){ + break; + } + i++; + } + System.out.println(i); + } +} From c0cb7c61f4055b7ac63d23b61d758821a7fea78e Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 24 Jul 2022 16:44:51 +0900 Subject: [PATCH 011/822] kihun --- ...40\354\247\234\352\263\204\354\202\260.py" | 23 +++++++ ...70\354\204\234\352\262\200\354\203\211.py" | 22 +++++++ ...34\354\234\244\354\240\225\354\235\264.py" | 42 ++++++++++++ ...34\352\260\204\354\264\210\352\263\274.py" | 37 +++++++++++ ...54\355\203\225\352\262\214\354\236\204.py" | 66 +++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 "07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" create mode 100644 "07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" create mode 100644 "07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" create mode 100644 "07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" create mode 100644 "07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" "b/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" new file mode 100644 index 0000000..c4b8f86 --- /dev/null +++ "b/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" @@ -0,0 +1,23 @@ +E, S, M = map(int, input().split()) + +# 조건문에서 생기게 될 오류 방지 +if E == 15: + E = 0 +if S == 28: + S = 0 +if M == 19: + M = 0 + +i = 0 + +while (True): + result = 15 * i + E + if (result % 28 == S and result % 19 == M): + if (result != 0): + break + else: + i += 1 + else: + i += 1 + +print(result) diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" "b/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" new file mode 100644 index 0000000..0a3f961 --- /dev/null +++ "b/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" @@ -0,0 +1,22 @@ +text = input() +search = input() + +# 012345678 +# ababababa len = 9 +# abaxabaxx len = 3 +# i = 6일때까지만 체크 + +i = 0 +count = 0 + +# i가 range를 차례로 도는 것이 아니라 +# 값을 불규칙적으로 점프해야 되므로 while 사용 +while i <= (len(text) - len(search)): + text_sub = text[i: i + len(search)] + if (text_sub == search): + count += 1 + i += len(search) + else: + i += 1 +print(count) + diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" "b/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" new file mode 100644 index 0000000..24e2a63 --- /dev/null +++ "b/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" @@ -0,0 +1,42 @@ +N, M = map(int, input().split()) + +iceCreamList = list(range(N)) # [0, 1, 2, 3, 4] +banList = [] +banSet = set() + +for _ in range(M): + a, b = map(int, input().split()) + temp = [a-1, b-1] + banList.append(temp) +# banList = [[0, 1], [2, 3], [0, 2]] + +# 3가지를 뽑는 모든 경우의 수 +if N < 3: + total = 0 +elif N == 3: + total = 1 +else: + total = N * (N-1) * (N-2) // 6 + +for i in banList: + for iceCream in iceCreamList: + # i에 j가 있으면 + if iceCream in i: + continue + else: + i.append(iceCream) + # tuple로 저장되어 (0,1,2)와 (0,2,1)이 다른 케이스로 저장되는 걸 방지 + i.sort() + banSet.add(tuple(i)) + # 다시 원본 i 상태로 복귀 + i.remove(iceCream) + +# 답이 음수가 될 수도 있으니 삼항 연산자로 처리 +result = total - len(banSet) if total - len(banSet) >= 0 else 0 + +print(result) + + + + + diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" "b/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" new file mode 100644 index 0000000..f5a9d56 --- /dev/null +++ "b/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" @@ -0,0 +1,37 @@ +N, M = map(int, input().split()) + +iceList = list(range(1, N + 1)) +banList = [] +result = [] + +for _ in range(M): + a, b = map(int, input().split()) + temp = [a, b] + banList.append(temp) + +# 조합 함수 +def combination(list, targetNum): + combiResult = [] + + def nowCombi(nowList, index): + if len(nowList) == targetNum: + combiResult.append(nowList) + return + for i in range(index, len(list)): + nowCombi(nowList + [list[i]], i + 1) + + nowCombi([], 0) + + return combiResult + +combiList = combination(iceList, 3) + +for i in combiList: + check = 1 + for j in banList: + if all(elem in i for elem in j): + check = 0 + if check == 1: + result.append(i) + +print(len(result)) diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" "b/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" new file mode 100644 index 0000000..5c57af0 --- /dev/null +++ "b/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" @@ -0,0 +1,66 @@ +N = int(input()) +matrix = [] +countSet = set() + +# 행 확인 +def check_row(matrix: list, countSet: set): + for y in range(N): + count = 1 + for x in range(1,N): + if (matrix[y][x] == matrix[y][x - 1]): + count += 1 + else: + countSet.add(count) + count = 1 + countSet.add(count) + + +# 열 확인 +def check_col(matrix: list, countSet: set): + for x in range(N): + count = 1 + for y in range(1,N): + if (matrix[y][x] == matrix[y - 1][x]): + count += 1 + else: + countSet.add(count) + count = 1 + countSet.add(count) + +# 입력 받기 +for i in range(N): + matrix.append(list(input())) + +# 좌우 바꿔서 체크 +for y in range(N): + for x in range(1,N): + if (matrix[y][x] != matrix[y][x - 1]): + # swap + temp = matrix[y][x - 1] + matrix[y][x - 1] = matrix[y][x] + matrix[y][x] = temp + check_row(matrix, countSet) + check_col(matrix, countSet) + # swap 원위치 + temp = matrix[y][x - 1] + matrix[y][x - 1] = matrix[y][x] + matrix[y][x] = temp + +# 위아래 바꿔서 체크 +for x in range(N): + for y in range(1,N): + if (matrix[y][x] != matrix[y - 1][x]): + # swap + temp = matrix[y - 1][x] + matrix[y - 1][x] = matrix[y][x] + matrix[y][x] = temp + check_row(matrix, countSet) + check_col(matrix, countSet) + # swap 원위치 + temp = matrix[y - 1][x] + matrix[y - 1][x] = matrix[y][x] + matrix[y][x] = temp + +print(max(countSet)) + + From e8289c491463ff08db04a15d9a177155d8d4dccd Mon Sep 17 00:00:00 2001 From: dldkfma9577 Date: Sun, 24 Jul 2022 17:25:25 +0900 Subject: [PATCH 012/822] =?UTF-8?q?[ADD]=207.25=20=EC=8A=A4=ED=84=B0?= =?UTF-8?q?=EB=94=94=203085=5F=EC=82=AC=ED=83=95=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\225\352\262\214\354\236\204.cpp" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git "a/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" "b/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" index 8b13789..9a793fb 100644 --- "a/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" +++ "b/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" @@ -1 +1,63 @@ +#include +#include +#include +#include +using namespace std; + +int N, biggest = 0; +vector board; +int px[] = { 0,-1,0,1 }; +int py[] = { -1,0,1,0 }; +void checkSame() { //ӵǴ + for (int i = 0; i < N; i++) { + int count = 1; + for (int k = 1; k < N; k++) { // Ȯ + if (board[i][k - 1] == board[i][k]) { + count++; + biggest = max(count, biggest); + } + else { + count = 1; + } + } + count = 1; + for (int k = 1; k < N; k++) { //Ȯ + if (board[k-1][i] == board[k][i]) { + count++; + biggest = max(count, biggest); + } + else { + count = 1; + } + } + } +} + +int main() { + //Է + cin >> N; + for (int i = 0; i < N; i++) { + string str; cin >> str; + board.push_back(str); + } + + // ڵ + for (int i = 0; i < N; i++) { + for (int k = 0; k < N; k++) { + int nextX, nextY; + for (int t = 0; t < 4; t++) { + nextX = i + px[t]; + nextY = k + py[t]; + if (0 <= nextX && nextX < N && 0 <= nextY && nextY < N) { + swap(board[nextX][nextY], board[i][k]); + checkSame(); + swap(board[nextX][nextY], board[i][k]); + } + } + } + } + + cout << biggest << endl; + return 0; +} From 2047e6e8db4a6bab34c878ea6d9eba68b22b463e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 24 Jul 2022 17:28:06 +0900 Subject: [PATCH 013/822] =?UTF-8?q?Update=203085=5F=EC=82=AC=ED=83=95?= =?UTF-8?q?=EA=B2=8C=EC=9E=84.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\254\355\203\225\352\262\214\354\236\204.cpp" | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git "a/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" "b/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" index 9a793fb..3cc3b16 100644 --- "a/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" +++ "b/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" @@ -7,12 +7,12 @@ using namespace std; int N, biggest = 0; vector board; -int px[] = { 0,-1,0,1 }; -int py[] = { -1,0,1,0 }; -void checkSame() { //ӵǴ +int px[] = {-1,0,1 }; +int py[] = { 0,1,0 }; +void checkSame() { //연속되는 개수 세기 for (int i = 0; i < N; i++) { int count = 1; - for (int k = 1; k < N; k++) { // Ȯ + for (int k = 1; k < N; k++) { // 행확인 if (board[i][k - 1] == board[i][k]) { count++; biggest = max(count, biggest); @@ -22,7 +22,7 @@ int py[] = { -1,0,1,0 }; } } count = 1; - for (int k = 1; k < N; k++) { //Ȯ + for (int k = 1; k < N; k++) { //열확인 if (board[k-1][i] == board[k][i]) { count++; biggest = max(count, biggest); @@ -35,18 +35,18 @@ int py[] = { -1,0,1,0 }; } int main() { - //Է + //입력 시작 cin >> N; for (int i = 0; i < N; i++) { string str; cin >> str; board.push_back(str); } - // ڵ + //본 코드 시작 for (int i = 0; i < N; i++) { for (int k = 0; k < N; k++) { int nextX, nextY; - for (int t = 0; t < 4; t++) { + for (int t = 0; t < 3; t++) { nextX = i + px[t]; nextY = k + py[t]; if (0 <= nextX && nextX < N && 0 <= nextY && nextY < N) { From 4efb3a606f162c0bf350165ace6cd03a8e5c8557 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 24 Jul 2022 22:17:25 +0900 Subject: [PATCH 014/822] solve --- ...\353\250\271\353\212\224\353\215\260.java" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" diff --git "a/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" "b/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" new file mode 100644 index 0000000..64fb7f6 --- /dev/null +++ "b/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" @@ -0,0 +1,65 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static boolean bad[][]; + public static int combination[]; + + public static boolean visited[]; + public static int ic_arr[]; + + public static int count = 0; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(token.nextToken()); + int M = Integer.parseInt(token.nextToken()); + + bad = new boolean[N+1][N+1]; // ȵǴ + combination = new int[3]; //̽ũ + + visited = new boolean[N+1]; + ic_arr = new int[N+1]; + + for (int i = 1; i <= N ; i++) { + ic_arr[i-1] = i; + } + + for (int i = 0; i < M; i++) { + token = new StringTokenizer(br.readLine()); + int ic = Integer.parseInt(token.nextToken()); + int ic2 = Integer.parseInt(token.nextToken()); + + bad[ic][ic2] = true; + bad[ic2][ic] = true; + } + comb(0,0,N); + System.out.println(count); + } + + public static void comb(int index, int size,int length) { + if (size == 3) { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + // ԵǾ pass + if (bad[combination[i]][combination[j]]) { + return; + } + } + } + count++; + return; + } + + for (int i = index; i < length; i++) { + if (!visited[i]) { + visited[i] = true; + combination[size] = ic_arr[i]; + comb(i+1,size+1,length); + visited[i] = false; + } + } + } +} From a44019d5921a0045125328a081ace164ee6d0370 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 25 Jul 2022 12:42:09 +0900 Subject: [PATCH 015/822] 07.25 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이지윤 - 미완 --- ...0\354\247\234 \352\263\204\354\202\260.py" | 37 ++++++++ ...354\247\234 \352\263\204\354\202\260_2.py" | 16 ++++ ...0\354\204\234 \352\262\200\354\203\211.py" | 15 ++++ ...354\204\234 \352\262\200\354\203\211_2.py" | 25 ++++++ ...54\353\250\271\353\212\224\353\215\260.py" | 19 ++++ ...4\355\203\225 \352\262\214\354\236\204.py" | 87 +++++++++++++++++++ ...355\203\225 \352\262\214\354\236\204_2.py" | 42 +++++++++ 7 files changed, 241 insertions(+) create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" new file mode 100644 index 0000000..114668e --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" @@ -0,0 +1,37 @@ + +def check_e(earth, year_val) -> True: + if year_val % 15 == 0 and earth == 15: + return True + elif year_val % 15 == earth: + return True + else: + return False + + +def check_s(sun, year_val) -> True: + if year_val % 28 == 0 and sun == 28: + return True + elif year_val % 28 == sun: + return True + else: + return False + + +def check_m(moon, year_val) -> True: + if year_val % 19 == 0 and moon == 19: + return True + elif year_val % 19 == moon: + return True + else: + return False + + +e, s, m = map(int, input().split()) + +year = 1 +while True: + if check_e(e, year) and check_s(s, year) and check_m(m, year): + print(year) + break + else: + year += 1 diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" new file mode 100644 index 0000000..3630b23 --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" @@ -0,0 +1,16 @@ + +E, S, M = 15, 28, 19 # 주기 상수 +e, s, m = map(int, input().split()) # 입력 값 + +e -= 1 +s -= 1 +m -= 1 # 표현 일치 + +year = 0 + +while True: + if year % E == e and year % S == s and year % M == m: + print(year + 1) + break + else: + year += 1 diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" new file mode 100644 index 0000000..910cc21 --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" @@ -0,0 +1,15 @@ + +if __name__ == '__main__': + document = input() + word = input() + len_d, len_w = len(document), len(word) + index, answer = 0, 0 + while index <= len_d: + if document[index:index+len_w] == word: + answer += 1 + index += len_w + else: + index +=1 + print(answer) + + diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" new file mode 100644 index 0000000..23e86cc --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" @@ -0,0 +1,25 @@ +# 고쳐야 한다. + +answer = 0 +document = input() +word = input() +len_d, len_w = len(document), len(word) + +def main(): + solution(document, word, 0, 0) + print(answer) + +def solution(_d, _w, _index, _count) : + global answer + if _index < len_d: + answer = max(answer, _count) + else: + return + for i in range(_index ,len_d): + if _d[i:i + len_w] == _w: + solution(_d, _w, i+len_w, _count+1) + + + +if __name__ == '__main__': + main() diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" new file mode 100644 index 0000000..05aa0fb --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" @@ -0,0 +1,19 @@ +import itertools + +# def solution(_n, _m, _arr) -> int : +# count = 0 +# for i in itertools.combinations(range(1, _n+1), 3): +# for j in _arr: +# set_i = set(i) +# if set_i - j != set_i : break +# else : +# print(count) +# print(i) +# print(j) +# count += 1 +# return count +# +# n, m = map(int, input().split()) +# arr = [list(map(int, input().split())) for i in range(m)] +# answer = solution(n, m, arr) +# print(answer) \ No newline at end of file diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" new file mode 100644 index 0000000..c20b8d0 --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" @@ -0,0 +1,87 @@ +def search_max_candy(n, candy_l): # 고정된 상황. 최대 캔디 수만 세기. + count_max_row = 1 + count_max_col = 1 + for x in range(n): + count_row = 1 + count_col = 1 + for y in range(n - 1): + if candy_l[x][y] == candy_l[x][y + 1]: # '우'와 동일 여부 비교.(row) (세로 마지막 열 배제) + count_row += 1 + if count_max_row < count_row: + count_max_row = count_row + else: + count_row = 1 + if candy_l[y][x] == candy_l[y + 1][x]: # '하'와 동일 여부 비교.(col) (가로 마지막 행 배제) + count_col += 1 + if count_max_col < count_col: + count_max_col = count_col + else: + count_col = 1 + return max(count_max_row, count_max_col) + + +input_n = int(input()) +candy_list = [list(input()) for _ in range(input_n)] +count_ans = 0 +for i in range(input_n): + for j in range(input_n): + # '우'와 '하'의 경우만 고려 - 인접한 사탕을 교환 + if i + 1 < input_n: # '하'의 경우 - 행이 최대 행일 경우, '하' 교환 성립 X. 따라서 해당 경우 배제. + candy_list[i][j], candy_list[i + 1][j] = candy_list[i + 1][j], candy_list[i][j] + max_count = search_max_candy(input_n, candy_list) + if max_count > count_ans: + count_ans = max_count + candy_list[i][j], candy_list[i + 1][j] = candy_list[i + 1][j], candy_list[i][j] + if j + 1 < input_n: # '우'의 경우 - 행이 최대 행일 경우, '우' 교환 성립 X. 따라서 해당 경우 배제. + candy_list[i][j], candy_list[i][j + 1] = candy_list[i][j + 1], candy_list[i][j] + max_count = search_max_candy(input_n, candy_list) + if max_count > count_ans: + count_ans = max_count + candy_list[i][j], candy_list[i][j + 1] = candy_list[i][j + 1], candy_list[i][j] + +print(count_ans) + +# import sys +# +# +# def check_max_candy(n, lst): # [Part1] 고정된 2차원 배열에서 최대 사탕의 갯수를 세어주는 함수 +# ans = 1 +# for i in range(n): +# count = 1 +# for j in range(n - 1): # same row, dif col 과의 비교 +# if lst[i][j] == lst[i][j + 1]: # 주의 : 여기서 i,j != row, col +# count += 1 +# else: +# count = 1 +# if ans < count: +# ans = count +# count = 1 +# for j in range(n - 1): # same col, dif row 와의 비교 +# if lst[j][i] == lst[j + 1][i]: +# count += 1 +# else: +# count = 1 +# if ans < count: +# ans = count +# return ans +# +# +# # --------------------------------------------------------------------------------------------------------------- +# +# max_num = int(input()) +# candy_list = [list(sys.stdin.readline().rstrip()) for _ in range(max_num)] +# max_candy = 0 +# +# for x in range(max_num): # [Part2] 주어진 2차원 배열에서 변화를 일으켜 모든 경우의 수를 커버하는 코드. +# for y in range(max_num): +# if x + 1 < max_num: +# candy_list[x][y], candy_list[x + 1][y] = candy_list[x + 1][y], candy_list[x][y] +# temp = check_max_candy(max_num, candy_list) +# if max_candy < temp: +# max_candy = temp +# if y + 1 < max_num: +# candy_list[x][y], candy_list[x][y + 1] = candy_list[x][y + 1], candy_list[x][y] +# temp = check_max_candy(max_num, candy_list) +# if max_candy < temp: +# max_candy = temp +# print(max_candy) diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" new file mode 100644 index 0000000..86525dd --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" @@ -0,0 +1,42 @@ +def search_max_candy(n, candy_l): # 고정된 상황. 최대 캔디 수만 세기. + count_max_row = 1 + count_max_col = 1 + for x in range(n): + count_row = 1 + count_col = 1 + for y in range(n - 1): + if candy_l[x][y] == candy_l[x][y + 1]: # '우'와 동일 여부 비교.(row) (세로 마지막 열 배제) + count_row += 1 + if count_max_row < count_row: + count_max_row = count_row + else: + count_row = 1 + if candy_l[y][x] == candy_l[y + 1][x]: # '하'와 동일 여부 비교.(col) (가로 마지막 행 배제) + count_col += 1 + if count_max_col < count_col: + count_max_col = count_col + else: + count_col = 1 + return max(count_max_row, count_max_col) + + +input_n = int(input()) +candy_list = [list(input()) for _ in range(input_n)] +count_ans = 0 +for i in range(input_n): + for j in range(input_n): + # '우'와 '하'의 경우만 고려 - 인접한 사탕을 교환 + if i + 1 < input_n: # '하'의 경우 - 행이 최대 행일 경우, '하' 교환 성립 X. 따라서 해당 경우 배제. + candy_list[i][j], candy_list[i + 1][j] = candy_list[i + 1][j], candy_list[i][j] + max_count = search_max_candy(input_n, candy_list) + if max_count > count_ans: + count_ans = max_count + candy_list[i][j], candy_list[i + 1][j] = candy_list[i + 1][j], candy_list[i][j] + if j + 1 < input_n: # '우'의 경우 - 행이 최대 행일 경우, '우' 교환 성립 X. 따라서 해당 경우 배제. + candy_list[i][j], candy_list[i][j + 1] = candy_list[i][j + 1], candy_list[i][j] + max_count = search_max_candy(input_n, candy_list) + if max_count > count_ans: + count_ans = max_count + candy_list[i][j], candy_list[i][j + 1] = candy_list[i][j + 1], candy_list[i][j] + +print(count_ans) From bb5370425a49886215294662157ced4d68513438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 25 Jul 2022 18:16:27 +0900 Subject: [PATCH 016/822] =?UTF-8?q?Create=203085=5F=EC=82=AC=ED=83=95?= =?UTF-8?q?=EA=B2=8C=EC=9E=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\203\225\352\262\214\354\236\204.java" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" "b/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" new file mode 100644 index 0000000..1de2d9f --- /dev/null +++ "b/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" @@ -0,0 +1,81 @@ +import java.util.Scanner; + +public class Main { + static char candy[][] = new char[50][50]; + + static int max_candy = 0; + + public static void find_long_candy(int n) { + for(int i=0; i Date: Mon, 25 Jul 2022 19:15:27 +0900 Subject: [PATCH 017/822] 07.25 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이지윤 - 한윤정이 이탈리에 가서 아이스크림 (미완) - 문서 검색_2 (미완) --- ...354\204\234 \352\262\200\354\203\211_3.py" | 20 +++++ ...4\355\203\225 \352\262\214\354\236\204.py" | 44 ---------- ...355\203\225 \352\262\214\354\236\204_2.py" | 86 ++++++++++--------- 3 files changed, 64 insertions(+), 86 deletions(-) create mode 100644 "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" new file mode 100644 index 0000000..d616aad --- /dev/null +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" @@ -0,0 +1,20 @@ +# 그 외 파이썬이라 가능한 풀이들 + +document = input() +word = input() + + +# [풀이 1] replace & count 메소드 활용 +def solution1() -> int : + replaced_document = document.replace(word, '*') + return replaced_document.count('*') + +# [풀이 2] count 메소드 활용 +def solution2() -> int : + return document.count(word) + +if __name__ == '__main__': + answer1 = solution1() + answer2 = solution2() + print(answer1) + print(answer2) \ No newline at end of file diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" index c20b8d0..572282f 100644 --- "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" @@ -41,47 +41,3 @@ def search_max_candy(n, candy_l): # 고정된 상황. 최대 캔디 수만 세 print(count_ans) -# import sys -# -# -# def check_max_candy(n, lst): # [Part1] 고정된 2차원 배열에서 최대 사탕의 갯수를 세어주는 함수 -# ans = 1 -# for i in range(n): -# count = 1 -# for j in range(n - 1): # same row, dif col 과의 비교 -# if lst[i][j] == lst[i][j + 1]: # 주의 : 여기서 i,j != row, col -# count += 1 -# else: -# count = 1 -# if ans < count: -# ans = count -# count = 1 -# for j in range(n - 1): # same col, dif row 와의 비교 -# if lst[j][i] == lst[j + 1][i]: -# count += 1 -# else: -# count = 1 -# if ans < count: -# ans = count -# return ans -# -# -# # --------------------------------------------------------------------------------------------------------------- -# -# max_num = int(input()) -# candy_list = [list(sys.stdin.readline().rstrip()) for _ in range(max_num)] -# max_candy = 0 -# -# for x in range(max_num): # [Part2] 주어진 2차원 배열에서 변화를 일으켜 모든 경우의 수를 커버하는 코드. -# for y in range(max_num): -# if x + 1 < max_num: -# candy_list[x][y], candy_list[x + 1][y] = candy_list[x + 1][y], candy_list[x][y] -# temp = check_max_candy(max_num, candy_list) -# if max_candy < temp: -# max_candy = temp -# if y + 1 < max_num: -# candy_list[x][y], candy_list[x][y + 1] = candy_list[x][y + 1], candy_list[x][y] -# temp = check_max_candy(max_num, candy_list) -# if max_candy < temp: -# max_candy = temp -# print(max_candy) diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" index 86525dd..572b30c 100644 --- "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" @@ -1,42 +1,44 @@ -def search_max_candy(n, candy_l): # 고정된 상황. 최대 캔디 수만 세기. - count_max_row = 1 - count_max_col = 1 - for x in range(n): - count_row = 1 - count_col = 1 - for y in range(n - 1): - if candy_l[x][y] == candy_l[x][y + 1]: # '우'와 동일 여부 비교.(row) (세로 마지막 열 배제) - count_row += 1 - if count_max_row < count_row: - count_max_row = count_row - else: - count_row = 1 - if candy_l[y][x] == candy_l[y + 1][x]: # '하'와 동일 여부 비교.(col) (가로 마지막 행 배제) - count_col += 1 - if count_max_col < count_col: - count_max_col = count_col - else: - count_col = 1 - return max(count_max_row, count_max_col) - - -input_n = int(input()) -candy_list = [list(input()) for _ in range(input_n)] -count_ans = 0 -for i in range(input_n): - for j in range(input_n): - # '우'와 '하'의 경우만 고려 - 인접한 사탕을 교환 - if i + 1 < input_n: # '하'의 경우 - 행이 최대 행일 경우, '하' 교환 성립 X. 따라서 해당 경우 배제. - candy_list[i][j], candy_list[i + 1][j] = candy_list[i + 1][j], candy_list[i][j] - max_count = search_max_candy(input_n, candy_list) - if max_count > count_ans: - count_ans = max_count - candy_list[i][j], candy_list[i + 1][j] = candy_list[i + 1][j], candy_list[i][j] - if j + 1 < input_n: # '우'의 경우 - 행이 최대 행일 경우, '우' 교환 성립 X. 따라서 해당 경우 배제. - candy_list[i][j], candy_list[i][j + 1] = candy_list[i][j + 1], candy_list[i][j] - max_count = search_max_candy(input_n, candy_list) - if max_count > count_ans: - count_ans = max_count - candy_list[i][j], candy_list[i][j + 1] = candy_list[i][j + 1], candy_list[i][j] - -print(count_ans) +# import sys +# +# +# def check_max_candy(n, lst): # [Part1] 고정된 2차원 배열에서 최대 사탕의 갯수를 세어주는 함수 +# ans = 1 +# for i in range(n): +# count = 1 +# for j in range(n - 1): # same row, dif col 과의 비교 +# if lst[i][j] == lst[i][j + 1]: # 주의 : 여기서 i,j != row, col +# count += 1 +# else: +# count = 1 +# if ans < count: +# ans = count +# count = 1 +# for j in range(n - 1): # same col, dif row 와의 비교 +# if lst[j][i] == lst[j + 1][i]: +# count += 1 +# else: +# count = 1 +# if ans < count: +# ans = count +# return ans +# +# +# # --------------------------------------------------------------------------------------------------------------- +# +# max_num = int(input()) +# candy_list = [list(sys.stdin.readline().rstrip()) for _ in range(max_num)] +# max_candy = 0 +# +# for x in range(max_num): # [Part2] 주어진 2차원 배열에서 변화를 일으켜 모든 경우의 수를 커버하는 코드. +# for y in range(max_num): +# if x + 1 < max_num: +# candy_list[x][y], candy_list[x + 1][y] = candy_list[x + 1][y], candy_list[x][y] +# temp = check_max_candy(max_num, candy_list) +# if max_candy < temp: +# max_candy = temp +# if y + 1 < max_num: +# candy_list[x][y], candy_list[x][y + 1] = candy_list[x][y + 1], candy_list[x][y] +# temp = check_max_candy(max_num, candy_list) +# if max_candy < temp: +# max_candy = temp +# print(max_candy) From f441a18f479e41fb3c48cef3d6d4d337742cdbbe Mon Sep 17 00:00:00 2001 From: hojojeong Date: Mon, 25 Jul 2022 19:46:04 +0900 Subject: [PATCH 018/822] =?UTF-8?q?0725=20=EC=8A=A4=ED=84=B0=EB=94=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 11 +++ .gitignore | 1 + .project | 17 ++++ ...247\234\352\263\204\354\202\260_1476.java" | 29 +++++++ ...204\234\352\262\200\354\203\211_1543.java" | 22 ++++++ ...203\225\352\262\214\354\236\204_3085.java" | 78 +++++++++++++++++++ ...225\234\354\234\244\354\240\225_2422.java" | 34 ++++++++ 7 files changed, 192 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 "07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" create mode 100644 "07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" create mode 100644 "07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" create mode 100644 "07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3291221 --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..f677493 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + p0725 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git "a/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" "b/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" new file mode 100644 index 0000000..7eaf582 --- /dev/null +++ "b/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" @@ -0,0 +1,29 @@ +package problum1476; + +import java.util.*; + +public class 날짜계산_1476 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int e = sc.nextInt(); + int s = sc.nextInt(); + int m = sc.nextInt(); + int re = 0; + int rs = 0; + int rm = 0; + int ans = 0; + + while(true) { + re++; + rs++; + rm++; + ans++; + if(re == 16) re = 1; + if(rs == 29) rs = 1; + if(rm == 20) rm = 1; + if((e == re) && (s == rs) && (m == rm)) break; + } + System.out.println(ans); + } +} diff --git "a/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" "b/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" new file mode 100644 index 0000000..4247752 --- /dev/null +++ "b/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" @@ -0,0 +1,22 @@ +package problum1543; + +import java.util.Scanner; + +public class 문서검색_1543 { + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + String str1 = sc.next(); + String str2 = sc.next(); + int cnt = 0; + + for(int i=0; i Date: Mon, 25 Jul 2022 19:48:11 +0900 Subject: [PATCH 019/822] 07.25 time over --- ...54\353\250\271\353\212\224\353\215\260.py" | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" "b/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" index 05aa0fb..c68f52a 100644 --- "a/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" +++ "b/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" @@ -1,19 +1,18 @@ import itertools -# def solution(_n, _m, _arr) -> int : -# count = 0 -# for i in itertools.combinations(range(1, _n+1), 3): -# for j in _arr: -# set_i = set(i) -# if set_i - j != set_i : break -# else : -# print(count) -# print(i) -# print(j) -# count += 1 -# return count -# -# n, m = map(int, input().split()) -# arr = [list(map(int, input().split())) for i in range(m)] -# answer = solution(n, m, arr) -# print(answer) \ No newline at end of file +def solution(_n, _m, _arr) -> int : + count = 0 + for combs in itertools.combinations(range(1, _n+1), 3): + flag = 0 + for badComb in _arr: + if badComb[0] in combs and badComb[1] in combs: + flag = 1 + break + if flag: continue + else : count += 1 + return count + +n, m = map(int, input().split()) +arr = [list(map(int, input().split())) for i in range(m)] +answer = solution(n, m, arr) +print(answer) \ No newline at end of file From f5be4f2407810cca6190540dbdd6deb5346af475 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 25 Jul 2022 19:56:18 +0900 Subject: [PATCH 020/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=201476.jva?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 1476.jva" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" new file mode 100644 index 0000000..fc104b1 --- /dev/null +++ "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" @@ -0,0 +1,24 @@ +package etc; + +import java.util.Scanner; +public class 백준1476 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + int e =scan.nextInt(); + int s= scan.nextInt(); + int m=scan.nextInt(); + int original; + if(e==15) e=0; + if(m==19) m=0; + for(int i=0;;i++) { + original=28 *i+s; + if(original%15==e&&original%19==m) { + break; + } + } + System.out.println(original); + } + +} From 0168b2bd030f7903967af5fa66ba0f62ca86beb1 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 25 Jul 2022 19:56:37 +0900 Subject: [PATCH 021/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=201543.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 1543.java" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" new file mode 100644 index 0000000..d40a7f9 --- /dev/null +++ "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" @@ -0,0 +1,38 @@ +package etc; + +import java.util.Scanner; + +public class 백준1543 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + String str=scan.nextLine(); + String search=scan.nextLine(); + int tmp_cnt=0; + int ans_cnt=0; + int search_leng=search.length(); + int str_leng=str.length(); + for(int i=0;i Date: Mon, 25 Jul 2022 19:56:59 +0900 Subject: [PATCH 022/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=202422.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 2422.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" new file mode 100644 index 0000000..373be4e --- /dev/null +++ "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" @@ -0,0 +1,40 @@ +package etc; + +import java.util.ArrayList; +import java.util.Scanner; + +public class 백준2422 { + static int [][] arr; + static int[] visited; + static int ans=0,n,m; + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + + n=scan.nextInt(); + m=scan.nextInt(); + + arr=new int[n+1][n+1]; + visited=new int[n]; + for(int i=0;i Date: Mon, 25 Jul 2022 19:57:16 +0900 Subject: [PATCH 023/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=203085.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 3085.java" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" new file mode 100644 index 0000000..a7b9fbb --- /dev/null +++ "b/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" @@ -0,0 +1,92 @@ +package etc; + +import java.util.Scanner; + +public class 백준3085 { + static int max=0; + static int n; + static char[][] arr; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + n=scan.nextInt(); + arr=new char[n][n]; + + for(int i=0;i Date: Tue, 26 Jul 2022 08:53:17 +0900 Subject: [PATCH 024/822] Create readme.md --- 07.28/readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 07.28/readme.md diff --git a/07.28/readme.md b/07.28/readme.md new file mode 100644 index 0000000..c0cf2f2 --- /dev/null +++ b/07.28/readme.md @@ -0,0 +1,5 @@ +17086 아기 상어2 +https://www.acmicpc.net/problem/17086 + +2502 떡먹는 호랑이 +https://www.acmicpc.net/problem/2502 From 415f45c7b020590bdef2936d4220616e7fdfd039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 26 Jul 2022 08:54:44 +0900 Subject: [PATCH 025/822] Update readme.md --- 07.28/readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/07.28/readme.md b/07.28/readme.md index c0cf2f2..297231a 100644 --- a/07.28/readme.md +++ b/07.28/readme.md @@ -1,3 +1,5 @@ +## 07.28 (목) 8시 + 17086 아기 상어2 https://www.acmicpc.net/problem/17086 From a990512923ee3dc6b55fc039169c328aee616b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 26 Jul 2022 13:53:18 +0900 Subject: [PATCH 026/822] =?UTF-8?q?Create=202502=5F=EB=96=A1=EB=A8=B9?= =?UTF-8?q?=EB=8A=94=5F=ED=98=B8=EB=9E=91=EC=9D=B4.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\355\230\270\353\236\221\354\235\264.cpp" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" diff --git "a/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" "b/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" new file mode 100644 index 0000000..c1a088f --- /dev/null +++ "b/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" @@ -0,0 +1,27 @@ +#include +#include +using namespace std; + +int D, K; +int checkSum(int A,int B) { + int next = A + B; + for (int i = 0; i < D-3; i++) { + A = B; + B = next; + next = A + B; + } + return next; +} + +int main() { + cin >> D >> K; + for (int i = 1; i <= K; i++) { + for (int k = i; k <= K; k++) { + if (checkSum(i, k) == K) { + cout << i << '\n' << k << endl; + return 0; + } + } + } + return 0; +} From a64a3aed9b76d3508bf38d3012e386e1efc080b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Tue, 26 Jul 2022 17:06:11 +0900 Subject: [PATCH 027/822] solve --- ...\355\230\270\353\236\221\354\235\264.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" diff --git "a/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" "b/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" new file mode 100644 index 0000000..084d213 --- /dev/null +++ "b/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" @@ -0,0 +1,44 @@ +import java.io.*; +import java.util.StringTokenizer; + +public class Main { + + public static int D; // 넘어온 날 + public static int K; // 떡 개수 + + public static int[] k_arr; + + public static void main(String[] args) throws Exception { + // System.setIn(new FileInputStream("res/1143.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + + D = Integer.parseInt(token.nextToken()); + K = Integer.parseInt(token.nextToken()); + + k_arr = new int[D]; + + search(); + + } + + private static void search() { + + for (int i = 1; i <= K / 2; i++) { // A + for (int j = i + 1; j < K; j++) { // B + k_arr[0] = i; + k_arr[1] = j; + for (int k = 2; k < k_arr.length; k++) { + k_arr[k] = k_arr[k - 2] + k_arr[k - 1]; + } + if (k_arr[D - 1] == K) { + System.out.println(k_arr[0]); // 첫째 날 + System.out.println(k_arr[1]); // 둘째 날 + System.exit(0); + } + } + + } + } +} From c20ce28a255f32a1a7da5c1d4bbd8455cc2ba91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 27 Jul 2022 13:05:54 +0900 Subject: [PATCH 028/822] =?UTF-8?q?Create=201706=5F=EC=95=84=EA=B8=B0?= =?UTF-8?q?=EC=83=81=EC=96=B42.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\270\260\354\203\201\354\226\2642.cpp" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" diff --git "a/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" "b/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" new file mode 100644 index 0000000..b3948b0 --- /dev/null +++ "b/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" @@ -0,0 +1,44 @@ +#include +#include +#include +using namespace std; +int goX[] = {-1,-1,-1,0,0,1,1,1}; +int goY[] = {-1,0,1,-1,1,-1,0,1}; + +int main() { + int N, M; cin >> N >> M; + vector> board; + queue> q; + int answer = 0; + bool visited[51][51] = { false }; + for (int i = 0; i < N; i++) { + vector list; + for (int k = 0; k < M; k++) { + int n; cin >> n; + if (n > 0) { + q.push({ i,k }); + } + list.push_back(n); + } + board.push_back(list); + } + + while (!q.empty()) { + int x = q.front().first, y = q.front().second; + q.pop(); + for (int i = 0; i < 8; i++) { + int nx = x + goX[i]; + int ny = y + goY[i]; + if (0 <= nx && nx < N && 0 <= ny && ny < M && !visited[nx][ny]) { + visited[nx][ny] = true; + if (board[nx][ny] == 0 || board[nx][ny] >= board[x][y]+1) { + board[nx][ny] = board[x][y] + 1; + answer = max(answer, board[nx][ny]); + } + q.push({ nx,ny }); + } + } + } + cout << answer-1 << endl; + return 0; +} From ac4306d35de4559e7d04558bd7bc4fe1264ae2ac Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 27 Jul 2022 23:08:00 +0900 Subject: [PATCH 029/822] kihun --- ...4\352\270\260\354\203\201\354\226\2642.py" | 34 +++++++++++++++++++ ...24\355\230\270\353\236\221\354\235\264.py" | 21 ++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 "07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" create mode 100644 "07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" diff --git "a/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" "b/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" new file mode 100644 index 0000000..e6c2b26 --- /dev/null +++ "b/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" @@ -0,0 +1,34 @@ +N, M = map(int, input().split()) + +matrix = [] +distance = [0] * (N * M) +sharkIdx = [] + +# 1차원 만들기, 상어 좌표 받기 +for y in range(N): + row = list(map(int, input().split())) + for x in range(M): + if row[x] == 1: + sharkIdx.append((y, x)) + matrix += row + +for i in range(len(sharkIdx)): + sharkY = sharkIdx[i][0] + sharkX = sharkIdx[i][1] + for idx in range(N * M): + if matrix[idx] == 1: + continue + + y = idx // M + x = idx % M + + diffY = abs(sharkY - y) + diffX = abs(sharkX - x) + + tempDis = max(diffY, diffX) + if i == 0: + distance[idx] = tempDis + else: + if distance[idx] > tempDis: + distance[idx] = tempDis +print(max(distance)) diff --git "a/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" "b/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" new file mode 100644 index 0000000..5f3d1ca --- /dev/null +++ "b/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" @@ -0,0 +1,21 @@ +D, K = map(int, input().split()) + +# arr = [0, 0, 0, 0, 0, 0] +arr = [0 for _ in range(D)] + +a = 1 + +# a = 1, b = 1부터 대입해서 무한 반복 +while a <= K: + for b in range(1, K): + arr[0] = a + arr[1] = b + + for i in range(2, D): + arr[i] = arr[i - 1] + arr[i - 2] + + if arr[D - 1] == K: + print(arr[0]) + print(arr[1]) + exit() + a += 1 From c38a7626d4802c4610a98246448eb3b233d7cc02 Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 27 Jul 2022 23:58:49 +0900 Subject: [PATCH 030/822] solve --- ...52\270\260_\354\203\201\354\226\2642.java" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" diff --git "a/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" "b/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" new file mode 100644 index 0000000..deb6ca8 --- /dev/null +++ "b/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" @@ -0,0 +1,66 @@ +import java.awt.Point; +import java.io.*; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Main { + + static int N; + static int M; + static int distance = 0; + static int graph[][]; + static int visited[][]; + static int [] dx = {-1,-1,-1,1,1,1,0,0}; //x축 방향 + static int [] dy = {-1,0,1,-1,0,1,-1,1}; //y축 방향 + static Queue shark = new LinkedList(); //상어 좌표 + + + + public static void main(String[] args) throws Exception { + // System.setIn(new FileInputStream("res/1143.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(br.readLine()); + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + graph = new int[N][M]; + visited = new int[N][M]; + + for (int i = 0; i < N; i++) { + token = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + graph[i][j] = Integer.parseInt(token.nextToken()); + visited[i][j] = Integer.MAX_VALUE; + if (graph[i][j] == 1 ) { + shark.add(new Point(i,j)); + visited[i][j] = 0; + } + } + } + + bfs(); + System.out.println(distance); + } + + static void bfs() { + while(!shark.isEmpty()) { + Point point = shark.poll(); + + for (int i = 0; i < dx.length; i++) { + int x = point.x+dx[i]; + int y = point.y+dy[i]; + + if (x >= 0 && x < N && y >= 0 && y < M ) { + if (visited[x][y] > visited[point.x][point.y] + 1) { + visited[x][y] = visited[point.x][point.y] + 1; + + distance = Math.max(distance, visited[x][y]); + shark.add(new Point(x,y)); + } + } + } + } + } + + +} From 312f0eca1677b390f4f004a62cd5e47618da7c8e Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Thu, 28 Jul 2022 00:10:31 +0900 Subject: [PATCH 031/822] complete --- ...2\270\260_\354\203\201\354\226\264_2.java" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" diff --git "a/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" "b/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" new file mode 100644 index 0000000..95aaa42 --- /dev/null +++ "b/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" @@ -0,0 +1,79 @@ +import java.util.*; +import java.io.*; + +public class Main_17086_아기_상어_2 { + static int arr[][]; + static int dirX[] = {0, 0, -1, 1, -1, 1, 1, -1}; // 상 하 좌 우 + static int dirY[] = {-1, 1, 0, 0, -1, -1, 1, 1}; + static int N, M; + static int nowX, nowY; + static int max = -1; + + public static class Node { + int x; + int y; + int dist; + + public Node(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/17086.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new int[N][M]; + + for(int i=0; i que = new LinkedList<>(); + que.offer(new Node(x, y, 0)); + boolean visit[][] = new boolean[N][M]; + visit[x][y] = true; + + while( !que.isEmpty() ) { + Node node = que.poll(); + + for(int i=0; i<8; i++) { + nowX = dirX[i] + node.x; + nowY = dirY[i] + node.y; + + if(!range_check() || visit[nowX][nowY]) continue; + if(arr[nowX][nowY] == 1) { + max = Math.max(max, node.dist + 1); + return; + } + + visit[nowX][nowY] = true; + que.offer(new Node(nowX, nowY, node.dist + 1)); + } + } + } // End of BFS + + private static boolean range_check() { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check +} // End of Main class \ No newline at end of file From 98e74e03ba8fd8e82eb3641ee9bff63d414c201b Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 28 Jul 2022 08:59:10 +0900 Subject: [PATCH 032/822] =?UTF-8?q?2505=5F=EB=96=A1=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=ED=98=B8=EB=9E=91=EC=9D=B4=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\270\260\354\203\201\354\226\2642.py" | 15 ++++++++++ ...24\355\230\270\353\236\221\354\235\264.py" | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 "07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" create mode 100644 "07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" diff --git "a/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" "b/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" new file mode 100644 index 0000000..dbe44f1 --- /dev/null +++ "b/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" @@ -0,0 +1,15 @@ + +def solution(_n, _m, _arr) -> int: + return 0 + + +def main(): + n, m = map(int, input().split()) + n_list = [list(map(int, input().split())) for i in range(n)] + answer = solution(n, m, n_list) + print(answer) + + +# -- 실행 함수 +if __name__ == '__main__': + main() \ No newline at end of file diff --git "a/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" "b/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" new file mode 100644 index 0000000..3e763c9 --- /dev/null +++ "b/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" @@ -0,0 +1,30 @@ +#------------------------------------------------------------------------------------------------ +def is_fibo(_arr, _d) -> bool: + for i in range(3, _d) : + _arr[i] = _arr[i - 1] + _arr[i - 2] + if _arr[_d] == _arr[_d - 1] + _arr[_d - 2] : return True + else : return False + + +def solution(_arr, _d, _limit) -> (int, int): + count = 1 + while count < _limit + 1: # index <= limit + for i in range(count, _limit + 1): # index <= limit + _arr[1], _arr[2] = count, i + if is_fibo(_arr, _d): return _arr[1], _arr[2] + count += 1 + return -1, -1 + + +def main(): + d, k = map(int, input().split()) + arr = [0] * (d + 1) # 배열 선언 + arr[d] = k # 배열 값 대입 + limit = (k//(d-2)) # 초기 값들 최대 범위 설정 + a, b = solution(arr, d, limit) + print(a, b, sep='\n') + + +# -- 실행 함수 ------------------------------------------------------------------------------------ +if __name__ == '__main__': + main() \ No newline at end of file From f3e7731185d5f58458bfe7c754a77f87530685ce Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Thu, 28 Jul 2022 19:05:17 +0900 Subject: [PATCH 033/822] complete --- ...\355\230\270\353\236\221\354\235\264.java" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" diff --git "a/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" "b/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" new file mode 100644 index 0000000..07b7faf --- /dev/null +++ "b/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" @@ -0,0 +1,38 @@ +import java.util.*; +import java.io.*; + +public class Main_2502_떡_먹는_호랑이 { + static int memo[]; + static int D; static int K; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2502.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + D = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + memo = new int[D]; // 넘어논 날 만큼 배열 생성 + memo[D - 1] = K; // 배열 떡의 마지막 부분은 마지막 날 호랑이에게 준 떡의 개수 + DP(1); + } // End of main + + private static void DP(int ans) { + memo[0] = ans; + + for (int i=ans; i Date: Thu, 28 Jul 2022 19:07:17 +0900 Subject: [PATCH 034/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=202502.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 2502.java" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" diff --git "a/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" "b/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" new file mode 100644 index 0000000..989fad8 --- /dev/null +++ "b/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class Main { + static int D, K; + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + + D=scan.nextInt(); + K=scan.nextInt(); + for(int i=1;i<=K;i++) { + for(int j=i;j<=K;j++) { + int[] arr=sol(i,j); + if(arr[0]==K) { + System.out.println(i); + System.out.println(j); + System.exit(0); + } + } + } + + + } + static int[] sol(int a,int b) { + int nexta=a,nextb=b; + for(int i=0;i"+nexta+" "+nextb); + int[] arr= {nexta,nextb}; + return arr; + } + + +} From 4cc6a622d3be862d5e834153994c33ca0b99832e Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Thu, 28 Jul 2022 19:07:47 +0900 Subject: [PATCH 035/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=2017086.jav?= =?UTF-8?q?a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 17086.java" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" diff --git "a/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" "b/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" new file mode 100644 index 0000000..ecb592b --- /dev/null +++ "b/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" @@ -0,0 +1,66 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; +class point{ + int x; + int y; + public point(int x,int y) { + // TODO Auto-generated constructor stub + this.x=x; + this.y=y; + } +} + +public class Main { + static int[] dx= {1,-1,0,0,1,1,-1,-1}; + static int[] dy= {0,0,-1,1,-1,1,-1,1}; + static int m,n; + static int[][] visited; + static int [][]arr; + static Queue q; + static int max=Integer.MIN_VALUE; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + + n=scan.nextInt(); + m=scan.nextInt(); + arr=new int [n][m]; + visited=new int [n][m]; + q=new LinkedList<>(); + for(int i=0;i=0&&ny>=0&&nxmax) { + max=visited[nx][ny]; + } + + q.add(new point(nx,ny)); + } + } + } + } + + } + +} From 67b34ed8e16c681efce7e1c45f409fb5c9c672c9 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 28 Jul 2022 19:39:52 +0900 Subject: [PATCH 036/822] =?UTF-8?q?17086=5F=EC=95=84=EA=B8=B0=EC=83=81?= =?UTF-8?q?=EC=96=B42=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\270\260\354\203\201\354\226\2642.py" | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git "a/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" "b/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" index dbe44f1..b8f6063 100644 --- "a/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" +++ "b/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" @@ -1,15 +1,39 @@ +from collections import deque -def solution(_n, _m, _arr) -> int: - return 0 + +dx = [0, 1, 1, 1, 0, -1, -1, -1] # 가능한 모든 방향 : 8방향 +dy = [-1, -1, 0, 1, 1, 1, 0, -1] # 가능한 모든 방향 : 8방향 +search_order = deque() + + +def bfs(_n, _m, _visited): + while search_order: # 종료 조건 : 더 이상 방문할 곳이 없는 경우. (즉, 모든 곳을 방문한 경우) + x, y = search_order.popleft() + for i in range(8): + nx, ny = x + dx[i], y + dy[i] # 이동할 방향 생성 + if nx < 0 or nx >= _n or ny < 0 or ny >= _m: continue # 배열을 벗어 나면 X. + if _visited[nx][ny] == 0: # 상어도 방문한 적도 없을 때 + _visited[nx][ny] = _visited[x][y] + 1 + search_order.append([nx, ny]) + + +def solution(_n, _m, _inputs) -> int: + for x in range(_n): + for y in range(_m): + if _inputs[x][y] : + search_order.append([x,y]) + bfs(_n,_m, _inputs) + max_val = max(map(max, _inputs)) + return max_val -1 def main(): n, m = map(int, input().split()) - n_list = [list(map(int, input().split())) for i in range(n)] - answer = solution(n, m, n_list) + input_list = [list(map(int, input().split())) for i in range(n)] + answer = solution(n, m, input_list) print(answer) -# -- 실행 함수 +# -- 실행 함수 ------------------------------------------------------------------------------------ if __name__ == '__main__': main() \ No newline at end of file From 475e4b5c8b47bd2831a70c12a5b1709b77ea2cd6 Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Thu, 28 Jul 2022 20:12:28 +0900 Subject: [PATCH 037/822] =?UTF-8?q?Update=202502=5F=EB=96=A1=EB=A8=B9?= =?UTF-8?q?=EB=8A=94=ED=98=B8=EB=9E=91=EC=9D=B4.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" "b/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" index 5f3d1ca..5fedd70 100644 --- "a/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" +++ "b/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" @@ -7,7 +7,7 @@ # a = 1, b = 1부터 대입해서 무한 반복 while a <= K: - for b in range(1, K): + for b in range(a, K): arr[0] = a arr[1] = b From 43971dfe0ac4ced92508c2cda432a2edff7a725d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 28 Jul 2022 20:59:56 +0900 Subject: [PATCH 038/822] Create readme.md --- 08.01/readme.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 08.01/readme.md diff --git a/08.01/readme.md b/08.01/readme.md new file mode 100644 index 0000000..212557b --- /dev/null +++ b/08.01/readme.md @@ -0,0 +1,13 @@ +8.1(월) 8시 스터디 + +1. 1388) 바닥장식 +https://www.acmicpc.net/problem/1388 + +2. 16173) 점프왕 젤리 +https://www.acmicpc.net/problem/16173 + +3. 2606) 바이러스 +https://www.acmicpc.net/problem/2606 + +4. 11725) 트리의 부모찾기 +https://www.acmicpc.net/problem/11725 From d68096a86e365bf2b5770347400e5de8a35adfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 28 Jul 2022 21:00:22 +0900 Subject: [PATCH 039/822] Update readme.md --- 08.01/readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/08.01/readme.md b/08.01/readme.md index 212557b..1261d1a 100644 --- a/08.01/readme.md +++ b/08.01/readme.md @@ -1,13 +1,13 @@ 8.1(월) 8시 스터디 -1. 1388) 바닥장식 +1388 바닥장식 https://www.acmicpc.net/problem/1388 -2. 16173) 점프왕 젤리 +16173 점프왕 젤리 https://www.acmicpc.net/problem/16173 -3. 2606) 바이러스 +2606 바이러스 https://www.acmicpc.net/problem/2606 -4. 11725) 트리의 부모찾기 +11725 트리의 부모찾기 https://www.acmicpc.net/problem/11725 From 11ca253da55b2a39bee074d066e72918ab38dd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 29 Jul 2022 15:03:29 +0900 Subject: [PATCH 040/822] =?UTF-8?q?Create=201388=5F=EB=B0=94=EB=8B=A5?= =?UTF-8?q?=EC=9E=A5=EC=8B=9D.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\213\245\354\236\245\354\213\235.cpp" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "08.01/\354\235\264\354\225\204\353\246\204/1388_\353\260\224\353\213\245\354\236\245\354\213\235.cpp" diff --git "a/08.01/\354\235\264\354\225\204\353\246\204/1388_\353\260\224\353\213\245\354\236\245\354\213\235.cpp" "b/08.01/\354\235\264\354\225\204\353\246\204/1388_\353\260\224\353\213\245\354\236\245\354\213\235.cpp" new file mode 100644 index 0000000..760e496 --- /dev/null +++ "b/08.01/\354\235\264\354\225\204\353\246\204/1388_\353\260\224\353\213\245\354\236\245\354\213\235.cpp" @@ -0,0 +1,43 @@ +#include +#include +#include +#include +using namespace std; +int main() { + int N, M; cin >> N >> M; + vector board; + for (int i = 0; i < N; i++) { + string str; cin >> str; + board.push_back(str); + } + bool visit[51][51] = { false }; + int count = N * M; + //if _ -> +(0,1) -> _이면 전체 count -1 push + // | -> (+1,0) | 이면 전체 count-1 push + queue> q; + for (int i = 0; i < N; i++) { + for (int k = 0; k < M; k++) { + if (!visit[i][k]) { + visit[i][k] = true; + q.push({ i,k }); + } + while (!q.empty()) { + int x = q.front().first, y= q.front().second; + int xx, yy; + q.pop(); + if (board[x][y] == '-') { + xx = x; yy = y + 1; + } + else { + xx = x + 1; yy = y; + } + if (xx < N && yy < M && board[x][y] == board[xx][yy]) { + visit[xx][yy] = true; + count--; + q.push({ xx,yy }); + } + } + } + } + cout << count << endl; +} From 21f154cd5c49c95fbf11b8f5957bcf073ae8353f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 29 Jul 2022 15:16:30 +0900 Subject: [PATCH 041/822] =?UTF-8?q?Create=2016173=5F=EC=A0=90=ED=94=84?= =?UTF-8?q?=EC=99=95=EC=A0=A4=EB=A6=AC.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\231\225\354\240\244\353\246\254.cpp" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "08.01/\354\235\264\354\225\204\353\246\204/16173_\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.cpp" diff --git "a/08.01/\354\235\264\354\225\204\353\246\204/16173_\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.cpp" "b/08.01/\354\235\264\354\225\204\353\246\204/16173_\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.cpp" new file mode 100644 index 0000000..4f653b1 --- /dev/null +++ "b/08.01/\354\235\264\354\225\204\353\246\204/16173_\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.cpp" @@ -0,0 +1,40 @@ +#include +#include +#include +using namespace std; +int main() { + int toX[] = { 0,1 }; + int toY[] = { 1,0 }; + int N; cin >> N; + vector> board; + for (int i = 0; i < N; i++) { + vector list; + for (int k = 0; k < N; k++) { + int n; cin >> n; + list.push_back(n); + } + board.push_back(list); + } + queue> q; + bool visit[5][5] = { false }; //왜 visit를 찍어야하지? - 이미 지나가봤던 실패케이스는 가지 않기위해 + q.push({ 0,0 }); + while (!q.empty()) { + int x = q.front().first; + int y = q.front().second; + q.pop(); + if (board[x][y] == -1) { + cout << "HaruHaru" << endl; + return 0; + } + for (int i = 0; i < 2; i++) { + int xx = x + (toX[i] * board[x][y]); + int yy = y + (toY[i] * board[x][y]); + if (xx < N && yy < N && !visit[xx][yy]) { + q.push({ xx,yy }); + visit[xx][yy] = true; + } + } + } + cout << "Hing" << endl; + return 0; +} From 97edcb998eceb7a154efb3e13b67bc3cd78eb638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 29 Jul 2022 16:38:13 +0900 Subject: [PATCH 042/822] =?UTF-8?q?Create=202606=5F=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EB=9F=AC=EC=8A=A4.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\264\353\237\254\354\212\244.cpp" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "08.01/\354\235\264\354\225\204\353\246\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244.cpp" diff --git "a/08.01/\354\235\264\354\225\204\353\246\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244.cpp" "b/08.01/\354\235\264\354\225\204\353\246\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244.cpp" new file mode 100644 index 0000000..e7434c2 --- /dev/null +++ "b/08.01/\354\235\264\354\225\204\353\246\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244.cpp" @@ -0,0 +1,31 @@ +#include +#include +#include +using namespace std; + +int main() { + bool visited[200] = { false }; + bool connect[200][200] = { false }; + int N, K; cin >> N >> K; + for (int i = 0; i < K; i++) { + int c1, c2; cin >> c1 >> c2; + connect[c1][c2] = connect[c2][c1] = true; + } + int count = 0; + queue q; + q.push(1); + visited[1] = true; + while (!q.empty()) { + int computer = q.front(); + q.pop(); + for (int i = 1; i <= N; i++) { + if (connect[computer][i] && !visited[i]) { + visited[i] = true; + count++; + q.push(i); + } + } + } + cout << count << endl; + return 0; +} From 3ddaaac1ce1a830b8b32ae7af69e8ae11e68d3c0 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 29 Jul 2022 22:54:03 +0900 Subject: [PATCH 043/822] =?UTF-8?q?1388=5F=EB=B0=94=EB=8B=A5=EC=9E=A5?= =?UTF-8?q?=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\245\354\236\245\354\213\235.java" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" new file mode 100644 index 0000000..b7c06d4 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" @@ -0,0 +1,61 @@ +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(token.nextToken()); + int M = Integer.parseInt(token.nextToken()); + + char[][] board = new char[N][M]; + char width = 'w'; + char height = 'h'; + int count = 0; + + for (int i = 0; i < N; i++) { + String input = br.readLine(); + for (int j = 0; j < M; j++) { + board[i][j] = input.charAt(j); + } + } + + // Ž + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (width != '-') { + if (board[i][j] == '-') { + count++; + width = '-'; + }else continue; + }else { + if (board[i][j] == '-' ) continue; + else width = 'w'; + } + } + width = 'w'; + + } + + // Ž + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + if (height != '|') { + if (board[j][i] == '|') { + count++; + height = '|'; + }else continue; + }else { + if (board[j][i] == '|' ) continue; + else height = 'h'; + } + } + height = 'h'; + } + + System.out.println(count); + + } +} From 83fa05cf9a3e01e2affd1424c7e58dd974e3363f Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sat, 30 Jul 2022 02:22:26 +0900 Subject: [PATCH 044/822] complete --- ...353\213\245_\354\236\245\354\213\235.java" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" new file mode 100644 index 0000000..0828949 --- /dev/null +++ "b/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" @@ -0,0 +1,77 @@ +import java.util.*; +import java.io.*; + +// 기훈이의 방 바닥을 장식하는데 필요한 나무 판자의 개수를 출력하는 프로그램을 작성하시오. + +// -는 인접, 같은 행 , |는 인접 같은 열 + +public class Main_1388_바닥_장식 { + static int N; + static int M; + static char arr[][]; + static boolean visit[][]; + static int nowX; static int nowY; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + + static int result = 0; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1388.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + arr = new char[N][M]; + visit = new boolean[N][M]; + for (int i = 0; i < N; i++) { + String temp = br.readLine(); + for (int j = 0; j < M; j++) { + arr[i][j] = temp.charAt(j); + } + } + + int result = 0; + // 가로 모양 타일 탐색 + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if(!visit[i][j] && arr[i][j] == '-') { + DFS(i, j, 0, 2, '-'); + result++; + } + } + } + + + // 세로 + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + if(!visit[j][i] && arr[j][i] == '|') { + DFS(j, i, 2, 4, '|'); + result++; + } + } + } + + System.out.println(result); + } // End of main + + private static void DFS(int x, int y, int idxStart, int idxEnd, char ch) { + visit[x][y] = true; + + for(int i=idxStart; i= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check +} // End of Main class \ No newline at end of file From 87e881a0769b138a3160f8b6187cc37bc333ec4d Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 10:10:38 +0900 Subject: [PATCH 045/822] reload --- ...\353\213\245\354\236\245\354\213\235.java" | 61 ------------------- 1 file changed, 61 deletions(-) delete mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" deleted file mode 100644 index b7c06d4..0000000 --- "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" +++ /dev/null @@ -1,61 +0,0 @@ -import java.io.*; -import java.util.*; - -public class Main { - - public static void main(String[] args) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer token = new StringTokenizer(br.readLine()); - - int N = Integer.parseInt(token.nextToken()); - int M = Integer.parseInt(token.nextToken()); - - char[][] board = new char[N][M]; - char width = 'w'; - char height = 'h'; - int count = 0; - - for (int i = 0; i < N; i++) { - String input = br.readLine(); - for (int j = 0; j < M; j++) { - board[i][j] = input.charAt(j); - } - } - - // Ž - for (int i = 0; i < N; i++) { - for (int j = 0; j < M; j++) { - if (width != '-') { - if (board[i][j] == '-') { - count++; - width = '-'; - }else continue; - }else { - if (board[i][j] == '-' ) continue; - else width = 'w'; - } - } - width = 'w'; - - } - - // Ž - for (int i = 0; i < M; i++) { - for (int j = 0; j < N; j++) { - if (height != '|') { - if (board[j][i] == '|') { - count++; - height = '|'; - }else continue; - }else { - if (board[j][i] == '|' ) continue; - else height = 'h'; - } - } - height = 'h'; - } - - System.out.println(count); - - } -} From a7fe97908ebc2a337716cc63f25b560dabe46b55 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 10:11:54 +0900 Subject: [PATCH 046/822] =?UTF-8?q?1388=5F=EB=B0=94=EB=8B=A5=EC=9E=A5?= =?UTF-8?q?=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\245\354\236\245\354\213\235.java" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" new file mode 100644 index 0000000..b7c06d4 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" @@ -0,0 +1,61 @@ +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(token.nextToken()); + int M = Integer.parseInt(token.nextToken()); + + char[][] board = new char[N][M]; + char width = 'w'; + char height = 'h'; + int count = 0; + + for (int i = 0; i < N; i++) { + String input = br.readLine(); + for (int j = 0; j < M; j++) { + board[i][j] = input.charAt(j); + } + } + + // Ž + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (width != '-') { + if (board[i][j] == '-') { + count++; + width = '-'; + }else continue; + }else { + if (board[i][j] == '-' ) continue; + else width = 'w'; + } + } + width = 'w'; + + } + + // Ž + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + if (height != '|') { + if (board[j][i] == '|') { + count++; + height = '|'; + }else continue; + }else { + if (board[j][i] == '|' ) continue; + else height = 'h'; + } + } + height = 'h'; + } + + System.out.println(count); + + } +} From 74857ef5b67434efc1295aa3b4b81c01d898cbfb Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 10:15:03 +0900 Subject: [PATCH 047/822] =?UTF-8?q?=EC=9E=AC=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\245\354\236\245\354\213\235.java" | 61 ------------------- 1 file changed, 61 deletions(-) delete mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" deleted file mode 100644 index b7c06d4..0000000 --- "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" +++ /dev/null @@ -1,61 +0,0 @@ -import java.io.*; -import java.util.*; - -public class Main { - - public static void main(String[] args) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer token = new StringTokenizer(br.readLine()); - - int N = Integer.parseInt(token.nextToken()); - int M = Integer.parseInt(token.nextToken()); - - char[][] board = new char[N][M]; - char width = 'w'; - char height = 'h'; - int count = 0; - - for (int i = 0; i < N; i++) { - String input = br.readLine(); - for (int j = 0; j < M; j++) { - board[i][j] = input.charAt(j); - } - } - - // Ž - for (int i = 0; i < N; i++) { - for (int j = 0; j < M; j++) { - if (width != '-') { - if (board[i][j] == '-') { - count++; - width = '-'; - }else continue; - }else { - if (board[i][j] == '-' ) continue; - else width = 'w'; - } - } - width = 'w'; - - } - - // Ž - for (int i = 0; i < M; i++) { - for (int j = 0; j < N; j++) { - if (height != '|') { - if (board[j][i] == '|') { - count++; - height = '|'; - }else continue; - }else { - if (board[j][i] == '|' ) continue; - else height = 'h'; - } - } - height = 'h'; - } - - System.out.println(count); - - } -} From 1df68b519dd79a78fea857de6332bc696a21ac4a Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 10:15:39 +0900 Subject: [PATCH 048/822] =?UTF-8?q?1388)=EB=B0=94=EB=8B=A5=EC=9E=A5?= =?UTF-8?q?=EC=8B=9D=20clear!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\245\354\236\245\354\213\235.java" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" new file mode 100644 index 0000000..e64cdd0 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" @@ -0,0 +1,61 @@ +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(token.nextToken()); + int M = Integer.parseInt(token.nextToken()); + + char[][] board = new char[N][M]; + char width = 'w'; + char height = 'h'; + int count = 0; + + for (int i = 0; i < N; i++) { + String input = br.readLine(); + for (int j = 0; j < M; j++) { + board[i][j] = input.charAt(j); + } + } + + //가로줄 탐색 + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (width != '-') { + if (board[i][j] == '-') { + count++; + width = '-'; + }else continue; + }else { + if (board[i][j] == '-' ) continue; + else width = 'w'; + } + } + width = 'w'; + + } + + //세로줄 탐색 + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + if (height != '|') { + if (board[j][i] == '|') { + count++; + height = '|'; + }else continue; + }else { + if (board[j][i] == '|' ) continue; + else height = 'h'; + } + } + height = 'h'; + } + + System.out.println(count); + + } +} From 895ce9eadd04dfa6822568125d1bc90cdc3af33e Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sat, 30 Jul 2022 12:04:07 +0900 Subject: [PATCH 049/822] copmplete --- ...\235\264\353\237\254\354\212\244_BFS.java" | 66 +++++++++++++++++++ ...\235\264\353\237\254\354\212\244_DFS.java" | 48 ++++++++++++++ ...35\264\353\237\254\354\212\244_Floyd.java" | 63 ++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.java" create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd.java" diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.java" new file mode 100644 index 0000000..530595c --- /dev/null +++ "b/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.java" @@ -0,0 +1,66 @@ +import java.util.*; +import java.io.*; + +// https://www.acmicpc.net/problem/2606 + +// 목표 : 1번 컴퓨터가 웜 바이러스에 걸렸을 때, +// 1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터의 수를 첫째 줄에 출력한다. + +public class Main_2606_바이러스_BFS { + static Queue que = new LinkedList<>(); + static int arr[][]; + static boolean visit[]; + + static int N, M; + static int result = 0; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_2606.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); // 컴퓨터의 수 + M = Integer.parseInt(br.readLine()); // 컴퓨터 쌍의 수 + + // 1을 기준으로 한번만 탐색하면 됨. + // visit 배열은 1차원 배열로 생성. + visit = new boolean[N+1]; + arr = new int[N+1][N+1]; + for(int i=0; i Date: Sat, 30 Jul 2022 12:09:24 +0900 Subject: [PATCH 050/822] complete --- ...35\264\353\237\254\354\212\244_Floyd.java" | 63 ---------------- ...3\237\254\354\212\244_Floyd_Warshall.java" | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 63 deletions(-) delete mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd.java" create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd_Warshall.java" diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd.java" deleted file mode 100644 index 9d802d2..0000000 --- "a/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd.java" +++ /dev/null @@ -1,63 +0,0 @@ -import java.util.*; -import java.io.*; - -// https://www.acmicpc.net/problem/2606 - -// 목표 : 1번 컴퓨터가 웜 바이러스에 걸렸을 때, -// 1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터의 수를 첫째 줄에 출력한다. - -public class Main_2606_바이러스_Floyd { - static int arr[][]; - - static int N, M; - static int result = 0; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_2606.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st; - - N = Integer.parseInt(br.readLine()); // 컴퓨터의 수 - M = Integer.parseInt(br.readLine()); // 컴퓨터 쌍의 수 - - arr = new int[N+1][N+1]; - - for(int i=0; i 0) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + // 무방향 그래프 특성. + arr[x][y] = 1; + arr[y][x] = 1; + } + + // floyd_warshall (완전탐색) + // 각 노드에서 갈 수 있는 곳을 모두 탐색. + floyd(); + + int count = 0; + boolean node[] = new boolean[N+1]; + for(int i=1; i<=N; i++) { + + // 이미 등록된 노드는 탐색할 필요없음 + if(node[i] == true) { + continue; + } + + // 방문 가능한 노드는 바로 true처리. + for(int j=1; j<=N; j++) { + if(arr[i][j] == 1 && node[j] == false) { + node[j] = true; + } + } + + count ++; + } + + System.out.println(count); + + } // End of main + + static void floyd() { + + for(int k=0; k<=N; k++) { + for(int i=0; i<=N; i++) { + for(int j=0; j<=N; j++) { + + if(arr[i][k] == 1 && arr[k][j] == 1) { + arr[i][j] = 1; + } + } + } + } + + } // End of floyd + +} // End of class \ No newline at end of file From 09deb0d3b264ef63136359c42d167cb7cdc77022 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 12:20:40 +0900 Subject: [PATCH 051/822] =?UTF-8?q?2602=5F=EB=B0=94=EC=9D=B4=EB=9F=AC?= =?UTF-8?q?=EC=8A=A4=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\264\353\237\254\354\212\244.java" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" "b/08.01/\354\241\260\354\210\230\354\227\260/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" new file mode 100644 index 0000000..4ff6522 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" @@ -0,0 +1,62 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int computer; + static int pair; + static boolean[] infected = new boolean[101]; //감염되었다면 true + static Queue last = new LinkedList(); + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + computer = Integer.parseInt(br.readLine()); + pair = Integer.parseInt(br.readLine()); + int[][] pairs = new int[pair][2]; + + infected[0] = true; + infected[1] = true; + + last.add(1); //1부터 시작 + + + for (int i = 0; i < pair; i++) { //감염된 컴퓨터 쌍 + StringTokenizer token = new StringTokenizer(br.readLine()); + pairs[i][0] = Integer.parseInt(token.nextToken());; + pairs[i][1] = Integer.parseInt(token.nextToken()); + } + + while(true) { + if (last.isEmpty()) break; + + int last_index = last.poll(); + + for (int i = 0; i < pairs.length; i++) { //마지막으로 감염된 컴퓨터가 쌍에 있으면 last에 추가 이미 감염되었으면 continue + + if (pairs[i][0] == last_index) { + if (infected[pairs[i][1]] == false) { + infected[pairs[i][1]] = true; + last.add(pairs[i][1]); + } + }else if(pairs[i][1] == last_index) { + if (infected[pairs[i][0]] == false) { + infected[pairs[i][0]] = true; + last.add(pairs[i][0]); + } + } + } + } + + int count = 0; + + + for (int i = 2; i < infected.length; i++) { //감염된 컴퓨터 찾기 + if (infected[i]) { + count++; + } + } + + System.out.println(count); + } +} From 705c5364f8e6883dcc03d033115ec0b50cd2c6bd Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Sat, 30 Jul 2022 13:22:10 +0900 Subject: [PATCH 052/822] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index ac41e4b..bc746a3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,3 @@ - 스터디마다 작성하신 코드를 제출하는 곳입니다. - 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 - -## Contents -- [07.21.목](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.21) -- [07.25.월](https://github.com/SAlgorithmStudy6/StudyCodes/tree/main/07.25) From bccd92a6d5e0501585d931cf06c8be3b685d2daf Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 14:09:56 +0900 Subject: [PATCH 053/822] =?UTF-8?q?16173=20=EC=A0=90=ED=94=84=EC=99=95=20?= =?UTF-8?q?=EC=A9=B0=EB=A6=AC=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\231\225_\354\251\260\353\246\254.java" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" "b/08.01/\354\241\260\354\210\230\354\227\260/16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" new file mode 100644 index 0000000..354d0d8 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" @@ -0,0 +1,61 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int[][] area; + static int[] dx = {1,0}; //x축 + static int[] dy = {0,1}; //y축 + static Queue jelly = new LinkedList(); //젤리 좌표 + static boolean[][] visited; + static String result = "Hing"; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + + area = new int[N][N]; + jelly.add(new Point(0,0)); // 0,0부터 시작 + visited = new boolean[N][N]; + visited[0][0] = true; + + for (int i = 0; i < area.length; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 0; j < area.length; j++) { + area[i][j] = Integer.parseInt(token.nextToken()); + } + } + + move(); + System.out.println(result); + + } + + static void move() { + while(!jelly.isEmpty()) { + Point point = jelly.poll(); + + for (int i = 0; i < 2; i++) { + int x = point.x + ( dx[i] * area[point.x][point.y]); + int y = point.y + ( dy[i] * area[point.x][point.y]); + if (x >= 0 && x < N && y >= 0 && y < N) { + if (area[x][y] == -1) { + result = "HaruHaru"; + jelly.clear(); + break; + }else { + if (!visited[x][y]) { + jelly.add(new Point(x,y)); + visited[x][y] = true; + } + } + } + } + System.out.println("-------"+jelly); + } + } +} From 80a6958f7bb565b8249c7dad7fdab2dcdd8bc66d Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 16:30:25 +0900 Subject: [PATCH 054/822] =?UTF-8?q?11725=20=ED=8A=B8=EB=A6=AC=EC=9D=98=20?= =?UTF-8?q?=EB=B6=80=EB=AA=A8=20=EC=B0=BE=EA=B8=B0=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\252\250_\354\260\276\352\270\260.java" | 58 +++++++++++++++++++ ...\352\260\204\354\264\210\352\263\274.java" | 58 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" create mode 100644 "08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" "b/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" new file mode 100644 index 0000000..8781893 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" @@ -0,0 +1,58 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static boolean[] visited = new boolean[100001]; + static int[] node = new int[100001]; + static Queue current_floor = new LinkedList(); + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + N = Integer.parseInt(br.readLine()); + List pair[] = new ArrayList [N+1]; + + for (int i = 0; i < pair.length; i++) { + pair[i] = new ArrayList(); + } + + visited[1] = true; + node[1] = 1; + + for (int i = 0; i < N-1; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + int pair1 = Integer.parseInt(token.nextToken()); + int pair2 = Integer.parseInt(token.nextToken()); + + pair[pair1].add(pair2); + pair[pair2].add(pair1); + } + + current_floor.add(1); + + while (!current_floor.isEmpty()) { + + int parent = current_floor.poll(); + + for (Integer i : pair[parent]) { + if(!visited[i]) { + visited[i] = true; + node[i] = parent; + current_floor.add(i); + } + } + } + + for (int i = 2; i <= N ; i++) { + bw.write(String.valueOf(node[i])+"\n"); + } + + bw.flush(); + bw.close(); + + } + +} diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" "b/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" new file mode 100644 index 0000000..415c320 --- /dev/null +++ "b/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" @@ -0,0 +1,58 @@ +import java.io.*; +import java.util.*; + +public class Main2 { + + static int N; + static int[][] pair; + static boolean[] visited = new boolean[100001]; + static int[] node = new int[100001]; + static Queue current_floor = new LinkedList(); + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + N = Integer.parseInt(br.readLine()); + pair = new int[N - 1][2]; + visited[1] = true; + node[1] = 1; + + for (int i = 0; i < pair.length; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + pair[i][0] = Integer.parseInt(token.nextToken()); + pair[i][1] = Integer.parseInt(token.nextToken()); + } + + current_floor.add(1); + + while (!current_floor.isEmpty()) { + int parent = current_floor.poll(); + + for (int i = 0; i < pair.length; i++) { + if (pair[i][0] == parent) { + if (!visited[pair[i][1]]) { + visited[pair[i][1]] = true; + node[pair[i][1]] = parent; + current_floor.add(pair[i][1]); + } + } else if (pair[i][1] == parent) { + if(!visited[pair[i][0]]) { + visited[pair[i][0]] = true; + node[pair[i][0]] = parent; + current_floor.add(pair[i][0]); + } + } + } + } + + for (int i = 2; i <= N ; i++) { + bw.write(String.valueOf(node[i])+"\n"); + } + + bw.flush(); + bw.close(); + + } + +} From fbd21c735afdacb565033c896070baa4aa0a5450 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 30 Jul 2022 19:27:39 +0900 Subject: [PATCH 055/822] =?UTF-8?q?11725=5F=ED=8A=B8=EB=A6=AC=EC=9D=98=5F?= =?UTF-8?q?=EB=B6=80=EB=AA=A8=5F=EC=B0=BE=EA=B8=B0=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...200\353\252\250_\354\260\276\352\270\260.java" | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git "a/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" "b/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" index 8781893..935d84c 100644 --- "a/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" +++ "b/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" @@ -4,8 +4,8 @@ public class Main { static int N; - static boolean[] visited = new boolean[100001]; - static int[] node = new int[100001]; + static boolean[] visited = new boolean[100001]; //중복체크 + static int[] node = new int[100001]; //노드 배열 static Queue current_floor = new LinkedList(); public static void main(String[] args) throws Exception { @@ -13,16 +13,16 @@ public static void main(String[] args) throws Exception { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); N = Integer.parseInt(br.readLine()); - List pair[] = new ArrayList [N+1]; + List pair[] = new ArrayList [N+1]; //노드 짝 배열 for (int i = 0; i < pair.length; i++) { pair[i] = new ArrayList(); } - visited[1] = true; + visited[1] = true; node[1] = 1; - for (int i = 0; i < N-1; i++) { + for (int i = 0; i < N-1; i++) { StringTokenizer token = new StringTokenizer(br.readLine()); int pair1 = Integer.parseInt(token.nextToken()); int pair2 = Integer.parseInt(token.nextToken()); @@ -30,14 +30,15 @@ public static void main(String[] args) throws Exception { pair[pair1].add(pair2); pair[pair2].add(pair1); } - + current_floor.add(1); while (!current_floor.isEmpty()) { int parent = current_floor.poll(); - for (Integer i : pair[parent]) { + for (Integer i : pair[parent]) { //짝 배열에 current_floor poll값을 가져온 것에 노드 값 삽입 + if(!visited[i]) { visited[i] = true; node[i] = parent; From 17f8ba3bb842be40dcda0108c87aed3e6d390cdc Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sat, 30 Jul 2022 19:50:02 +0900 Subject: [PATCH 056/822] complete --- ...354\231\225_\354\251\260\353\246\254.java" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" new file mode 100644 index 0000000..5e7ec59 --- /dev/null +++ "b/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" @@ -0,0 +1,71 @@ +import java.util.*; +import java.io.*; + +public class Main_16173_점프왕_쩰리 { + static int N; + static int nowX; static int nowY; + static int arr[][]; + static int dirX[] = {1, 0}; // 하 우 + static int dirY[] = {0, 1}; + + private static class Node { + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/16173.txt")); + BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + arr = new int[N][N]; + + for(int i=0; i que = new LinkedList<>(); + boolean visit[][] = new boolean[N][N]; + visit[x][y] = true; + que.offer(new Node(x, y)); + + while(!que.isEmpty()) { + Node node = que.poll(); + + for(int i=0; i<2; i++) { + nowX = node.x + (dirX[i] * arr[node.x][node.y]); + nowY = node.y + (dirY[i] * arr[node.x][node.y]); + + if(range_check() && !visit[nowX][nowY]) { + if(arr[nowX][nowY] == -1) return true; + + visit[nowX][nowY] = true; + que.offer(new Node(nowX, nowY)); + } + } + } + + return false; + } // End of BFS + + private static boolean range_check() { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY Date: Sun, 31 Jul 2022 00:48:43 +0900 Subject: [PATCH 057/822] complete --- ...353\252\250_\354\260\276\352\270\260.java" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" new file mode 100644 index 0000000..0ca81a4 --- /dev/null +++ "b/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" @@ -0,0 +1,56 @@ +import java.util.*; +import java.io.*; + +// 뒤가 1이면, 앞자리 x값을 1을 넣음 +// 만약 y자리가 0이 아니라면 x자리에 y값이 들어감 + +public class Main_11725_트리의_부모_찾기 { + static int N; + static int node[]; + static List> list = new ArrayList<>(); + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/11725.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + node = new int[N+1]; + for(int i=0; i()); + + for(int i=0; i que = new LinkedList<>(); + que.offer(1); + + while(!que.isEmpty()) { + int nodeNum = que.poll(); + + for(int num : list.get(nodeNum)) { + if(node[num] == 0) { + node[num] = nodeNum; + que.offer(num); + } + } + + } + + } // End of BFS +} // End of Main class \ No newline at end of file From 0a7e73e3162e4a34ad2d962257db8f2706aeac11 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 31 Jul 2022 00:53:34 +0900 Subject: [PATCH 058/822] complete --- ...\266\200\353\252\250_\354\260\276\352\270\260.java" | 1 - ...0\224\354\235\264\353\237\254\354\212\244_BFS.java" | 8 ++------ ...0\224\354\235\264\353\237\254\354\212\244_DFS.java" | 10 ++++------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" index 0ca81a4..5e12292 100644 --- "a/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" +++ "b/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" @@ -29,7 +29,6 @@ public static void main(String[] args) throws Exception { list.get(y).add(x); } - node[1] = 1; BFS(); for(int i=2; i que = new LinkedList<>(); static int arr[][]; static boolean visit[]; - static int N, M; static int result = 0; @@ -41,7 +39,7 @@ public static void main(String[] args) throws Exception { // k를 통해 갈 수 있는 곳을 모두 연결 private static void BFS() { - + Queue que = new LinkedList<>(); que.offer(1); visit[1] = true; @@ -61,6 +59,4 @@ private static void BFS() { } } // End of BFS - - -} // End of class +} // End of class \ No newline at end of file diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" "b/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" index e0de1a3..7d24fc9 100644 --- "a/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" +++ "b/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" @@ -4,7 +4,6 @@ public class Main_2606_바이러스_DFS { static int arr[][]; static boolean visit[]; - static int N, M; static int result = 0; @@ -30,19 +29,18 @@ public static void main(String[] args) throws Exception { DFS(1); - System.out.println(result); - } + System.out.print(result); + } // End of main static void DFS(int node) { visit[node] = true; for(int i=1; i Date: Sun, 31 Jul 2022 13:00:05 +0900 Subject: [PATCH 059/822] Create readme.md --- "08.01/\355\231\251\354\247\200\354\233\220/readme.md" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "08.01/\355\231\251\354\247\200\354\233\220/readme.md" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.01/\355\231\251\354\247\200\354\233\220/readme.md" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/08.01/\355\231\251\354\247\200\354\233\220/readme.md" @@ -0,0 +1 @@ + From dd447d68406e808f5861667b40e71f6b97a1cbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 31 Jul 2022 13:00:51 +0900 Subject: [PATCH 060/822] =?UTF-8?q?Create=201388=5F=EB=B0=94=EB=8B=A5?= =?UTF-8?q?=EC=9E=A5=EC=8B=9D.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\245\354\236\245\354\213\235.java" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" new file mode 100644 index 0000000..b53677a --- /dev/null +++ "b/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" @@ -0,0 +1,72 @@ +import java.util.*; + +public class Main { + static int count = 0; + static char plank[][] = new char[50][50]; + static boolean visited[][] = new boolean[50][50]; + static int n; + static int m; + + static void bfs(int x, int y) { + int dx[] = { -1, 1, 0, 0}; // 상 하 , 좌 우 + int dy[] = { 0, 0, -1, 1}; + + + if (plank[x][y] == '-') { // 좌 우만 볼것 + for(int i=2; i<4; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if(0 <= nx && nx < n && 0 <= ny && ny < m) { + if(plank[nx][ny] == plank[x][y] && !visited[nx][ny]) { + visited[nx][ny] = true; + bfs(nx, ny); + } + } + } + }else { // 상하만 볼 것 + for(int i=0; i<2; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if(0 <= nx && nx < n && 0 <= ny && ny < m) { + if(plank[nx][ny] == plank[x][y] && !visited[nx][ny]) { + visited[nx][ny] = true; + bfs(nx, ny); + } + } + } + } + + } + + public static void main(String[] args) { + // 입력받기 + Scanner sc = new Scanner(System.in); + + n = sc.nextInt(); // 세로 + m = sc.nextInt(); // 가로 + sc.nextLine(); + + // 입력 + for (int i = 0; i < n; i++) { + String s = sc.nextLine(); + for (int j = 0; j < s.length(); j++) { + plank[i][j] = s.charAt(j); + } + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if(visited[i][j] == false) { + visited[i][j] = true; + count++; + bfs(i, j); + } + } + } + + System.out.println(count); + + } +} From 1b194ec777f8dd525c53008d68b0354da6a35135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 31 Jul 2022 13:06:26 +0900 Subject: [PATCH 061/822] Update readme.md --- "08.01/\355\231\251\354\247\200\354\233\220/readme.md" | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.01/\355\231\251\354\247\200\354\233\220/readme.md" index 8b13789..88b65af 100644 --- "a/08.01/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.01/\355\231\251\354\247\200\354\233\220/readme.md" @@ -1 +1,9 @@ +## 바닥장식 +0. static으로 int n, int m, boolean visited, char plank[50][50], int result 선언해주고 +1. [main] n, m 입력받기 +2. [main] plank에 입력하기 +3. [main] 2중 for문에서 자기자신 방문 true해주고 bfs함수 돌리기 +4. [bfs] '-' 모양이면 좌우만 비교해서 방문 false면 true로 바꿔주기 +5. [bfs] '|' 모양이면 상하만 비교해서 방문 false면 true로 바꿔주기 +6. [bfs] 다시 bfs함수에 다음 x, y값으로 nx, ny를 넣어서 재귀함수 실행 From 63eb3dddc85d82033f6075177d254880658f2e5d Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 31 Jul 2022 16:51:00 +0900 Subject: [PATCH 062/822] kihun --- ...00\353\252\250\354\260\276\352\270\260.py" | 25 +++++++++++++++++ ...24\353\213\245\354\236\245\354\213\235.py" | 23 ++++++++++++++++ ...04\354\231\225\354\251\260\353\246\254.py" | 27 +++++++++++++++++++ ...24\354\235\264\353\237\254\354\212\244.py" | 22 +++++++++++++++ ...4\354\212\244_\355\213\200\353\246\274.py" | 19 +++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.py" create mode 100644 "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1388_\353\260\224\353\213\245\354\236\245\354\213\235.py" create mode 100644 "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" create mode 100644 "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" create mode 100644 "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244_\355\213\200\353\246\274.py" diff --git "a/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.py" "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.py" new file mode 100644 index 0000000..0d12845 --- /dev/null +++ "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.py" @@ -0,0 +1,25 @@ +import sys +sys.setrecursionlimit(10**9) + +N = int(sys.stdin.readline()) + +tree = [[] for _ in range(N+1)] +visited = [0] * (N+1) + +for _ in range(N-1): + a, b = map(int, sys.stdin.readline().split()) + tree[a].append(b) + tree[b].append(a) + + +def dfs(x): + for i in tree[x]: + if visited[i] == 0: + visited[i] = x + dfs(i) + + +dfs(1) + +for i in range(2, N+1): + print(visited[i]) diff --git "a/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1388_\353\260\224\353\213\245\354\236\245\354\213\235.py" "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1388_\353\260\224\353\213\245\354\236\245\354\213\235.py" new file mode 100644 index 0000000..37726e9 --- /dev/null +++ "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1388_\353\260\224\353\213\245\354\236\245\354\213\235.py" @@ -0,0 +1,23 @@ +garo = '-' +sero = '|' + +N, M = map(int, input().split()) + +matrix = [] + +for _ in range(N): + matrix.append(list(input())) + +count = 0 + +for y in range(N): + for x in range(1, M): + if matrix[y][x] == garo and matrix[y][x - 1] == garo: + count += 1 + +for x in range(M): + for y in range(1, N): + if matrix[y][x] == sero and matrix[y - 1][x] == sero: + count += 1 + +print(N * M - count) diff --git "a/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" new file mode 100644 index 0000000..2360f25 --- /dev/null +++ "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" @@ -0,0 +1,27 @@ +N = int(input()) + +matrix = [] + +for i in range(N): + matrix.append(list(map(int, input().split()))) + +visited = [[False] * N for _ in range(N)] + + +def dfs(x, y): + if x >= N or y >= N: + return + + nowJelly = matrix[y][x] + if nowJelly == -1: + print("HaruHaru") + exit() + + if not visited[y][x]: + visited[y][x] = True + dfs(x + nowJelly, y) + dfs(x, y + nowJelly) + + +dfs(0, 0) +print("Hing") diff --git "a/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" new file mode 100644 index 0000000..0869cfc --- /dev/null +++ "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" @@ -0,0 +1,22 @@ +N = int(input()) +netNum = int(input()) + +netList = [[] for _ in range(N)] +virusList = [0 for _ in range(N)] + +for _ in range(netNum): + a, b = map(int, input().split()) + netList[a - 1].append(b) + netList[b - 1].append(a) + + +def dfs(netList, i, virusList): + virusList[i - 1] = 1 + for element in netList[i - 1]: + if virusList[element - 1] == 0: + dfs(netList, element, virusList) + return + + +dfs(netList, 1, virusList) +print(sum(virusList) - 1) diff --git "a/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244_\355\213\200\353\246\274.py" "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244_\355\213\200\353\246\274.py" new file mode 100644 index 0000000..818547c --- /dev/null +++ "b/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244_\355\213\200\353\246\274.py" @@ -0,0 +1,19 @@ +N = int(input()) +netNum = int(input()) + +netList = [[] for _ in range(N)] +virusList = [0 for _ in range(N)] + +virusList[0] = 1 + +for _ in range(netNum): + a, b = map(int, input().split()) + netList[a - 1].append(b) + netList[b - 1].append(a) + +for i in range(N): + if virusList[i]: + for j in netList[i]: + virusList[j - 1] = 1 + +print(sum(virusList) - 1) From d61109258747a7ab3c76713cce47183c1de6e5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 31 Jul 2022 18:43:58 +0900 Subject: [PATCH 063/822] =?UTF-8?q?Create=2011725=5F=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=9D=98=20=EB=B6=80=EB=AA=A8=EC=B0=BE=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" diff --git "a/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" "b/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" @@ -0,0 +1 @@ + From 81785a8c88aa44450bdff2058364a405d48488b6 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Sun, 31 Jul 2022 21:27:07 +0900 Subject: [PATCH 064/822] =?UTF-8?q?=EC=A0=90=ED=94=84=ED=82=B9=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\354\231\225\354\251\260\353\246\254.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_16173]\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" diff --git "a/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_16173]\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_16173]\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" new file mode 100644 index 0000000..3de4968 --- /dev/null +++ "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_16173]\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" @@ -0,0 +1,40 @@ +# 모든 경우를 다 탐색할 필요 있는가? X. +# 만약 목표 지점에 도달하지 못한다면 다 탐색해보긴 해야 하지만, 그냥 이미 목표 지점에 도달했다면 더 이상 돌 필요 X. +# 따라서 BFS + 재귀 구현시 , exit으로 해당 상황 가지치기 해주기. +# => 최대, 최소가 아닌 되냐 안되냐, 즉 Yes or No이므로 global 변수가 필요 없다. + +#------------------------------------------------------------------------------------------------ +dx = [1, 0] +dy = [0, 1] +direction = len(dx) +visited = [] +n_list = [] + +def dfs(_x, _y, _n) : + if _x < 0 or _x >= _n or _y < 0 or _y >= _n: return + if visited[_x][_y] == 1 : return + if n_list[_x][_y] == 0 : return + if n_list[_x][_y] == -1 : + print('HaruHaru') + exit() + visited[_x][_y] = 1 + value = n_list[_x][_y] + for i in range(direction): + nx = _x + dx[i]*value + ny = _y + dy[i]*value + dfs(nx, ny, _n) + return + + +def main(): + n = int(input()) + for i in range(n): + n_list.append(list(map(int, input().split()))) + visited.append([0]*n) + dfs(0, 0, n) + print('Hing') + + +# -- 실행 함수 ------------------------------------------------------------------------------------ +if __name__ == '__main__': + main() \ No newline at end of file From 854f2a230d52c97efbbe5c75e72583c9ba26acc4 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Sun, 31 Jul 2022 23:06:28 +0900 Subject: [PATCH 065/822] =?UTF-8?q?=EB=B0=94=EB=8B=A5=EC=9E=A5=EC=8B=9D=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\353\213\245\354\236\245\354\213\235.py" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_1388]\353\260\224\353\213\245\354\236\245\354\213\235.py" diff --git "a/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_1388]\353\260\224\353\213\245\354\236\245\354\213\235.py" "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_1388]\353\260\224\353\213\245\354\236\245\354\213\235.py" new file mode 100644 index 0000000..3955560 --- /dev/null +++ "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_1388]\353\260\224\353\213\245\354\236\245\354\213\235.py" @@ -0,0 +1,31 @@ +# 문제 풀이의 핵심 : 중복을 세지 않아야 한다는 것! 이걸 아래와 같이 구현이 가능하다. +# 구현 방법 1. 걍 단순 DFS 돌리고, visited 체크를 하여 중복을 예외 처리 하기 +# 구현 방법 2. [얘만 가능한 풀이] 최악의 경우가 되는 최대 수인 1짜리 나무판자로만 이루어진 경우에서 이어지는 경우를 뺴기 +# => 단, n개가 이어져 한 덩어리가 될 때, n이 아닌 n-1을 빼주어야 함을 유의할 것! +# => 또한, 전체 답이 행들의 답의 합과 같다는 특징을 이용할 수 있다는 것을 참고할 것. + +#------------------------------------------------------------------------------------------------ +namu = ['-', '|'] + +def count(_type, _iter, _arr) -> int: + _count = 0 + for i in range(_iter-1): + if _arr[i] == namu[_type] and _arr[i+1] == namu[_type]: _count += 1 + return _count + +def solution(_n,_m,_arr) -> int: + col_arr = list(map(list,zip(*_arr))) + count_arr = [0, 0] + for x in range(_n): count_arr[0] += count(0, _m, _arr[x]) + for x in range(_m): count_arr[1] += count(1, _n, col_arr[x]) + return _n*_m - sum(count_arr) + +def main(): + n, m = map(int, input().split()) + decoration = [list(input()) for _ in range(n)] + answer = solution(n, m, decoration) + print(answer) + +# -- 실행 함수 ------------------------------------------------------------------------------------ +if __name__ == '__main__': + main() \ No newline at end of file From 193828f0f609ba42b82cb934b1ee1bd7dbb21f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 1 Aug 2022 00:11:03 +0900 Subject: [PATCH 066/822] =?UTF-8?q?Create=2011725=5F=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=9D=98=EB=B6=80=EB=AA=A8=EC=B0=BE=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\252\250\354\260\276\352\270\260.java" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" "b/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" new file mode 100644 index 0000000..0ce27f5 --- /dev/null +++ "b/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" @@ -0,0 +1,45 @@ +import java.util.*; + +public class Main { + static ArrayList> pc = new ArrayList<>(); + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int n = sc.nextInt(); // 노드 개수 + + int result[] = new int[n + 1]; + boolean visited[][] = new boolean[n + 1][n + 1]; + + for(int i=0; i()); + } + + // 입력 + for (int i = 1; i < n; i++) { + int a = sc.nextInt(); + int b = sc.nextInt(); + + pc.get(a).add(b); + pc.get(b).add(a); + } + + Queue q = new LinkedList<>(); + + q.add(1); + + while(q.size() > 0) { + int parent = q.poll(); + + for(int num : pc.get(parent)) { + if(result[num] == 0) { + result[num] = parent; + q.offer(num); + } + } + } + for (int i = 2; i <= n; i++) { // 자식 + System.out.println(result[i]); + } + } +} From f3fc262ada46297b1a328fc5fe345604d6abd78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 1 Aug 2022 00:39:47 +0900 Subject: [PATCH 067/822] =?UTF-8?q?Create=202606=5F=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EB=9F=AC=EC=8A=A4.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\264\353\237\254\354\212\244.java" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" "b/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" new file mode 100644 index 0000000..944641a --- /dev/null +++ "b/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" @@ -0,0 +1,50 @@ +import java.util.*; + +public class Main { + static ArrayList> coms = new ArrayList<>(); + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + int n = sc.nextInt(); + int m = sc.nextInt(); + + int result[] = new int[n + 1]; + boolean visited[] = new boolean[n + 1]; + + for(int i=0; i()); + } + + // 입력 + for (int i = 0; i < m; i++) { + int a = sc.nextInt(); + int b = sc.nextInt(); + + coms.get(a).add(b); + coms.get(b).add(a); + } + + + Queue q = new LinkedList<>(); + + q.add(1); + visited[1] = true; + + int count = 0; + while(q.size() > 0) { + int parent = q.poll(); + + for(int num : coms.get(parent)) { + if(visited[num] == false) { + visited[num] = true; + q.add(num); + count++; + } + } + } + System.out.println(count); + + } +} From 0a18fb9ced46a2e7b1a4ec8a83ef54cf23c06a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 1 Aug 2022 13:32:14 +0900 Subject: [PATCH 068/822] =?UTF-8?q?Update=2011725=5F=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=9D=98=20=EB=B6=80=EB=AA=A8=EC=B0=BE=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\252\250\354\260\276\352\270\260.cpp" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git "a/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" "b/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" index 8b13789..45b6855 100644 --- "a/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" +++ "b/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" @@ -1 +1,31 @@ +#include +#include +#include +using namespace std; +int main() { + int N; cin >> N; + vector connect[100005]; + int answer[100005] = { 0 }; + for (int i = 0; i < N - 1; i++) { + int n1, n2; cin >> n1 >> n2; + connect[n1].push_back(n2); + connect[n2].push_back(n1); + } + queue q; + q.push(1); + answer[1] = 1; + while (!q.empty()) { + int before = q.front(); q.pop(); + for (int next : connect[before]) { + if (answer[next] == 0) { + answer[next] = before; + q.push(next); + } + } + } + for (int i = 2; i <= N; i++) { + cout << answer[i] << "\n"; + } + return 0; +} From 0c2b4f34a3d9c90d8ab6fffb4f1f5cc23d002f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:47:06 +0900 Subject: [PATCH 069/822] =?UTF-8?q?Create=2016173=5F=EC=A0=90=ED=94=84?= =?UTF-8?q?=EC=99=95=EC=A9=B0=EB=A6=AC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\231\225\354\251\260\353\246\254.java" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" "b/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" new file mode 100644 index 0000000..308a84a --- /dev/null +++ "b/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" @@ -0,0 +1,47 @@ +import java.util.*; + +public class Main { + static int zzeli[][]; + static boolean visited[][]; + static int count; + static int n; + static int dx[] = {0, 1}; + static int dy[] = {1, 0}; + + static void dfs(int i, int j) { + if(zzeli[i][j] == -1) { + System.out.println("HaruHaru"); + System.exit(0); + } + for(int k=0; k<2; k++) { + int nx = i + dx[k] * zzeli[i][j]; + int ny = j + dy[k] * zzeli[i][j]; + if(nx>=n || ny>=n || visited[nx][ny]) continue; + + visited[nx][ny] = true; + dfs(nx, ny); + + } + } + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + n = sc.nextInt(); + visited = new boolean[n][n]; + zzeli = new int[n][n]; + + // 입력 + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + int a = sc.nextInt(); + zzeli[i][j] = a; + } + } + + dfs(0, 0); + + System.out.println("Hing"); + } +} From b55d7ba525922677d6ef35202c28b2beead68aa3 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 1 Aug 2022 18:06:07 +0900 Subject: [PATCH 070/822] =?UTF-8?q?=ED=8A=B8=EB=A6=AC=EC=9D=98=20=EB=B6=80?= =?UTF-8?q?=EB=AA=A8=20=EC=B0=BE=EA=B8=B0=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 얼렁뚱땅이라 공부 다시 제대로 싹 정리할 것! --- ...\252\250\354\260\276\352\270\260_graph.py" | 36 +++++++++++++++ ...\250\354\260\276\352\270\260_graph_bad.py" | 41 +++++++++++++++++ ...54\260\276\352\270\260_graph_bad_logic.py" | 45 +++++++++++++++++++ ...54\260\276\352\270\260_graph_recursive.py" | 29 ++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph.py" create mode 100644 "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad.py" create mode 100644 "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad_logic.py" create mode 100644 "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_recursive.py" diff --git "a/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph.py" "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph.py" new file mode 100644 index 0000000..7dd80ca --- /dev/null +++ "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph.py" @@ -0,0 +1,36 @@ +# 모든 경우를 다 탐색할 필요 있는가? X. +# 만약 목표 지점에 도달하지 못한다면 다 탐색해보긴 해야 하지만, 그냥 이미 목표 지점에 도달했다면 더 이상 돌 필요 X. +# 따라서 BFS + 재귀 구현시 , exit으로 해당 상황 가지치기 해주기. +# => 최대, 최소가 아닌 '부모 노드'만 찾기이므로, global 변수가 필요 없다. + +# 위 과정의 여러 번일 뿐이다. +#------------------------------------------------------------------------------------------------ +import sys +sys.stdin = open("input.txt", "r") + +def dfs(_n, _graph) -> list: + parentNode = [0]*(_n+1) # 노드 번호 = 인덱스+1 + parentNode[1],stack = 1, [1] + while stack: + node = stack.pop() + for _v in _graph[node]: + if parentNode[_v] : continue + parentNode[_v] = node + stack.append(_v) + return parentNode + +def main(): + n = int(input()) + graph = [[] for _ in range(n+1)] + for _ in range(n - 1): + a, b = map(int, input().split()) + graph[a].append(b) + graph[b].append(a) + answer = dfs(n, graph) + print(*answer[2:], sep="\n") + + + +# -- 실행 함수 ------------------------------------------------------------------------------------ +if __name__ == '__main__': + main() \ No newline at end of file diff --git "a/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad.py" "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad.py" new file mode 100644 index 0000000..32340b7 --- /dev/null +++ "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad.py" @@ -0,0 +1,41 @@ +# 모든 경우를 다 탐색할 필요 있는가? X. +# 만약 목표 지점에 도달하지 못한다면 다 탐색해보긴 해야 하지만, 그냥 이미 목표 지점에 도달했다면 더 이상 돌 필요 X. +# 따라서 BFS + 재귀 구현시 , exit으로 해당 상황 가지치기 해주기. +# => 최대, 최소가 아닌 '부모 노드'만 찾기이므로, global 변수가 필요 없다. + +# 위 과정의 여러 번일 뿐이다. +#------------------------------------------------------------------------------------------------ +import sys +sys.stdin = open("input.txt", "r") + +def make_linked_list(_arr) -> dict: + tree = {} # or tree = {i: [] for i in range(1, n+1)} => 인접 딕셔너리 + for row in _arr: + m1, m2 = row[0], row[1] + tree[m1] = tree.get(m1, []) + [m2] + tree[m2] = tree.get(m2, []) + [m1] + return tree + +def dfs(_n, _graph) -> list: + parentNode = [0]*(_n+1) # 노드 번호 = 인덱스+1 + parentNode[1],stack = 1, [1] + while stack: + node = stack.pop() + for _v in _graph.get(node): + if parentNode[_v] : continue + parentNode[_v] = node + stack.append(_v) + return parentNode + +def main(): + n = int(input()) + n_list = [list(map(int, input().split())) for _ in range(n-1)] + graph = make_linked_list(n_list) + answer = dfs(n, graph) + print(*answer[2:], sep="\n") + + + +# -- 실행 함수 ------------------------------------------------------------------------------------ +if __name__ == '__main__': + main() \ No newline at end of file diff --git "a/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad_logic.py" "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad_logic.py" new file mode 100644 index 0000000..608cd49 --- /dev/null +++ "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad_logic.py" @@ -0,0 +1,45 @@ +# 모든 경우를 다 탐색할 필요 있는가? X. +# 만약 목표 지점에 도달하지 못한다면 다 탐색해보긴 해야 하지만, 그냥 이미 목표 지점에 도달했다면 더 이상 돌 필요 X. +# 따라서 BFS + 재귀 구현시 , exit으로 해당 상황 가지치기 해주기. +# => 최대, 최소가 아닌 '부모 노드'만 찾기이므로, global 변수가 필요 없다. + +# 위 과정의 여러 번일 뿐이다. +#------------------------------------------------------------------------------------------------ +import sys +sys.stdin = open("input.txt", "r") + +answer = [] + +def make_linked_list(_arr) -> dict: + tree = {} # or tree = {i: [] for i in range(1, n+1)} => 인접 딕셔너리 + for row in _arr: + m1, m2 = row[0], row[1] + tree[m1] = tree.get(m1, []) + [m2] + tree[m2] = tree.get(m2, []) + [m1] + return tree + +def dfs(_stack, _graph) : + if not _stack : return + node = _stack.pop() + for _v in _graph.get(node): + if _v : + print("dd" , _v , node) + answer.append(_v) + return + _stack.append(_v) + dfs(_stack, _graph) + +def main(): + n = int(input()) + n_list = [list(map(int, input().split())) for _ in range(n-1)] + graph = make_linked_list(n_list) + for i in range(2, n+1): + stack = [i] + dfs(stack, graph) + print(*answer, sep="\n") + + + +# -- 실행 함수 ------------------------------------------------------------------------------------ +if __name__ == '__main__': + main() \ No newline at end of file diff --git "a/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_recursive.py" "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_recursive.py" new file mode 100644 index 0000000..48f2e0e --- /dev/null +++ "b/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_recursive.py" @@ -0,0 +1,29 @@ +# DFS 풀이 + +import sys + +input = sys.stdin.readline +sys.setrecursionlimit(1000000) + +N = int(input()) +visited = [False] * (N + 1) +answer = [0] * (N + 1) +E = [[] for _ in range(N + 1)] +for i in range(N - 1): + S, D = map(int, input().split()) + E[S].append(D) + E[D].append(S) + + +def dfs(E, v, visited): + visited[v] = True + for i in E[v]: + if not visited[i]: + answer[i] = v + dfs(E, i, visited) + + +dfs(E, 1, visited) + +for i in range(2, N + 1): + print(answer[i]) \ No newline at end of file From d6e53b83a0f99d571261700455525b6e010adbe0 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:15:50 +0900 Subject: [PATCH 071/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=201388.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 1388.java" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1388.java" diff --git "a/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1388.java" "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1388.java" new file mode 100644 index 0000000..b89d2cb --- /dev/null +++ "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1388.java" @@ -0,0 +1,52 @@ +package etc; + +import java.util.Scanner; + +public class 백준1388 { + static int n,m,cnt; + + static char arr[][]; + static int visited[][]; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + + n=scan.nextInt(); + m=scan.nextInt(); + arr=new char[n][m]; + visited=new int[n][m]; + for(int i=0;i Date: Mon, 1 Aug 2022 18:16:09 +0900 Subject: [PATCH 072/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=2015173.jav?= =?UTF-8?q?a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 15173.java" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 15173.java" diff --git "a/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 15173.java" "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 15173.java" new file mode 100644 index 0000000..baf6419 --- /dev/null +++ "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 15173.java" @@ -0,0 +1,60 @@ +package etc; + +import java.util.Scanner; + +public class 백준16173 { + + static int arr[][]; + static boolean visited[][]; + static int dx[]= {1,0}; + static int dy[]= {0,1}; + static int n; + static int cnt=0; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + + n=scan.nextInt(); + arr=new int[n][n]; + visited=new boolean[n][n]; + for(int i=0;i0) { + System.out.println("HaruHaru"); + } + else System.out.println("Hing"); + + + } + public static void dfs(int i, int j) { + if(i==n-1&&j==n-1) { + cnt++; + return; + } + if (arr[i][j]==0) { + return; + } + int nx=i+arr[i][j]; + int ny=j; + if(nx>=0&&ny>=0&&nx=0&&ny>=0&&nx Date: Mon, 1 Aug 2022 18:17:03 +0900 Subject: [PATCH 073/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=202606.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 2606.java" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2606.java" diff --git "a/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2606.java" "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2606.java" new file mode 100644 index 0000000..99d68de --- /dev/null +++ "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2606.java" @@ -0,0 +1,41 @@ +import java.util.*; + +public class Main { + static Scanner scan=new Scanner(System.in); + static ArrayList> list =new ArrayList<>(); + static int[] visited; + static int cnt; + public static void main(String[] args) { + int n=scan.nextInt(); + int m=scan.nextInt(); + visited=new int[n+1]; + + for(int i=0;i()); + } + + for(int i=0;i Date: Mon, 1 Aug 2022 18:17:32 +0900 Subject: [PATCH 074/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=2011725.jav?= =?UTF-8?q?a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 11725.java" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 11725.java" diff --git "a/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 11725.java" "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 11725.java" new file mode 100644 index 0000000..726db79 --- /dev/null +++ "b/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 11725.java" @@ -0,0 +1,43 @@ +import java.util.*; + +public class Main { + static Scanner scan=new Scanner(System.in); + static ArrayList> list =new ArrayList<>(); + static int[] visited; + static int[] parent; + static int cnt; + public static void main(String[] args) { + int n=scan.nextInt(); + visited=new int[n+1]; + parent=new int[n+1]; + + for(int i=0;i()); + } + + for(int i=0;i Date: Mon, 1 Aug 2022 19:54:02 +0900 Subject: [PATCH 075/822] 0810 study --- ...\353\213\245\354\236\245\354\213\235.java" | 34 ++++++++++ ...\354\235\264\353\237\254\354\212\244.java" | 46 +++++++++++++ ...\354\231\225\354\240\244\353\246\254.java" | 65 +++++++++++++++++++ ...\353\252\250\354\260\276\352\270\260.java" | 56 ++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 "08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\353\213\245\354\236\245\354\213\235.java" create mode 100644 "08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\354\235\264\353\237\254\354\212\244.java" create mode 100644 "08.01/\354\240\225\355\230\270\354\241\260/\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.java" create mode 100644 "08.01/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\353\266\200\353\252\250\354\260\276\352\270\260.java" diff --git "a/08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\353\213\245\354\236\245\354\213\235.java" new file mode 100644 index 0000000..0f8aa98 --- /dev/null +++ "b/08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\353\213\245\354\236\245\354\213\235.java" @@ -0,0 +1,34 @@ +package problum1388; + +import java.util.Scanner; + +public class 바닥장식 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int n = sc.nextInt(); + int m = sc.nextInt(); + String[][] arr = new String[n][m]; + int cnt = 1; + + for(int i=0; i queue = new LinkedList<>(); + int index = 1; + vis[index] =1; + queue.offer(index); + int cnt = 0; + + while(!queue.isEmpty()) { + int x = queue.poll(); + for(int i=1;i que = new LinkedList<>(); + int q[] = {0,0}; + que.add(q); + + while (!que.isEmpty()) { + int[] temp = que.poll(); + int r = temp[0], c = temp[1]; + visited[r][c] = true; + + if(board[r][c] == -1){ + answer = true; + break; + } + + int bottom = r + board[r][c]; + int right = c + board[r][c]; + + + if (bottom < len && !visited[bottom][c]){ + int[] m = {r + board[r][c], c}; + que.add(m); + visited[bottom][c] = true; + } + if (right < len && !visited[r][right]){ + int[] m = {r + board[r][c], c}; + que.add(m); + visited[r][right] = true; + } + } + + if(answer){ + System.out.println("HaruHaru"); + }else{ + System.out.println("Hing"); + } + } +} \ No newline at end of file diff --git "a/08.01/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\353\266\200\353\252\250\354\260\276\352\270\260.java" "b/08.01/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\353\266\200\353\252\250\354\260\276\352\270\260.java" new file mode 100644 index 0000000..1446f69 --- /dev/null +++ "b/08.01/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\353\266\200\353\252\250\354\260\276\352\270\260.java" @@ -0,0 +1,56 @@ +package pro11725; +import java.util.*; + +public class 트리부모찾기 { + + static ArrayList[] list; + static int[] parents; + static boolean[] check; + + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + + list = new ArrayList[n+1]; + parents = new int[n+1]; + check = new boolean[n+1]; + + for (int i = 1; i <= n; i++) { + list[i] = new ArrayList(); + } + for (int j = 1; j Date: Tue, 2 Aug 2022 12:31:05 +0900 Subject: [PATCH 076/822] Create readme.md --- 0804/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 0804/readme.md diff --git a/0804/readme.md b/0804/readme.md new file mode 100644 index 0000000..1a86b4e --- /dev/null +++ b/0804/readme.md @@ -0,0 +1,7 @@ +# 08.04(목) 스터디 문제(BFS) + +1743) 음식물 피하기 +https://www.acmicpc.net/problem/1743 + +2583) 영역 구하기 +https://www.acmicpc.net/problem/2583 From dea38a3513fd144fd004eeaa5515459c467f80e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 2 Aug 2022 12:57:34 +0900 Subject: [PATCH 077/822] Rename 0804/readme.md to 08.04/readme.md --- {0804 => 08.04}/readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {0804 => 08.04}/readme.md (100%) diff --git a/0804/readme.md b/08.04/readme.md similarity index 100% rename from 0804/readme.md rename to 08.04/readme.md From 7b0c991c6624a2894e3b7fbf28eb8e747a39bac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:17:10 +0900 Subject: [PATCH 078/822] =?UTF-8?q?Create=201743=5F=EC=9D=8C=EC=8B=9D?= =?UTF-8?q?=EB=AC=BC=5F=ED=94=BC=ED=95=98=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\355\224\274\355\225\230\352\270\260.cpp" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" diff --git "a/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" "b/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..5d61163 --- /dev/null +++ "b/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" @@ -0,0 +1,48 @@ +#include +#include +#include +#include +using namespace std; +int main() { + int N, M, K; + cin >> N >> M >> K; + int board[200][200]; + vector> trash; + for (int i = 0; i < K; i++) { + int r, c; cin >> r >> c; + board[r][c] = 1; + trash.push_back({ r,c }); + } + int max_count = 0; + queue> q; + bool visit[200][200] = { false }; + int y[] = { 0,1,0,-1 }; + int x[] = { 1,0,-1,0 }; + for(pair t : trash){ + int nowX = t.first; int nowY = t.second; + if (!visit[nowX][nowY]) { + q.push({ nowX, nowY }); + visit[nowX][nowY] = true; + int count = 1; + while (!q.empty()) { + int nx = q.front().first; + int ny = q.front().second; + q.pop(); + for (int i = 0; i < 4; i++) { + int xx = nx + x[i]; + int yy = ny + y[i]; + if (0 < xx && xx <= N && 0 < yy && yy <= M) { + if (board[xx][yy] == 1 && !visit[xx][yy]) { + visit[xx][yy] = true; + count++; + q.push({ xx,yy }); + } + } + } + } + max_count = max(max_count, count); + } + } + cout << max_count << endl; + return 0; +} From a3a1e7c196fe62eb2013395028a042f32bb6419e Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Wed, 3 Aug 2022 01:11:26 +0900 Subject: [PATCH 079/822] complete --- ...\224\274\355\225\230\352\270\260_BFS.java" | 86 +++++++++++++++++++ ...\224\274\355\225\230\352\270\260_DFS.java" | 67 +++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" create mode 100644 "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" "b/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" new file mode 100644 index 0000000..de4689e --- /dev/null +++ "b/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" @@ -0,0 +1,86 @@ +import java.util.*; +import java.io.*; + +public class Main_1743_음식물피하기_BFS { + static boolean visit[][]; + static int map[][]; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + static Queue que = new LinkedList<>(); + + static int N, M; + static int nowX, nowY; + static int x, y; + static int count; + + static class Node { + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_1743.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()) + 1; + M = Integer.parseInt(st.nextToken()) + 1; + int K = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + visit = new boolean[N][M]; + for(int i=0; i 0) { + BFS(j, i); + max = Math.max(max, count); + } + + } + } + + System.out.println(max); + } // End of main + + static void BFS(int x, int y) { + que.offer(new Node(x, y)); + visit[y][x] = true; + // 자기 자신 포함 + count = 1; + + while( !que.isEmpty() ) { + Node node = que.poll(); + + for(int i=0; i<4; i++) { + nowY = node.y + dirY[i]; + nowX = node.x + dirX[i]; + + if(range_check() && visit[nowY][nowX] == false && map[nowY][nowX] == 1) { + que.offer(new Node(nowX, nowY)); + visit[nowY][nowX] = true; + count ++; + } + } + + } + } // End of BFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); + } // End of range_check +} // End of Main class \ No newline at end of file diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" "b/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" new file mode 100644 index 0000000..57a1d10 --- /dev/null +++ "b/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" @@ -0,0 +1,67 @@ +import java.util.*; +import java.io.*; + +public class Main_1743_음식물피하기_DFS { + static boolean visit[][]; + static int map[][]; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int x, y; + static int count = 1; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_1743.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()) + 1; + M = Integer.parseInt(st.nextToken()) + 1; + int K = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + visit = new boolean[N][M]; + for(int i=0; i 0) { + DFS(j, i); + max = Math.max(max, count); + } + } + } + + System.out.println(max); + } // End of main + + static void DFS(int x, int y) { + visit[y][x] = true; + count++; + + for(int i=0; i<4; i++) { + nowX = x + dirX[i]; + nowY = y + dirY[i]; + + if(range_check() && visit[nowY][nowX] == false && map[nowY][nowX] > 0) { + DFS(nowX, nowY); + } + } + } // End of DFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); + } // End of range_check +} // End of Main class \ No newline at end of file From 3de6fb313c6855019710efd970f3a454cb238d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 3 Aug 2022 07:18:44 +0900 Subject: [PATCH 080/822] =?UTF-8?q?Create=201743=5F=EC=9D=8C=EC=8B=9D?= =?UTF-8?q?=EB=AC=BC=ED=94=BC=ED=95=98=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\224\274\355\225\230\352\270\260.java" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" diff --git "a/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" "b/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" new file mode 100644 index 0000000..19e54c2 --- /dev/null +++ "b/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" @@ -0,0 +1,77 @@ +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; + +public class App { + + static int N, M, K, cnt, ans; + static int map[][]; + static boolean visited[][]; + static int dx[] = { -1, 1, 0, 0 }; + static int dy[] = { 0, 0, -1, 1 }; + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(System.in); + + N = sc.nextInt(); // 세로길이 + M = sc.nextInt(); // 가로길이 + K = sc.nextInt(); + + map = new int[N+1][M+1]; + visited = new boolean[N+1][M+1]; + + for (int i = 0; i < K; i++) { + int a = sc.nextInt(); // r 세로 + int b = sc.nextInt(); // c 가로 + + map[a][b] = 1; + } + + + for (int i = 1; i <= N; i++) { // 세로 + for (int j = 1; j <= M; j++) { // 가로 + if (!visited[i][j] && map[i][j] == 1) { + cnt = 0; + bfs(i, j); + ans = Math.max(cnt, ans); // 최대값 갱신 + } + } + } + + System.out.println(ans); + } + + static int max_check = 1; + static int max = 0; + + static void bfs(int x, int y) { + Queue q = new LinkedList<>(); + q.add(new point(x, y)); + visited[x][y] = true; + cnt++; + + while(!q.isEmpty()){ + point tmp = q.poll(); + for(int k=0; k<4; k++){ + int nx = tmp.x + dx[k]; + int ny = tmp.y + dy[k]; + if(1 <= nx && nx <= N && 1 <= ny && ny <= M){ + if(!visited[nx][ny] && map[nx][ny] == 1){ + q.add(new point(nx, ny)); + visited[nx][ny] = true; + cnt++; + } + } + } + } + } + static class point{ + int x; + int y; + public point(int x, int y){ + super(); + this.x = x; + this.y = y; + } + } +} From 3f565b7926fbfa5e9291837d287251656ddd3e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 3 Aug 2022 09:50:03 +0900 Subject: [PATCH 081/822] Update readme.md --- 08.04/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08.04/readme.md b/08.04/readme.md index 1a86b4e..03f7e67 100644 --- a/08.04/readme.md +++ b/08.04/readme.md @@ -1,7 +1,7 @@ # 08.04(목) 스터디 문제(BFS) -1743) 음식물 피하기 +## 1743 음식물 피하기 https://www.acmicpc.net/problem/1743 -2583) 영역 구하기 +## 2583 영역 구하기 https://www.acmicpc.net/problem/2583 From 5ffcceee92bbfbdb8ff8de3378803450ec636a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 3 Aug 2022 09:50:13 +0900 Subject: [PATCH 082/822] Update readme.md --- 08.04/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08.04/readme.md b/08.04/readme.md index 03f7e67..32e391c 100644 --- a/08.04/readme.md +++ b/08.04/readme.md @@ -1,7 +1,7 @@ # 08.04(목) 스터디 문제(BFS) -## 1743 음식물 피하기 +### 1743 음식물 피하기 https://www.acmicpc.net/problem/1743 -## 2583 영역 구하기 +### 2583 영역 구하기 https://www.acmicpc.net/problem/2583 From fab7d3edcac21a2f901af3190919b93bf76135dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 3 Aug 2022 10:16:02 +0900 Subject: [PATCH 083/822] =?UTF-8?q?Create=202583=5F=EC=98=81=EC=97=AD=5F?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\352\265\254\355\225\230\352\270\260.cpp" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" diff --git "a/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" "b/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..2f154c0 --- /dev/null +++ "b/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" @@ -0,0 +1,54 @@ +#include +#include +#include +#include +using namespace std; + +bool visit[101][101] = { false }; + +int main() { + int M, N, K; cin >> M >> N >> K; + for (int i = 0; i < K; i++) { + int x1, y1,x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + for (int k = x1; k < x2;k++) { + for (int t = y1; t < y2; t++) { + visit[k][t] = true; + } + } + } + int tox[] = {0,1,0,-1}; + int toy[] = { 1,0,-1,0 }; + queue> q; + vector answer; + for (int i = 0; i < N; i++) { + for (int k = 0; k < M; k++) { + if (!visit[i][k]) { + int count = 1; + q.push({ i,k }); + visit[i][k] = true; + while (!q.empty()) { + int x = q.front().first; + int y = q.front().second; + q.pop(); + for (int j = 0; j < 4; j++) { + int nx = x + tox[j]; + int ny = y + toy[j]; + if (0 <= nx && nx < N && 0 <= ny && ny < M && !visit[nx][ny]) { + count++; + q.push({ nx,ny }); + visit[nx][ny] = true; + } + } + } + answer.push_back(count); + } + } + } + sort(answer.begin(), answer.end()); + cout << answer.size() << endl; + for (int n : answer) { + cout << n << " "; + } + cout << endl; +} From 18ea4664815d548413ca0eb491cdfa54fe05796b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Wed, 3 Aug 2022 13:49:35 +0900 Subject: [PATCH 084/822] =?UTF-8?q?1743=5F=EC=9D=8C=EC=8B=9D=EB=AC=BC?= =?UTF-8?q?=ED=94=BC=ED=95=98=EA=B8=B0=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\224\274\355\225\230\352\270\260.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" diff --git "a/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" "b/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" new file mode 100644 index 0000000..3886675 --- /dev/null +++ "b/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" @@ -0,0 +1,70 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int M; + static int K; + static boolean[][] visited = new boolean[101][101]; + static boolean[][] passThrough = new boolean[101][101]; + static Queue trash = new LinkedList<>(); + static int[] dx = {-1,1,0,0}; + static int[] dy = {0,0,-1,1}; + static int count = 0; + static int max = 0; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer token = new StringTokenizer(br.readLine()); + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + K = Integer.parseInt(token.nextToken()); + + for (int i = 0; i < K; i++) { + token = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(token.nextToken()); + int y = Integer.parseInt(token.nextToken()); + passThrough[x][y] = true; + + } + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= M; j++) { + if (!visited[i][j] && passThrough[i][j] ) { + count = 0; + bfs(i,j); + max = Math.max(max, count); + } + } + } + + System.out.println(max); + + } + + static void bfs(int x, int y) { + Queue trash = new LinkedList<>(); + trash.add(new Point(x,y)); + visited[x][y] = true; + count++; + while(!trash.isEmpty()) { + Point point = trash.poll(); + for (int i = 0; i < 4; i++) { + int pointX = point.x + dx[i]; + int pointY = point.y + dy[i]; + + if (pointX >= 1 && pointX <= N && pointY >= 1 && pointY <= M ) { + if (!visited[pointX][pointY] && passThrough[pointX][pointY]) { + visited[pointX][pointY] = true; + trash.add(new Point(pointX,pointY)); + count++; + } + } + + } + + } + } +} From 08ea4467d3044772b04b404e71ee4156523da298 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 3 Aug 2022 22:55:36 +0900 Subject: [PATCH 085/822] kihun --- ...74\355\224\274\355\225\230\352\270\260.py" | 43 +++++++++++++++++++ ...55\352\265\254\355\225\230\352\270\260.py" | 40 +++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 "08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" create mode 100644 "08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" diff --git "a/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" "b/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" new file mode 100644 index 0000000..f9de610 --- /dev/null +++ "b/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" @@ -0,0 +1,43 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +N, M, K = map(int, input().split()) + +matrix = [[0] * M for _ in range(N)] + +dy = [0, 0, 1, -1] +dx = [1, -1, 0, 0] + +for _ in range(K): + y, x = map(int, input().split()) + matrix[y - 1][x - 1] = 1 + + +def bfs(y, x, matrix): + q = deque([[y, x]]) + matrix[y][x] = -1 + trashLength = 1 + + while q: + y, x = q.popleft() + + for i in range(4): + moveY = y + dy[i] + moveX = x + dx[i] + if 0 <= moveY < N and 0 <= moveX < M and matrix[moveY][moveX] == 1: + q.append([moveY, moveX]) + matrix[moveY][moveX] = -1 + trashLength += 1 + return trashLength + +maxTrash = 0 + +for i in range(N): + for j in range(M): + if matrix[i][j] == 1: + temp = bfs(i, j, matrix) + maxTrash = max(temp, maxTrash) + +print(maxTrash) diff --git "a/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" "b/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..74a1be4 --- /dev/null +++ "b/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" @@ -0,0 +1,40 @@ +import sys +sys.setrecursionlimit(10**9) +input = sys.stdin.readline + +M, N, K = map(int, input().split()) + +matrix = [[0] * N for _ in range(M)] + +dy = [0, 0, 1, -1] +dx = [1, -1, 0, 0] + +for _ in range(K): + x1, y1, x2, y2 = map(int, input().split()) + for i in range(y1, y2): + for j in range(x1, x2): + matrix[i][j] = 1 + + +def dfs(y, x, area): + matrix[y][x] = 1 + for i in range(4): + moveY = y + dy[i] + moveX = x + dx[i] + if 0 <= moveY < M and 0 <= moveX < N and matrix[moveY][moveX] == 0: + area = dfs(moveY, moveX, area + 1) + return area + + +areaList = [] + +for i in range(M): + for j in range(N): + if matrix[i][j] == 0: + temp = dfs(i, j, 1) + areaList.append(temp) + +areaList.sort() +print(len(areaList)) +for i in areaList: + print(i, end=" ") From 03a8b7c1ef8d6b8fcb0179b466035d1791651ce1 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Thu, 4 Aug 2022 00:57:36 +0900 Subject: [PATCH 086/822] complete --- ...\352\265\254\355\225\230\352\270\260.java" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" "b/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" new file mode 100644 index 0000000..45d3877 --- /dev/null +++ "b/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" @@ -0,0 +1,79 @@ +import java.util.*; +import java.io.*; + +public class Main_2583_영역구하기 { + static int arr[][]; + static boolean visit[][]; + static List resultList = new ArrayList<>(); + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {1, -1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int areaCount = 0; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2583.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + arr = new int[N][M]; + visit = new boolean[N][M]; + + while(K-->0) { + st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for(int i=x1; i= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check +} // End of Main class \ No newline at end of file From 525273303987fc68272375d9546ab5d93c947fb1 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Thu, 4 Aug 2022 01:57:27 +0900 Subject: [PATCH 087/822] complete --- ...\265\254\355\225\230\352\270\260_BFS.java" | 96 +++++++++++++++++++ ...\265\254\355\225\230\352\270\260_DFS.java" | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" rename "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" => "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" (94%) diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" "b/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" new file mode 100644 index 0000000..14f8e6f --- /dev/null +++ "b/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" @@ -0,0 +1,96 @@ +import java.util.*; +import java.io.*; + +public class Main_2583_영역_구하기_BFS { + static int arr[][]; + static boolean visit[][]; + static List resultList = new ArrayList<>(); + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {1, -1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int areaCount = 0; + + static class Node{ + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2583.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + arr = new int[N][M]; + visit = new boolean[N][M]; + + while(K-->0) { + st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for(int i=x1; i que = new LinkedList<>(); + visit[x][y] = true; + que.offer(new Node(x,y)); + + while(!que.isEmpty()) { + Node node = que.poll(); + + for(int i=0; i<4; i++) { + nowX = dirX[i] + node.x; + nowY = dirY[i] + node.y; + + if(range_check() && !visit[nowX][nowY] && arr[nowX][nowY] == 0) { + que.offer(new Node(nowX, nowY)); + visit[nowX][nowY] = true; + areaCount++; + } + } + } + } // End of BFS + + private static boolean range_check() { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check +} // End of Main class \ No newline at end of file diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" "b/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" similarity index 94% rename from "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" rename to "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" index 45d3877..5fce386 100644 --- "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" +++ "b/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" @@ -1,7 +1,7 @@ import java.util.*; import java.io.*; -public class Main_2583_영역구하기 { +public class Main_2583_영역_구하기_DFS { static int arr[][]; static boolean visit[][]; static List resultList = new ArrayList<>(); From c3bb8bd3b3a8c59ec16c993ad6847a221dd85d0c Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 4 Aug 2022 09:58:10 +0900 Subject: [PATCH 088/822] solve --- ...\352\265\254\355\225\230\352\270\260.java" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" diff --git "a/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" "b/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" new file mode 100644 index 0000000..2e81c4d --- /dev/null +++ "b/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" @@ -0,0 +1,90 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Main { + + static int M; + static int N; + static int K; + static int[] dx = { -1, 1, 0, 0 }; + static int[] dy = { 0, 0, -1, 1 }; + static boolean[][] visitied = new boolean[101][101]; + static boolean[][] area = new boolean[101][101]; + static int count = 0; + static List list = new ArrayList(); + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(token.nextToken()); + N = Integer.parseInt(token.nextToken()); + K = Integer.parseInt(token.nextToken()); + + for (int i = 0; i < K; i++) { + token = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(token.nextToken()); + int y1 = Integer.parseInt(token.nextToken()); + int x2 = Integer.parseInt(token.nextToken()); + int y2 = Integer.parseInt(token.nextToken()); + + for (int y = M - y2 +1; y<= M - y1 ; y++) { //영역채우기 + for (int x = x1+1; x <= x2; x++) { + area[y][x] = true; + } + } + } + + for (int i = 1; i <= M ; i++) { //방문하지 않고 영역이 색칠되지 않았을때 시작 + for (int j = 1; j <= N; j++) { + if (!visitied[i][j] && !area[i][j]) { + count = 0; + bfs(i,j); + list.add(count); + } + } + } + + Collections.sort(list); //정렬 + + bw.write(list.size()+"\n"); + + for (int i = 0; i < list.size(); i++) { + bw.write(list.get(i)+" "); + } + + bw.flush(); + bw.close(); + + } + + static void bfs(int x, int y) { + Queue squarePoint = new LinkedList<>(); + squarePoint.add(new Point(x,y)); + visitied[x][y] = true; + count++; + + while(!squarePoint.isEmpty()) { + + Point point = squarePoint.poll(); + + for (int i = 0; i < 4; i++) { + + int pointX = point.x + dx[i]; + int pointY = point.y + dy[i]; + + if (pointX >= 1 && pointX <= M && pointY >= 1 && pointY <= N) { + + if (!visitied[pointX][pointY] && !area[pointX][pointY]) { + visitied[pointX][pointY] = true; + squarePoint.add(new Point(pointX,pointY)); + count++; + } + } + } + } + } +} From 5670a0cc9da14f950f483edb457496b76e53797a Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 4 Aug 2022 14:05:09 +0900 Subject: [PATCH 089/822] =?UTF-8?q?1743=5F=EC=9D=8C=EC=8B=9D=EB=AC=BC=20?= =?UTF-8?q?=ED=94=BC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\355\224\274\355\225\230\352\270\260.py" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" diff --git "a/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" "b/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" new file mode 100644 index 0000000..e93a03d --- /dev/null +++ "b/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" @@ -0,0 +1,45 @@ +# 인덱스 범위가 1부터 시작이므로, 귀찮으니까 배열+1해주어 한칸 씩 밀것. +# 배열 내 데이터가 0또는 1이므로, visited 표시를 2로 가능하다. 따라서 굳이 visited 배열 만들 필요 X. +# ------------------------------------------------------------------------------------ +# from collections import deque +# trash = deque() +import sys +sys.setrecursionlimit(10**7) +sys.stdin = open("input.txt", "r") + + +move = [(0, -1), (1, 0), (0, 1), (-1, 0)] # 방향(4) : 위, 오, 아, 왼0 + +n, m, k = map(int, input().split()) +road = [[0]*(m+1) for _ in range(n+1)] + +def dfs(_x, _y) : + global count + print( _x, _y) + if _x<=0 or m<_x or _y<=0 or n<_y: return False + if road[_y][_x]: + count += 1 + road[_y][_x] = -1 + for dx, dy in move: + dfs(_x+dx, _y+dy) + return True + return False + + +def init() : + for _ in range(k): + y, x = map(int, input().split()) + road[y][x] = 1 + # trash.append([x,y]) + + +init() +answer, count = 0, 0 +for row in range(1, n+1): + for col in range(1, m+1): + if dfs(row, col): + answer = max(answer, count) + count = 0 +print(answer) + + From f3929bb57f809a1b4f5580eeb9100255401fe890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Thu, 4 Aug 2022 14:11:10 +0900 Subject: [PATCH 090/822] =?UTF-8?q?Create=202583=5F=EC=98=81=EC=97=AD?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\265\254\355\225\230\352\270\260.java" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" diff --git "a/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" "b/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" new file mode 100644 index 0000000..91a1c66 --- /dev/null +++ "b/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" @@ -0,0 +1,79 @@ +import java.util.*; + +public class Main { + static int N, M, K, cnt = 1; + static boolean visited[][]; + static int dx[] = { 0, 0, -1, 1 }; + static int dy[] = { -1, 1, 0, 0 }; + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + N = sc.nextInt(); + M = sc.nextInt(); + K = sc.nextInt(); + sc.nextLine(); + visited = new boolean[N][M]; + + // 입력 + for (int k = 0; k < K; k++) { + String s[] = sc.nextLine().split(" "); // 0 2 4 4 + for (int i = Integer.parseInt(s[0]); i < Integer.parseInt(s[2]); i++) { + for (int j = Integer.parseInt(s[1]); j < Integer.parseInt(s[3]); j++) { + visited[j][i] = true; + } + } + } + LinkedList area = new LinkedList<>(); + + for (int i = N - 1; i >= 0; i--) { + for (int j = 0; j < M; j++) { + if (!visited[i][j]) { + cnt = 0; + area.add(bfs(i, j)); + } + } + } + System.out.println(area.size()); + Collections.sort(area); + for (int a : area) { + System.out.print(a + " "); + } + + } + + static int bfs(int i, int j) { + Queue q = new LinkedList<>(); + visited[i][j] = true; + q.add(new Pair(i, j)); + + while (!q.isEmpty()) { // 목표는 영역 구해주기 + Pair p = q.poll(); + cnt++; + for (int a = 0; a < 4; a++) { + int nx = dx[a] + p.x; + int ny = dy[a] + p.y; + if (0 <= nx && nx < N && 0 <= ny && ny < M) { + if (!visited[nx][ny]) { + q.add(new Pair(nx, ny)); + visited[nx][ny] = true; + } + } + } + } + return cnt; + } + + static class Pair { + int x; + int y; + + Pair(int x, int y) { + super(); + this.x = x; + this.y = y; + } + + } +} From a8bd64863b5f5540bcb7cb3be383ca5aba00087c Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 4 Aug 2022 18:28:40 +0900 Subject: [PATCH 091/822] =?UTF-8?q?2583=5F=EC=98=81=EC=97=AD=EA=B5=AC?= =?UTF-8?q?=ED=95=98=EA=B8=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5 \352\265\254\355\225\230\352\270\260.py" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" diff --git "a/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" "b/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..1123efd --- /dev/null +++ "b/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" @@ -0,0 +1,43 @@ +from collections import deque + +m,n,k = map(int,input().split()) + +graph = [[0]*n for i in range(m)] + +for _ in range(k): + x1,y1,x2,y2= map(int,input().split()) + for i in range(y1,y2): + for j in range(x1,x2): + graph[i][j] = 1 + +move = [(-1, 0), (1,0), (0,1), (0,-1)] # 좌 우 상 하 + + +def bfs(_y,_x): + queue = deque() + queue.append((_y,_x)) + graph[_y][_x]=1 # 다시 방문하지 않기 위해 1로 변경 + cnt=1 + while queue : + current = queue.popleft() + cx,cy = current[0],current[1] + for dx, dy in move: + nx = cx+dx + ny = cy+dy + if (0 <= nx < m) and (0 <= ny < n): + if graph[nx][ny] == 0: + graph[nx][ny] = 1 + queue.append((nx, ny)) + cnt += 1 + return cnt + +area = 0 # 영역의 개수 +cnts = [] # 영역의 넓이 +for y in range(m): + for x in range(n): + if graph[y][x]==0: + cnts.append(bfs(y,x)) + area+=1 +print(area) +cnts.sort() +print(*cnts) \ No newline at end of file From 260c982b493eb85f2acb9f5ef3b4b4525e67f8dd Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Thu, 4 Aug 2022 19:23:36 +0900 Subject: [PATCH 092/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=202583.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 2583.java" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" diff --git "a/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" "b/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" new file mode 100644 index 0000000..9970982 --- /dev/null +++ "b/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" @@ -0,0 +1,67 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class Main { + static int[] dx= {1,-1,0,0}; + static int[] dy= {0,0,-1,1}; + static int m,n,k,cnt=0,idx=0; + static int[][] arr; + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + m=scan.nextInt(); + n=scan.nextInt(); + k=scan.nextInt(); + arr=new int[m][n]; + ArrayList list=new ArrayList<>(); + for(int i=0;i=0&&ny>=0&&nx Date: Thu, 4 Aug 2022 19:24:06 +0900 Subject: [PATCH 093/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=201743.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 1743.java" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" diff --git "a/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" "b/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" new file mode 100644 index 0000000..dbd2eaf --- /dev/null +++ "b/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" @@ -0,0 +1,54 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class Main { + static int n,m,k,cnt,ans=0; + static int[] dx= {1,-1,0,0}; + static int[] dy= {0,0,-1,1}; + static boolean[][] visited; + static int[][] list; + static int max=Integer.MIN_VALUE; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + n=scan.nextInt(); + m=scan.nextInt(); + k=scan.nextInt(); + + list=new int[n+1][m+1]; + visited=new boolean[n+1][m+1]; + for(int i=0;imax) { + max=cnt; + } + } + } + } + System.out.println(max); + } + public static void dfs(int i,int j) { + cnt++; + visited[i][j]=true; + for(int a=0;a<4;a++) { + int nx=i+dx[a]; + int ny=j+dy[a]; + + if(nx>0&&ny>0&&nx<=n&&ny<=m&&visited[nx][ny]==false) { + if(list[nx][ny]==1) { + dfs(nx,ny); + } + } + else continue; + } + } +} From 60dfb8d8ac3401db28b5f1f432a16bc85195570a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 4 Aug 2022 20:55:45 +0900 Subject: [PATCH 094/822] Create readme.md --- 08.08/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 08.08/readme.md diff --git a/08.08/readme.md b/08.08/readme.md new file mode 100644 index 0000000..034e5fd --- /dev/null +++ b/08.08/readme.md @@ -0,0 +1,6 @@ +# 08.08(월) +1. 1697) 숨바꼭질 +https://www.acmicpc.net/problem/1697 + +2. 2644) 촌수계산 +https://www.acmicpc.net/problem/2644 From e92b3cf42a0e77be1faba3915c550d13593df92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 4 Aug 2022 20:55:57 +0900 Subject: [PATCH 095/822] Update readme.md --- 08.08/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08.08/readme.md b/08.08/readme.md index 034e5fd..7d77a6e 100644 --- a/08.08/readme.md +++ b/08.08/readme.md @@ -1,6 +1,6 @@ # 08.08(월) -1. 1697) 숨바꼭질 +1697) 숨바꼭질 https://www.acmicpc.net/problem/1697 -2. 2644) 촌수계산 +2644) 촌수계산 https://www.acmicpc.net/problem/2644 From 800e6b75d3a77d218d1fe3f40db8667b54a767be Mon Sep 17 00:00:00 2001 From: ChangYoung Choi <74912130+chang0-0@users.noreply.github.com> Date: Fri, 5 Aug 2022 10:03:23 +0900 Subject: [PATCH 096/822] complete --- "08.04/\354\265\234\354\260\275\354\230\201/readme" | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 "08.04/\354\265\234\354\260\275\354\230\201/readme" diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/readme" "b/08.04/\354\265\234\354\260\275\354\230\201/readme" new file mode 100644 index 0000000..05e5d48 --- /dev/null +++ "b/08.04/\354\265\234\354\260\275\354\230\201/readme" @@ -0,0 +1,2 @@ +0으로 이루어진 2차원배열에서 1의 영역을 탐색한다고 했을 때, 전체 배열을 탐색하는 것이 아닌, +1의 좌표값을 리스트나 배열로 만들어서 배열에 있는 값만 탐색을 하면 효율적인 탐색이 될 수 있다. From 9b15622a446e5280de2ab1a10e4327d7c1716025 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Fri, 5 Aug 2022 12:14:49 +0900 Subject: [PATCH 097/822] complete --- ...\354\210\230\354\240\225\353\263\270.java" | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" "b/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" new file mode 100644 index 0000000..9886138 --- /dev/null +++ "b/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" @@ -0,0 +1,78 @@ +import java.util.*; +import java.io.*; + +public class Main_1743_음식물피하기_부분탐색_수정본 { + static boolean visit[][]; + static int map[][]; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int x, y; + static int count = 1; + + static class Node{ + int x; + int y; + + public Node(int x, int y){ + this.x = x; + this.y = y; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1743.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()) + 1; + M = Integer.parseInt(st.nextToken()) + 1; + int K = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + visit = new boolean[N][M]; + List trapList = new ArrayList<>(); + + for(int i=0; i 0) { + DFS(nowX, nowY); + } + } + } // End of DFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); + } // End of range_check +} // End of Main class \ No newline at end of file From e140d462523b1667843d1814f020e099bbff92a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Fri, 5 Aug 2022 12:19:09 +0900 Subject: [PATCH 098/822] Create readme.md --- "08.08/\355\231\251\354\247\200\354\233\220/readme.md" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "08.08/\355\231\251\354\247\200\354\233\220/readme.md" diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" new file mode 100644 index 0000000..94f2361 --- /dev/null +++ "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" @@ -0,0 +1,3 @@ +### 1697 숨바꼭질 + +![image](https://user-images.githubusercontent.com/41350477/182994323-9e826d2a-6409-4117-ad9f-5359b6cd3f78.png) From c09c3fc694df64b21d3941ab6eec1fe462309610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Fri, 5 Aug 2022 12:19:37 +0900 Subject: [PATCH 099/822] Update readme.md --- "08.08/\355\231\251\354\247\200\354\233\220/readme.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" index 94f2361..1e32c56 100644 --- "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" @@ -1,3 +1,3 @@ ### 1697 숨바꼭질 -![image](https://user-images.githubusercontent.com/41350477/182994323-9e826d2a-6409-4117-ad9f-5359b6cd3f78.png) +![image](https://user-images.githubusercontent.com/41350477/182994405-860cdac7-76d5-488a-848b-712c18339945.png) From 1507a6dba1e5161a6e6eedfbe68584633bcc17aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Fri, 5 Aug 2022 13:38:47 +0900 Subject: [PATCH 100/822] Update readme.md --- "08.08/\355\231\251\354\247\200\354\233\220/readme.md" | 3 +++ 1 file changed, 3 insertions(+) diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" index 1e32c56..fb78ba7 100644 --- "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" @@ -1,3 +1,6 @@ ### 1697 숨바꼭질 ![image](https://user-images.githubusercontent.com/41350477/182994405-860cdac7-76d5-488a-848b-712c18339945.png) + +#### 반례모음 +https://www.acmicpc.net/board/view/88502 From 4a5b425fd6e6470119aa9fe5c352bcfbbc9156c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Fri, 5 Aug 2022 13:39:06 +0900 Subject: [PATCH 101/822] Update readme.md --- "08.08/\355\231\251\354\247\200\354\233\220/readme.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" index fb78ba7..7bcdeb0 100644 --- "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" @@ -1,6 +1,6 @@ ### 1697 숨바꼭질 - -![image](https://user-images.githubusercontent.com/41350477/182994405-860cdac7-76d5-488a-848b-712c18339945.png) - #### 반례모음 https://www.acmicpc.net/board/view/88502 +![image](https://user-images.githubusercontent.com/41350477/182994405-860cdac7-76d5-488a-848b-712c18339945.png) + + From 3981b4f9a838342075ac1024ad88785fd7747f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Fri, 5 Aug 2022 13:39:22 +0900 Subject: [PATCH 102/822] Update readme.md --- "08.08/\355\231\251\354\247\200\354\233\220/readme.md" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" index 7bcdeb0..6841ef4 100644 --- "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.08/\355\231\251\354\247\200\354\233\220/readme.md" @@ -1,6 +1,5 @@ ### 1697 숨바꼭질 -#### 반례모음 -https://www.acmicpc.net/board/view/88502 +#### 반례모음 https://www.acmicpc.net/board/view/88502 ![image](https://user-images.githubusercontent.com/41350477/182994405-860cdac7-76d5-488a-848b-712c18339945.png) From 1c9c85b5836002712ebbfb0f55eef2b6271c27d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 5 Aug 2022 21:12:08 +0900 Subject: [PATCH 103/822] =?UTF-8?q?Create=201697=5F=EC=88=A8=EB=B0=94?= =?UTF-8?q?=EA=BC=AD=EC=A7=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\260\224\352\274\255\354\247\210.cpp" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" diff --git "a/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" "b/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" new file mode 100644 index 0000000..f95ecef --- /dev/null +++ "b/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" @@ -0,0 +1,50 @@ +#include +#include +using namespace std; + +int N, K; +int board[500000]; +queue q; +bool check(int now, int next) {// next < K*3 && + if (0 <= next && next < K * 2 && board[next] == 0) { + return true; + } + return false; +} + +void qInput(int now, int next) { + board[next] = board[now] + 1; + q.push(next); +} + +int main() { + cin >> N >> K; + if (K <= N) { + cout << N - K << endl; + return 0; + } + q.push(N); + while (!q.empty()) { //순서바꾸니 맞음 왜? + int now = q.front(); + q.pop(); + if (now == K) { + break; + } + int next; + next = now + 1; + if (check(now, next)) { + qInput(now, next); + } + next = now - 1; + if (check(now, next)) { + qInput(now, next); + } + next = now * 2; + if (check(now, next)) { + qInput(now, next); + } + } + board[N] = 0; + cout << board[K] << endl; + return 0; +} From e587ef8c268299ca138074402638a0ee58da6fc2 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 6 Aug 2022 11:26:30 +0900 Subject: [PATCH 104/822] complete --- ...\353\260\224\352\274\255\354\247\210.java" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" "b/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" new file mode 100644 index 0000000..441a2f6 --- /dev/null +++ "b/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" @@ -0,0 +1,85 @@ +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/1697 +// 목표 : 수빈이가 동생을 찾는 가장 빠른 시간을 출력한다. + +public class Main_1697_숨바꼭질 { + static Queue que = new LinkedList<>(); + static int arr[] = new int[100001]; + + static int N, K; + static int min_time; + static int next_time; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_1697.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + // 순간이동은 *2 로 증가만 가능하므로, 뒤로가는 방법은 - 1밖에 없다. + // 뒤로가는 것은 N - K로 계산하면됨. 방법의 수는 1가지 + if(N >= K) { + System.out.println(N-K); + return; + } + + BFS(); + + System.out.println(min_time); + + } // End of main + + private static void BFS() { + min_time = Integer.MAX_VALUE/16; // 최단 시간 + que.offer(N); + arr[N] = 1; + + while( !que.isEmpty() ) { + int time = que.poll(); + + if(min_time < arr[time]) { + return; + } + + for(int i=0; i<3; i++) { + + switch(i) { + case 0: next_time = time + 1; + break; + case 1: next_time = time - 1; + break; + default: next_time = time * 2; + } + + + if(next_time == K) { + min_time = arr[time]; + } + + + if( Range_check() && (arr[next_time] == 0 || arr[next_time] == arr[time] + 1) ) { + que.offer(next_time); + arr[next_time] = arr[time] + 1; + } + + } + } + }// End of BFS + + + // 범위 체크 + static boolean Range_check() { + return (next_time >= 0 && next_time <= 100000); + } + + // 숨바꼭질2랑 범위가 달라서 체크해야됨 + // 숨바꼭질2은 테스트케이스 중에 10만이 없는데 + + // 숨바꼭질1에서는 테스트 케이스 중에 next_time 범위가 10만 인 경우가 있기 때문에 + // 신경써야됨. + +} // End of class From 7bd72dedee829486f700b8ad0a1112ba4f2bdb1e Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 6 Aug 2022 13:09:06 +0900 Subject: [PATCH 105/822] complete --- ...\353\260\224\352\274\255\354\247\210.java" | 85 ------------------- ...3\260\224\352\274\255\354\247\210_DP.java" | 52 ++++++++++++ 2 files changed, 52 insertions(+), 85 deletions(-) delete mode 100644 "08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" create mode 100644 "08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" "b/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" deleted file mode 100644 index 441a2f6..0000000 --- "a/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" +++ /dev/null @@ -1,85 +0,0 @@ -import java.io.*; -import java.util.*; - -// https://www.acmicpc.net/problem/1697 -// 목표 : 수빈이가 동생을 찾는 가장 빠른 시간을 출력한다. - -public class Main_1697_숨바꼭질 { - static Queue que = new LinkedList<>(); - static int arr[] = new int[100001]; - - static int N, K; - static int min_time; - static int next_time; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_1697.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - N = Integer.parseInt(st.nextToken()); - K = Integer.parseInt(st.nextToken()); - - // 순간이동은 *2 로 증가만 가능하므로, 뒤로가는 방법은 - 1밖에 없다. - // 뒤로가는 것은 N - K로 계산하면됨. 방법의 수는 1가지 - if(N >= K) { - System.out.println(N-K); - return; - } - - BFS(); - - System.out.println(min_time); - - } // End of main - - private static void BFS() { - min_time = Integer.MAX_VALUE/16; // 최단 시간 - que.offer(N); - arr[N] = 1; - - while( !que.isEmpty() ) { - int time = que.poll(); - - if(min_time < arr[time]) { - return; - } - - for(int i=0; i<3; i++) { - - switch(i) { - case 0: next_time = time + 1; - break; - case 1: next_time = time - 1; - break; - default: next_time = time * 2; - } - - - if(next_time == K) { - min_time = arr[time]; - } - - - if( Range_check() && (arr[next_time] == 0 || arr[next_time] == arr[time] + 1) ) { - que.offer(next_time); - arr[next_time] = arr[time] + 1; - } - - } - } - }// End of BFS - - - // 범위 체크 - static boolean Range_check() { - return (next_time >= 0 && next_time <= 100000); - } - - // 숨바꼭질2랑 범위가 달라서 체크해야됨 - // 숨바꼭질2은 테스트케이스 중에 10만이 없는데 - - // 숨바꼭질1에서는 테스트 케이스 중에 next_time 범위가 10만 인 경우가 있기 때문에 - // 신경써야됨. - -} // End of class diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" "b/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" new file mode 100644 index 0000000..33e42d5 --- /dev/null +++ "b/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" @@ -0,0 +1,52 @@ +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/1697 +// 목표 : 수빈이가 동생을 찾는 가장 빠른 시간을 출력한다. + +// 숨바꼭질2랑 범위가 달라서 체크해야됨 +// 숨바꼭질2은 테스트케이스 중에 10만이 없는데 + +// 숨바꼭질1에서는 테스트 케이스 중에 next_location 범위가 10만 인 경우가 있기 때문에 +// 신경써야됨. + +public class Main_1697_숨바꼭질_DP { + static int distance[] = new int[100001]; // 전체 거리 + static int N, K; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_1697.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 수빈이 위치 + K = Integer.parseInt(st.nextToken()); // 동생 위치 + + if(N >= K) { + System.out.println(N-K); + return; + } + + for(int i=0; i Date: Sat, 6 Aug 2022 13:36:01 +0900 Subject: [PATCH 106/822] solve --- ...\354\210\230\352\263\204\354\202\260.java" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" diff --git "a/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" "b/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" new file mode 100644 index 0000000..56a5cba --- /dev/null +++ "b/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" @@ -0,0 +1,64 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int n; + static int p1; + static int p2; + static int m; + static boolean[] visited = new boolean[101]; + static List[] relation; + static int distance = -1; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + n = Integer.parseInt(br.readLine()); + + relation = new ArrayList[n+1]; + + for (int i = 1; i <= n; i++) { + relation[i] = new ArrayList(); + } + + StringTokenizer token = new StringTokenizer(br.readLine()); + + p1 = Integer.parseInt(token.nextToken()); + p2 = Integer.parseInt(token.nextToken()); + + m = Integer.parseInt(br.readLine()); + + + for (int i = 0; i < m; i++) { + + token = new StringTokenizer(br.readLine()); + + int x = Integer.parseInt(token.nextToken()); + int y = Integer.parseInt(token.nextToken()); + + relation[x].add(y); + relation[y].add(x); + } + + dfs(p1,p2,0); + + System.out.println(distance); + + } + + static void dfs(int start, int target, int count) { + if (start == target) { + distance = count; + return; + } + visited[start] = true; + + for (int i = 0; i < relation[start].size(); i++) { + int next = relation[start].get(i); + if (!visited[next]) { + dfs(next,target,count+1); + } + } + } +} From 5f5cd21cd4896a6d1d6667a47313de2c02f9d55f Mon Sep 17 00:00:00 2001 From: ChangYoung Choi <74912130+chang0-0@users.noreply.github.com> Date: Sat, 6 Aug 2022 14:19:07 +0900 Subject: [PATCH 107/822] complete --- "08.08/\354\265\234\354\260\275\354\230\201/README.md" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "08.08/\354\265\234\354\260\275\354\230\201/README.md" diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/README.md" "b/08.08/\354\265\234\354\260\275\354\230\201/README.md" new file mode 100644 index 0000000..913d376 --- /dev/null +++ "b/08.08/\354\265\234\354\260\275\354\230\201/README.md" @@ -0,0 +1,9 @@ +- BFS를 통해서 푸는 문제이지만, 정해진 규칙이 있기 때문에 DP로도 풀 수 있는 문제였다. + +**생각해보면 어떤 위치에서 출발하건 해당하는 위치에서의 최솟값은 변하지 않음을 생각해야 한다. 짝수위치 에서는 당연히 순간이동해서 온 시간이 최단시간이 될 것이고, 홀수 위치에서는 한칸 앞의 위치에서 이전에 순간이동을 해온 시간, 또는 한칸 뒤의 위치에서 순간이동을 해온 시간 중 2개중에 하나가 최단시간이 된다.** + +
+ +**가령, 각각 다른 10개의 테스트 케이스를 돌려서 `distance[10]`의 위치를 계속 파악한다고 했을 때, `distance[10]`의 최솟값은 항상 똑같다** + +
From cfc4ac2f54c007075c8eb8f966d9c18bc5697626 Mon Sep 17 00:00:00 2001 From: ChangYoung Choi <74912130+chang0-0@users.noreply.github.com> Date: Sat, 6 Aug 2022 14:19:31 +0900 Subject: [PATCH 108/822] complete --- "08.08/\354\265\234\354\260\275\354\230\201/README.md" | 3 +++ 1 file changed, 3 insertions(+) diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/README.md" "b/08.08/\354\265\234\354\260\275\354\230\201/README.md" index 913d376..7fd4de6 100644 --- "a/08.08/\354\265\234\354\260\275\354\230\201/README.md" +++ "b/08.08/\354\265\234\354\260\275\354\230\201/README.md" @@ -1,3 +1,6 @@ + + +# 숨바꼭질 - BFS를 통해서 푸는 문제이지만, 정해진 규칙이 있기 때문에 DP로도 풀 수 있는 문제였다. **생각해보면 어떤 위치에서 출발하건 해당하는 위치에서의 최솟값은 변하지 않음을 생각해야 한다. 짝수위치 에서는 당연히 순간이동해서 온 시간이 최단시간이 될 것이고, 홀수 위치에서는 한칸 앞의 위치에서 이전에 순간이동을 해온 시간, 또는 한칸 뒤의 위치에서 순간이동을 해온 시간 중 2개중에 하나가 최단시간이 된다.** From 4224b95c0df3141bd7967e2045fdc1b82baeaa91 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 6 Aug 2022 15:14:38 +0900 Subject: [PATCH 109/822] complete --- ...\210\230\352\263\204\354\202\260_DFS.java" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "08.08/\354\265\234\354\260\275\354\230\201/Main_2644_\354\264\214\354\210\230\352\263\204\354\202\260_DFS.java" diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/Main_2644_\354\264\214\354\210\230\352\263\204\354\202\260_DFS.java" "b/08.08/\354\265\234\354\260\275\354\230\201/Main_2644_\354\264\214\354\210\230\352\263\204\354\202\260_DFS.java" new file mode 100644 index 0000000..01c2bb1 --- /dev/null +++ "b/08.08/\354\265\234\354\260\275\354\230\201/Main_2644_\354\264\214\354\210\230\352\263\204\354\202\260_DFS.java" @@ -0,0 +1,54 @@ +import java.util.*; +import java.io.*; + +public class Main_2644_촌수계산_DFS { + static List> list; + static int node[]; + static boolean visit[]; + static int N; + static int a, b; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2644.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + list = new ArrayList<>(); + for(int i=0; i<=N; i++) { + list.add(new ArrayList<>()); + } + node = new int[N+1]; + visit = new boolean[N+1]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + a = Integer.parseInt(st.nextToken()); + b = Integer.parseInt(st.nextToken()); + + int M = Integer.parseInt(br.readLine()); + while(M-->0) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + list.get(y).add(x); + list.get(x).add(y); + } + + DFS(a); + if(node[b] == 0) System.out.println(-1); + else System.out.println(node[b]); + } // End of main + + private static void DFS(int num) { + visit[num] = true; + + for(int nodeNum : list.get(num)) { + + if(!visit[nodeNum]) { + node[nodeNum] = node[num] + 1; + DFS(nodeNum); + } + } + + } // End of DFS +} // End of Main class \ No newline at end of file From 9731e0d5f60d01f2d450c4363213a8ef769b561e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 6 Aug 2022 17:22:47 +0900 Subject: [PATCH 110/822] =?UTF-8?q?Create=202664=5F=EC=B4=8C=EC=88=98?= =?UTF-8?q?=EA=B3=84=EC=82=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\210\230\352\263\204\354\202\260.cpp" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" diff --git "a/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" "b/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" new file mode 100644 index 0000000..2c51eb9 --- /dev/null +++ "b/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" @@ -0,0 +1,42 @@ +#include +#include +#include +#include +using namespace std; + +int main() { + int N; cin >> N; + int board[200]; + for (int i = 1; i <= N; i++) { + board[i] = i; + } + int p1, p2; cin >> p1 >> p2; + int K; cin >> K; + for (int i = 0; i < K; i++) { + int x, y; cin >> x >> y; + board[y] = x; + } + + vector parent1(N + 1, -1), parent2(N + 1, -1); + int count = 0; + parent1[p1] = count++; + while (board[p1] != p1) { + p1 = board[p1]; + parent1[p1] = count++; + } + count = 0; + parent2[p2] = count++; + while (board[p2] != p2) { + p2 = board[p2]; + parent2[p2] = count++; + } + int answer = 200; + for (int i = 1; i <= N; i++) { + if (parent1[i] >= 0 && parent2[i] >= 0) { + answer = min(parent1[i] + parent2[i],answer); + } + } + if (answer == 200) cout << -1 << endl; + else cout << answer << endl; + return 0; +} From 4668b6add20feba6203dcd28494afaa5324a1cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 6 Aug 2022 17:32:38 +0900 Subject: [PATCH 111/822] Create readme.md --- .../readme.md" | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" new file mode 100644 index 0000000..9b45e26 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" @@ -0,0 +1,7 @@ +#프로그래머스_모의고사 + +기간 : 22년 07월 13일 10:00~ 08월 23일 23:59 + +총 3가지 문제집이 존재합니다. + +![image](https://user-images.githubusercontent.com/72062916/183241439-b4c63c66-826b-4c2b-ab1e-d4d646cf7efd.png) From 219e193d88ee4bf9e2caf6c2224a9c1539bcd0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:10:00 +0900 Subject: [PATCH 112/822] Create readme.md --- 08.11/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 08.11/readme.md diff --git a/08.11/readme.md b/08.11/readme.md new file mode 100644 index 0000000..bd9301d --- /dev/null +++ b/08.11/readme.md @@ -0,0 +1,7 @@ +#08.11(목) + +2468) 안전영역 +https://www.acmicpc.net/problem/2468 + +16953) A->B +https://www.acmicpc.net/problem/16953 From c0ad5920e570af62239176abf9bb684f52abb873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:35:52 +0900 Subject: [PATCH 113/822] =?UTF-8?q?Create=202468=5F=EC=95=88=EC=A0=84?= =?UTF-8?q?=EC=98=81=EC=97=AD.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\240\204\354\230\201\354\227\255.cpp" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" diff --git "a/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" "b/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" new file mode 100644 index 0000000..304d661 --- /dev/null +++ "b/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" @@ -0,0 +1,55 @@ +#include +#include +#include +using namespace std; +int main() { + int N; cin >> N; + vector> board; + int minest=200, maxest=0; + for (int i = 0; i < N; i++) { + vector list; + for (int k = 0; k < N; k++) { + int num; cin >> num; + minest = min(minest, num); + maxest = max(maxest, num); + list.push_back(num); + } + board.push_back(list); + } + int answer = 1; + int x[] = { 0,1,0,-1 }; + int y[] = { 1,0,-1,0 }; + for (int i = minest; i < maxest; i++) { + int count = 0; + bool visited[101][101] = { false }; + for (int k = 0; k < N; k++) { + for (int j = 0; j < N; j++) { + if (board[k][j] > i && !visited[k][j]) { + count++; + queue> q; + q.push({ k,j }); + visited[k][j] = true; + while (!q.empty()) { + pair now = q.front(); + q.pop(); + for (int t = 0; t < 4; t++) { + int xx = now.first + x[t]; + int yy = now.second + y[t]; + if (0 <= xx && xx < N && 0 <= yy && yy < N ) { + if (board[xx][yy] > i && !visited[xx][yy]) { + visited[xx][yy] = true; + q.push({ xx,yy }); + } + } + } + + } + } + + } + } + answer = max(answer, count); + } + cout << answer << endl; + return 0; +} From 2bcf370c1157b496567940e6ec5ff23620c9dda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 8 Aug 2022 10:37:04 +0900 Subject: [PATCH 114/822] Create 16953_AtoB.cpp --- .../16953_AtoB.cpp" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" diff --git "a/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" "b/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" new file mode 100644 index 0000000..4a09b55 --- /dev/null +++ "b/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" @@ -0,0 +1,25 @@ +#include +#include +using namespace std; +int main() { + long long A, B; cin >> A >> B; + queue> q; + q.push({ A,0 }); + while (!q.empty()) { + long long n = q.front().first; + int count = q.front().second; + q.pop(); + if (n == B) { + cout << count+1 << endl; + return 0; + } + if (n * 2 <= B) { + q.push({ n * 2,count + 1 }); + } + if (n * 10 + 1 <= B) { + q.push({ n * 10 + 1,count + 1 }); + } + } + cout << -1 << endl; + return 0; +} From 48d27860ff240aceec87c93d375ad66230cc7ce6 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 8 Aug 2022 12:07:44 +0900 Subject: [PATCH 115/822] solve --- ...\353\260\224\352\274\255\354\247\210.java" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" diff --git "a/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" "b/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" new file mode 100644 index 0000000..13a3211 --- /dev/null +++ "b/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" @@ -0,0 +1,61 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int time = 0; + static int[] walk = { -1, 1 }; + static Queue distance = new LinkedList(); + static boolean[] visited = new boolean[100001]; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(token.nextToken()); + int K = Integer.parseInt(token.nextToken()); + + bfs(N,K); + + } + + static void bfs(int N, int K) { + + distance.offer(N); + visited[N] = true; + + while (!distance.isEmpty()) { + + int size = distance.size(); + + for (int i = 0; i < size; i++) { + + int currentN = distance.poll(); + + if (currentN == K) { + System.out.println(time); + return; + } + + if (currentN - 1 >= 0 && !visited[currentN - 1]) { // N위치가 K위치보다 클 때 + visited[currentN - 1] = true; + distance.offer(currentN - 1); + } + + if (currentN + 1 <= 100000 && !visited[currentN + 1]) { // 걷기 + visited[currentN + 1] = true; + distance.offer(currentN + 1); + } + + if (currentN * 2 <= 100000 && !visited[currentN * 2]) { // 순간이동 + visited[currentN * 2] = true; + distance.offer(currentN * 2); + } + } + + time++; + } + } + +} From 20d4b5562316b6f210cf0eccd0324427ddfec4e9 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 8 Aug 2022 14:31:18 +0900 Subject: [PATCH 116/822] =?UTF-8?q?=EC=88=A8=EB=B0=94=EA=BC=AD=EC=A7=88=20?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14\354\210\230\352\263\204\354\202\260.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" new file mode 100644 index 0000000..60fa8ab --- /dev/null +++ "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" @@ -0,0 +1,26 @@ +import sys +sys.setrecursionlimit(300000) + +n = int(input()) +t1, t2 = map(int, input().split()) + +graph = [[] for _ in range(n+1)] # index 0 제거 +visited = [False]*(n+1) +result = [] + +for _ in range(int(input())): + x, y = map(int, input().split()) + graph[x].append(y) + graph[y].append(x) + +def dfs(node, count) : + if node == t2 : + print(count) + sys.exit() + visited[node] = True + for v in graph[node]: + if not visited[v]: + dfs(v, count+1) + +dfs(t1, 0) +print(-1) From 8e2e37abf22b07f2c579239a539fb88418dfa5e8 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 8 Aug 2022 14:32:44 +0900 Subject: [PATCH 117/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=801697.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\2001697.java" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" diff --git "a/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" "b/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" new file mode 100644 index 0000000..559508a --- /dev/null +++ "b/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" @@ -0,0 +1,101 @@ +package etc; + +import java.util.LinkedList; + +import java.util.Queue; + +import java.util.Scanner; + +class Position{ + + int me; + + int count; + + Position(int me, int count){ + + this.me=me; + + this.count=count; + + } + + + +} + + + +public class 백준1697 { + + static int n,k; + + static boolean [] visited; + + public static void main(String[] args) { + + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + visited=new boolean[100001]; + n=scan.nextInt(); + + k=scan.nextInt(); + if(n==k) System.out.print(0); + else System.out.println(bfs(n)); + + } + + public static int bfs(int n) { + + Queue q=new LinkedList<>(); + + q.offer(new Position(n,0)); + + + + while(!q.isEmpty()) { + + Position p=q.poll(); +// System.out.println(p.me+" "+p.count); + if( p.me*2<=100000&&!visited[p.me*2]) { + visited[p.me*2]=true; +// System.out.println("*2"); + + if(p.me*2==k) { + + return p.count+1; + + } + q.offer(new Position(p.me*2,p.count+1)); + } + if(p.me+1<=100000&&!visited[p.me+1]) { + visited[p.me+1]=true; +// System.out.println("+1"); + if(p.me+1==k) { + + return p.count+1; + + } + q.offer(new Position(p.me+1,p.count+1)); + } + if(p.me-1>=0&&!visited[p.me-1]) { + visited[p.me-1]=true; +// System.out.println("-1"); + if(p.me-1==k) { + + return p.count+1; + + } + q.offer(new Position(p.me-1,p.count+1)); + } + + + + + } + + return 0; + + } + +} From 3d33edaa824841f990469fb2aa4080adbd2a59e5 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 8 Aug 2022 14:34:59 +0900 Subject: [PATCH 118/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=802644.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\2002644.java" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" diff --git "a/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" "b/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" new file mode 100644 index 0000000..301354a --- /dev/null +++ "b/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" @@ -0,0 +1,51 @@ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; + +public class Main { + static int n,m, cnt; + static ArrayList> list=new ArrayList<>(); + static Queue q=new LinkedList<>(); + static int[] visited; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + n=scan.nextInt(); //전체 사람의 수 + int a=0,b=0; //촌수를 계산 해야하는 서로 다른 두사람의 번호 + a=scan.nextInt(); + b=scan.nextInt(); + m=scan.nextInt(); //부모 자식간의 관계 개수 + visited=new int[n+1]; + for(int i=0;i()); + } + + for(int i=0;i Date: Mon, 8 Aug 2022 17:01:40 +0900 Subject: [PATCH 119/822] =?UTF-8?q?=EC=88=A8=EB=B0=94=EA=BC=AD=EC=A7=88=20?= =?UTF-8?q?-=20=EC=9E=AC=EA=B7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bad ver --- ...\352\274\255\354\247\210_recursive_bad.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" new file mode 100644 index 0000000..fa250e9 --- /dev/null +++ "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" @@ -0,0 +1,19 @@ +# 무한 루프에 빠지게 되더라. + +import sys +sys.setrecursionlimit(300000) + +n, k = map(int, input().split()) + +def dfs(_n, _k, count) : + global answer + if _n == _k : answer = min(answer, count) + if _n < 0 or _n > 1000000 : return + dfs(_n-1, _k, count+1) + dfs(_n+1, _k, count+1) + dfs(2*_n, _k, count+1) + + +answer = 0 +dfs(n, k, 0) +print(answer) \ No newline at end of file From 122ad1d5ddf5503fd1e0da3820464dc200c19df9 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 8 Aug 2022 17:17:42 +0900 Subject: [PATCH 120/822] =?UTF-8?q?=EC=88=A8=EB=B0=94=EA=BC=AD=EC=A7=88=20?= =?UTF-8?q?-=20=EC=9E=AC=EA=B7=802?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 된 이유, 안 된 이유 정리 --- ...0\224\352\274\255\354\247\210_recursive.py" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" new file mode 100644 index 0000000..8c9bfaa --- /dev/null +++ "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" @@ -0,0 +1,18 @@ +# 재귀 방법으로 풀기 - 타 블로그 방식 + +import sys +sys.setrecursionlimit(300000) + +def recursive(_n, _k): + if _n >= _k: + return _n - _k + elif _k == 1: + return 1 + elif _k % 2: + return 1 + min(recursive(_n, _k- 1), recursive(_n, _k + 1)) + else: + return min(_k - _n, 1 + recursive(_n, _k // 2)) + + +n, k = map(int, input().split()) +print(recursive(n, k)) \ No newline at end of file From 473842aa6538c833bf63bd3b735981bd86e14a92 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 8 Aug 2022 18:16:47 +0900 Subject: [PATCH 121/822] =?UTF-8?q?=EC=88=A8=EB=B0=94=EA=BC=AD=EC=A7=88-BF?= =?UTF-8?q?S?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...53\260\224\352\274\255\354\247\210_bfs.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" new file mode 100644 index 0000000..e932d05 --- /dev/null +++ "b/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" @@ -0,0 +1,20 @@ +from collections import deque + +n, k = map(int, input().split()) +check = [0] * 100001 + + +def bfs(): + queue = deque() + queue.append(n) + while queue: + _present = queue.popleft() + if _present == k: return check[_present] + for _next in (_present - 1, _present + 1, _present*2): + if 0 <= _next <= 100000 and check[_next] == 0: + check[_next] = check[_present] + 1 + queue.append(_next) + + +answer = bfs() +print(answer) From fe96a142aa2c8def0b80ad3b61456a01df139dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:39:38 +0900 Subject: [PATCH 122/822] =?UTF-8?q?Create=202644=5F=EC=B4=8C=EC=88=98?= =?UTF-8?q?=EA=B3=84=EC=82=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\352\263\204\354\202\260.java" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" "b/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" new file mode 100644 index 0000000..7191a45 --- /dev/null +++ "b/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" @@ -0,0 +1,64 @@ +import java.util.*; + +public class Main { + + static int N, M, A, B, X, Y; + static ArrayList> map = new ArrayList<>(); + static int family[]; + + public static void main(String[] args) { + // 2644 촌수계산 + Scanner sc = new Scanner(System.in); + + // 전체 사람의 수 + N = sc.nextInt(); sc.nextLine(); + + family = new int[N + 1]; + for (int i = 0; i <= N; i++) { + map.add(new ArrayList<>()); + } + + String s[] = sc.nextLine().split(" "); + A = Integer.parseInt(s[0]); // 구해야하는 사람 1 + B = Integer.parseInt(s[1]); // 구해야하는 사람 2 + + // 부모관계 개수 + M = sc.nextInt(); sc.nextLine(); + + for (int i = 0; i < M; i++) { + s = sc.nextLine().split(" "); + X = Integer.parseInt(s[0]); // 부모 + Y = Integer.parseInt(s[1]); // 자식 + map.get(X).add(Y); + map.get(Y).add(X); + } + bfs(); + } + + static void bfs() { + + Queue q = new LinkedList<>(); + + q.add(A); + family[A] = 1; + + while (!q.isEmpty()) { + int n = q.poll(); + + if (n == B) { + System.out.println(family[B] - 1); + return; + } + for (int i = 0; i < map.get(n).size(); i++) { + int tmp = map.get(n).get(i); + + if(family[tmp] == 0) { + q.add(tmp); + family[tmp] = family[n] + 1; + } + } + + } + System.out.println(-1); + } +} From 1fede10c0ba8571fa3eabb7a313287769daa7c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:40:12 +0900 Subject: [PATCH 123/822] =?UTF-8?q?Create=201697=5F=EC=88=A8=EB=B0=94?= =?UTF-8?q?=EA=BC=AD=EC=A7=88.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\260\224\352\274\255\354\247\210.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" "b/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" new file mode 100644 index 0000000..922adcc --- /dev/null +++ "b/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" @@ -0,0 +1,40 @@ +import java.util.*; +public class Main { + static int N, K; + static int time[] = new int[100001]; + public static void main(String[] args) { + // 1697번 숨바꼭질 + + Scanner sc = new Scanner(System.in); + N = sc.nextInt(); + K = sc.nextInt(); + + bfs(N); + } + static void bfs(int n) { + Queue q = new LinkedList<>(); + q.add(n); + time[n] = 1; + while (!q.isEmpty()) { + int nn = q.poll(); + if (nn == K) { + System.out.println(time[nn] - 1); + return; + } + if (nn - 1 >= 0 && time[nn - 1] == 0) { + time[nn - 1] = time[nn] + 1; + q.add(nn - 1); + } + if (nn + 1 <= 100000 && time[nn + 1] == 0) { + time[nn + 1] = time[nn] + 1; + q.add(nn + 1); + + } + if (2 * nn <= 100000 && time[2 * nn] == 0) { + time[2 * nn] = time[nn] + 1; + q.add(2 * nn); + } + } + System.out.println(-1); + } +} From d6f070aa68f1c1892e9eb2eac6249215ab72e5a8 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 8 Aug 2022 19:33:34 +0900 Subject: [PATCH 124/822] solve --- .../16953_A_B.java" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" diff --git "a/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" "b/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" new file mode 100644 index 0000000..3a1c8bb --- /dev/null +++ "b/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" @@ -0,0 +1,56 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int count = 0; + static boolean[] visited = new boolean[1000000001]; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + + long A = Long.parseLong(token.nextToken()); + long B = Long.parseLong(token.nextToken()); + + bfs(A, B); + + System.out.println(count); + + } + + static void bfs(long A, long B) { + Queue current = new LinkedList(); + current.add(A); + visited[(int) A] = true; + + while (!current.isEmpty()) { + int cSize = current.size(); + + for (int i = 0; i < cSize; i++) { + + long num = current.poll(); + + if (num == B) { + count++; + return; + } + + if (num * 2 <= B && !visited[(int) (num * 2)]) { + current.offer(num * 2); + visited[(int) (num * 2)] = true; + } + + if ((num * 10) + 1 <= B && !visited[(int) ((num * 10) + 1)]) { + current.offer((num * 10) + 1); + visited[(int) ((num * 10) + 1)] = true; + } + } + count++; + } + + count = -1; + } + +} From dda33cc271d0b1965d86453a2b6b7d6f679f444b Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 8 Aug 2022 20:04:20 +0900 Subject: [PATCH 125/822] kihun --- ...50\353\260\224\352\274\255\354\247\210.py" | 33 +++++++++++++++++ ...14\354\210\230\352\263\204\354\202\260.py" | 37 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 "08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" create mode 100644 "08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" diff --git "a/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" "b/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" new file mode 100644 index 0000000..340836a --- /dev/null +++ "b/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" @@ -0,0 +1,33 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +N, K = map(int, input().split()) + +visited = [0] * 100001 + + +def bfs(n): + q = deque([n]) + while q: + n = q.popleft() + if n == K: + return visited[n] + for moveN in (n - 1, n + 1, n * 2): + if (0 <= moveN <= 100000) and (visited[moveN] == 0): + visited[moveN] = visited[n] + 1 + q.append(moveN) + + +time = bfs(N) + +print(time) + +""" +dfs는 모든 경로를 탐색하고 결과를 내놓으니까 bfs 사용 +visited를 만들어서 해당 칸에 터치되는 횟수 = 시간을 체크... +visited는 100001에서 -1 되는 경우도 있으므로 100001개 +K에 도달하면 visited의 값을 리턴 +a -> a1 a2 a3 -> a11 a12 a13 / a21 a22 a23 / a31 a32 a33 +""" diff --git "a/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" new file mode 100644 index 0000000..8dd2450 --- /dev/null +++ "b/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" @@ -0,0 +1,37 @@ +import sys + +input = sys.stdin.readline + +# 전체사람 수 n +n = int(input()) +# 찾을 관계 a, b +a, b = map(int, input().split()) +# 관계 수 +m = int(input()) + +arr = [[] for _ in range(n + 1)] +visited = [0] * (n + 1) + +# x가 부모, y가 자식 +for _ in range(m): + x, y = map(int, input().split()) + arr[x].append(y) + arr[y].append(x) + + +def dfs(first, index): + visited[first] = 1 + + if first == b: + print(index) + exit() + + for i in arr[first]: + if visited[i] == 0: + dfs(i, index + 1) + + +dfs(a, 0) +print(-1) + +# 11725 트리의 부모찾기 참고 From 179854712dd2a146df3f131ff837461d6d112418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:45:32 +0900 Subject: [PATCH 126/822] Create readme.md --- "08.11/\355\231\251\354\247\200\354\233\220/readme.md" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "08.11/\355\231\251\354\247\200\354\233\220/readme.md" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.11/\355\231\251\354\247\200\354\233\220/readme.md" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/08.11/\355\231\251\354\247\200\354\233\220/readme.md" @@ -0,0 +1 @@ + From bee8113fde8395d3840c2e98d55b40e80fea9b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:46:07 +0900 Subject: [PATCH 127/822] Create a.java --- "08.11/\355\231\251\354\247\200\354\233\220/a.java" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "08.11/\355\231\251\354\247\200\354\233\220/a.java" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/a.java" "b/08.11/\355\231\251\354\247\200\354\233\220/a.java" new file mode 100644 index 0000000..ce01362 --- /dev/null +++ "b/08.11/\355\231\251\354\247\200\354\233\220/a.java" @@ -0,0 +1 @@ +hello From ddc224c6e382fad22e66a97f9e3a8d61b8a41116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:46:15 +0900 Subject: [PATCH 128/822] Delete a.java --- "08.11/\355\231\251\354\247\200\354\233\220/a.java" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "08.11/\355\231\251\354\247\200\354\233\220/a.java" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/a.java" "b/08.11/\355\231\251\354\247\200\354\233\220/a.java" deleted file mode 100644 index ce01362..0000000 --- "a/08.11/\355\231\251\354\247\200\354\233\220/a.java" +++ /dev/null @@ -1 +0,0 @@ -hello From 0906b0f794670d4df764c6e85f02517cdeb3af5d Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 8 Aug 2022 22:44:11 +0900 Subject: [PATCH 129/822] solve --- ...\354\240\204\354\230\201\354\227\255.java" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" diff --git "a/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" "b/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" new file mode 100644 index 0000000..1f3280f --- /dev/null +++ "b/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" @@ -0,0 +1,86 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int count; + static int maxCount = 0; + static int[] dx = {0,0,-1,1}; + static int[] dy = {-1,1,0,0}; + static boolean[][] visited; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + int[][] area = new int[N][N]; + int maxHeight = 0; + + for (int i = 0; i < area.length; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 0; j < area.length; j++) { + area[i][j] = Integer.parseInt(token.nextToken()); + maxHeight = Math.max(maxHeight,area[i][j]); + } + } + + for (int i = 0; i <= maxHeight-1; i++) { + search(i,area); + } + + System.out.println(maxCount); + + } + + static void search(int base, int[][] area) { + visited = new boolean[N][N]; + count = 0; + + for (int i = 0; i < area.length; i++) { + for (int j = 0; j < area.length; j++) { + if (area[i][j] <= base) { + visited[i][j] = true; + } + } + } + + for (int i = 0; i < visited.length; i++) { + for (int j = 0; j < visited.length; j++) { + if (!visited[i][j]) { + bfs(i,j); + } + } + } + + maxCount = Math.max(maxCount,count); + + + + } + + static void bfs(int row, int col) { + + Queue safe = new LinkedList(); + + safe.add(new Point(row,col)); + visited[row][col] = true; + + while(!safe.isEmpty()) { + Point point = safe.poll(); + for (int i = 0; i < dx.length; i++) { + int x = point.x + dx[i]; + int y = point.y + dy[i]; + + if (x >= 0 && x < N && y >= 0 && y < N) { + if (!visited[x][y]) { + visited[x][y] = true; + safe.add(new Point(x,y)); + } + } + } + } + count++; + } +} From d871bcfcf1eeaf3c0359146683c2343f6a8e7586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:31:00 +0900 Subject: [PATCH 130/822] Update readme.md --- "08.11/\355\231\251\354\247\200\354\233\220/readme.md" | 4 ++++ 1 file changed, 4 insertions(+) diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.11/\355\231\251\354\247\200\354\233\220/readme.md" index 8b13789..e38b6a2 100644 --- "a/08.11/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.11/\355\231\251\354\247\200\354\233\220/readme.md" @@ -1 +1,5 @@ +### 16953번 - A → B 반례모음 +500000000 1000000000 // 2 +2 5 // -1 +-- long으로 안 하면 틀림 From b10f09c8d807199805ae4f8ba6b77bf0f666f2b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:31:26 +0900 Subject: [PATCH 131/822] Create 16953_A->B --- .../16953_A->B" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" "b/08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" new file mode 100644 index 0000000..abc7398 --- /dev/null +++ "b/08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" @@ -0,0 +1,57 @@ +import java.util.*; + +class Pair { + long x; + long y; + + Pair(long x, long y) { + this.x = x; + this.y = y; + } +} + +public class Main { + + static long A, B, cnt; + static ArrayList> a = new ArrayList<>(); + + public static void main(String[] args) { + // 16953 + Scanner sc = new Scanner(System.in); + + A = sc.nextInt(); + B = sc.nextInt(); + + bfs(); + if (cnt == -1) { + System.out.println(-1); + } else { + System.out.println(cnt + 1); + } + } + + static void bfs() { + Queue q = new LinkedList<>(); + q.add(new Pair(A, 0)); + + cnt = 0; + + while (!q.isEmpty()) { + Pair p = q.poll(); + + if (p.x == B) { + cnt = p.y; + return; + } + if (p.x * 2 <= B) { + q.add(new Pair(p.x * 2, p.y + 1)); + } + if ((p.x * 10 + 1) <= B) { + q.add(new Pair(p.x * 10 + 1, p.y + 1)); + } + } + cnt = -1; + + } + +} From bd7b93c3e79a3ca8164612fe529bf036d50cfa1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:31:49 +0900 Subject: [PATCH 132/822] Rename 16953_A->B to 16953_A->B.java --- .../\355\231\251\354\247\200\354\233\220/16953_A->B.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" => "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B.java" (100%) diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" "b/08.11/\355\231\251\354\247\200\354\233\220/16953_A->B.java" similarity index 100% rename from "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B" rename to "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B.java" From 4ab79c0f382d11bad8a04e4d6ff924f8770d2460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 9 Aug 2022 22:12:54 +0900 Subject: [PATCH 133/822] Rename 16953_A->B.java to 16953_AtoB.java --- .../\355\231\251\354\247\200\354\233\220/16953_AtoB.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B.java" => "08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" (100%) diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/16953_A->B.java" "b/08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" similarity index 100% rename from "08.11/\355\231\251\354\247\200\354\233\220/16953_A->B.java" rename to "08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" From 457a8c01eaed1c5f688aa75294f28e3d08730366 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Wed, 10 Aug 2022 15:58:56 +0900 Subject: [PATCH 134/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=8016953.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\20016953.java" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" diff --git "a/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" "b/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" new file mode 100644 index 0000000..80098f1 --- /dev/null +++ "b/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" @@ -0,0 +1,82 @@ +import java.util.LinkedList; + +import java.util.Queue; + +import java.util.Scanner; + + + +class position{ + + long p; + + long cnt; + + position(long p, long cnt){ + + this.p=p; + + this.cnt=cnt; + + } + +} + +public class Main { + + public static void main(String[] args) { + + // TODO Auto-generated method stub + + Scanner scan=new Scanner(System.in); + + long a=scan.nextLong(); + + long b=scan.nextLong(); + + if(a==b) { + System.out.println(0); + return; + } + + Queue q=new LinkedList<>(); + + + + q.offer(new position(a,1)); + long res = -1; + + while(!q.isEmpty()) { + + position now=q.poll(); + if(now.p == b) { + res = now.cnt; + break; + } + + if(now.p > b) { + break; + } + + if(now.p*2<=b) { + + q.offer(new position(now.p*2,now.cnt+1)); + + } + + + + if((now.p*10)+1<=b) { + + q.offer(new position((now.p*10)+1,now.cnt+1)); + + } + + + } +System.out.println(res); + } + + + +} From 3039dfe8e7ce3a2862dd8e3a81f05602bedbb1cf Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Wed, 10 Aug 2022 15:59:33 +0900 Subject: [PATCH 135/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=202468.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 2468.java" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" diff --git "a/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" "b/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" new file mode 100644 index 0000000..3bc89eb --- /dev/null +++ "b/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" @@ -0,0 +1,75 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; + +public class Main{ + static boolean[][] visited; + static int n,max; + static int[] dx= {0,1,0,-1}; + static int[] dy= {1,0,-1,0}; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + + n=scan.nextInt(); + max=0; + int cnt=0; + int MAX=0; + int min=101; + + int[][] arr=new int[n][n]; + for(int i=0;imax) { + max=arr[i][j]; + } + if(arr[i][j]k) { +// System.out.println("k : "+k); + + cnt++; + dfs(i,j,arr,k); + } + } + } + if(MAX=0&&ny>=0&&nxdepth) { +// System.out.println(nx+" "+ny); + visited[nx][ny]=true; + dfs(nx,ny,arr,depth); + } + } + + } +} From 39064fe4d5fe994c88d3f0059119c59ec4fee5b4 Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Wed, 10 Aug 2022 17:03:19 +0900 Subject: [PATCH 136/822] Create [BOJ_16953]A_B.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A_B 완료 --- .../[BOJ_16953]A_B.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" diff --git "a/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" "b/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" new file mode 100644 index 0000000..9a415d0 --- /dev/null +++ "b/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" @@ -0,0 +1,19 @@ +from collections import deque + +def solution(_a, _b) -> int: + queue = deque() + queue.append((_a, 1)) + while queue: + num, count = queue.popleft() + next_num = [10*num+1, 2*num] + for _next_n in next_num: + if _next_n == _b : return count + 1 + if _next_n < _b : + queue.append((_next_n, count+1)) + return -1 + + + +a, b = map(int, input().split()) +answer = solution(a, b) +print(answer) From 5a8edf295ad5765f12ace574a8ce31fa6cf818b3 Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Wed, 10 Aug 2022 17:04:02 +0900 Subject: [PATCH 137/822] =?UTF-8?q?Create=20[BOJ=5F2468]=EC=95=88=EC=A0=84?= =?UTF-8?q?=EC=98=81=EC=97=AD.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 안전 영역 완료 --- ...10\354\240\204\354\230\201\354\227\255.py" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" diff --git "a/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" "b/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" new file mode 100644 index 0000000..0946280 --- /dev/null +++ "b/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" @@ -0,0 +1,49 @@ +# import sys +# sys.stdin = open("input.txt") + +from copy import deepcopy + +from collections import deque +move = [(1, 0), (0, 1), (-1, 0), (0, -1)] # 오른쪽, 아래, 왼쪽, 위 (4방향 다 가야함) + + + + +def bfs(_start, _h, _n, _arr) -> list: + queue = deque() + queue.append(_start) + while queue: + x, y = queue.popleft() + for direction in move: + nx, ny = x + direction[0], y+direction[1] + if 0<=nx<_n and 0<=ny<_n and _arr[ny][nx]>_h: + queue.append((nx, ny)) + _arr[ny][nx] = -1 + return _arr + +def solution(_h, _n, _arr) -> int : + area_count = 0 + for y in range(_n): + for x in range(_n): + if _arr[y][x] > h: + pos = (x, y) + _arr[y][x] = -1 + _arr = bfs(pos, _h, _n, _arr) + area_count += 1 + return area_count + + + +n = int(input()) +max_height = 0 + +arr = [] +answer = [] +for _ in range(n): + row = list(map(int, input().split())) + max_height = max(max_height, max(row)) + arr.append(row) + +for h in range(0, max_height): # 주의 : 비가 전혀 오지 않을 경우도 고려 해야 한다. => max_height를 2부터 했더니 valueError! + answer.append(solution(h, n, deepcopy(arr))) # arr.copy()도 얕은 복사 메소드 +print(max(answer)) From 9aa31b3530be85e08939dc9e17cfb2e6202e1248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 10 Aug 2022 17:40:08 +0900 Subject: [PATCH 138/822] =?UTF-8?q?Create=202468=5F=EC=95=88=EC=A0=84?= =?UTF-8?q?=EC=98=81=EC=97=AD.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\240\204\354\230\201\354\227\255.java" | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 "08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" "b/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" new file mode 100644 index 0000000..7cf2065 --- /dev/null +++ "b/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" @@ -0,0 +1,115 @@ +import java.io.*; +import java.util.*; + +class Coo { + int x, y; + + Coo(int x, int y) { + this.x = x; + this.y = y; + } +} + +public class Main { + + static int N, cnt, maxL, minL, bigCnt; + static int map[][]; + static boolean visited[][]; + static int dx[] = { 0, 0, -1, 1 }; + static int dy[] = { 1, -1, 0, 0, }; + + public static void main(String[] args) throws Exception { + // 안전 영역 + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + // N 입력 + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + + // map 입력 + map = new int[N][N]; + visited = new boolean[N][N]; + + maxL = Integer.MIN_VALUE; // 최고 높이 + minL = Integer.MAX_VALUE; // 최저 높이 + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if (maxL < map[i][j]) { + maxL = map[i][j]; + } + if (minL > map[i][j]) { + minL = map[i][j]; + } + } + } + + for (int k = minL; k < maxL; k++) { + // 초기화 + cnt = 0; + for(boolean[] b : visited) { + Arrays.fill(b, false); + } + // 물에 가라 앉히기 + visitCheck(k); + + + // 물에 가라 앉지 않은 땅 개수 세기 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (!visited[i][j]) { + bfs(i, j); + cnt++; + } + } + } + if(cnt > bigCnt) { + bigCnt = cnt; + } + } + if (bigCnt == 0) + System.out.println(1); + else + System.out.println(bigCnt); + + } + + // 가서 방문체크만 다 하고 땅 덩어리 개수 cnt에 담아 + static void bfs(int i, int j) { + + Queue q = new LinkedList<>(); + q.offer(new Coo(i, j)); + + while(!q.isEmpty()) { + Coo a = q.poll(); + visited[a.x][a.y] = true; + + for(int f=0; f<4; f++) { + int nx = a.x + dx[f]; + int ny = a.y + dy[f]; + + if(0 <= nx && nx < N && 0 <= ny && ny < N) { + if(!visited[nx] [ny]) { + q.add(new Coo(nx, ny)); + visited[nx][ny] = true; + } + + } + } + + } + + } + + + static void visitCheck(int k) { + for(int i=0; i Date: Wed, 10 Aug 2022 17:41:29 +0900 Subject: [PATCH 139/822] Update readme.md --- .../readme.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" index 9b45e26..26000bf 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/readme.md" @@ -1,4 +1,4 @@ -#프로그래머스_모의고사 +# 프로그래머스_모의고사 기간 : 22년 07월 13일 10:00~ 08월 23일 23:59 From bba35e7a6dd55d00ea77c72cb531c46a8e5e7a22 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Wed, 10 Aug 2022 21:04:59 +0900 Subject: [PATCH 140/822] complete --- .../Main_16953_AtoB_BFS.java" | 69 +++++++++++++++++ ...\353\260\230\352\265\254\355\230\204.java" | 47 ++++++++++++ ...\354\240\204\354\230\201\354\227\255.java" | 75 +++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 "08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" create mode 100644 "08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" create mode 100644 "08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" diff --git "a/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" "b/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" new file mode 100644 index 0000000..086d17b --- /dev/null +++ "b/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" @@ -0,0 +1,69 @@ +import java.util.*; +import java.io.*; + +// https://www.acmicpc.net/problem/16953 + +/* + * - 뒤에서부터 거꾸로 접근한다. +B의 일의 자리가 1이면 (B % 10 = 1) 일의 자리를 없앤다. (B /= 10) +그렇지 않고, B가 2로 나뉜다면 (B % 2 = 0) 2로 나누어준다. (B /= 2) +둘 다 못한다면, B는 절대로 A가 될 수 없다. +A가 B로 나아가는 수단은 위 두 가지 밖에 없기 때문이다. + */ + +public class Main_16953_AtoB_BFS { + static Queue que = new LinkedList<>(); + + static long A, B; + static int count = 1; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_16953.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + A = Long.parseLong(st.nextToken()); + B = Long.parseLong(st.nextToken()); + + BFS(); + System.out.println(count); + } + + static void BFS() { + que.offer(B); + + while( !que.isEmpty() ) { + long num = que.poll(); + String str = Long.toString(num); + + // 탈출 조건 + if(num == A) { + return; + } + else if(num < A) { + count = -1; + return; + } + + if(num % 2 == 0) { + num /= 2; + que.offer(num); + count ++; + } + else if(str.charAt(str.length() -1) == '1') { + num = Long.parseLong( str.substring(0, str.length() - 1) ); + que.offer(num); + count ++; + } + else { + count = -1; + return; + } + + + + } + + } // End of BFS + +} // End of class diff --git "a/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" "b/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" new file mode 100644 index 0000000..18bdae0 --- /dev/null +++ "b/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" @@ -0,0 +1,47 @@ +import java.util.*; +import java.io.*; + +// https://www.acmicpc.net/problem/16953 + +public class Main_16953_AtoB_일반구현 { + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_16953.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + long A = Long.parseLong(st.nextToken()); + long B = Long.parseLong(st.nextToken()); + int count = 1; + + // B가 A보다 크면 계속 반복 + while(B != A) { + String str = Long.toString(B); + + // B가 짝수 일때 + if(B % 2 == 0) { + B /= 2; + } + else if(str.charAt(str.length() -1) == '1') { + B = Long.parseLong( str.substring(0, str.length() - 1) ); + } + // 홀수일 경우 -1 출력 + else { + count = -1; + break; + } + + + // 탈출 조건 + // 반복하면서 B가 계속 작아지면서, A보다 작아질 경우, 틀린것으로 판단 + // -1을 출력 + if(B < A) { + count = -1; + break; + } + + count ++; + } + + System.out.println(count); + } +} diff --git "a/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" "b/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" new file mode 100644 index 0000000..748f324 --- /dev/null +++ "b/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" @@ -0,0 +1,75 @@ +import java.util.*; +import java.io.*; + +public class Main_2468_안전영역 { + static List list = new ArrayList<>(); + static int dirX[] = {0, 0, -1, 1}; // 상 하 좌 우 + static int dirY[] = {-1, 1, 0, 0}; // 상 하 좌 우 + static boolean visit[][]; + static int arr[][]; + + static int N, nowX, nowY; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_2468.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + + arr = new int[N][N]; + for(int i=0; i= num) { + DFS(i, j, num); + safeArea++; + } + } + } + + max = Math.max(max, safeArea); + } + + System.out.println(max); + } // End of main + + static void DFS(int x, int y, int num) { + visit[x][y] = true; + + for(int i=0; i<4; i++) { + nowX = x + dirX[i]; + nowY = y + dirY[i]; + + if(range_check() && visit[nowX][nowY] == false && arr[nowX][nowY] >= num) { + DFS(nowX, nowY, num); + } + } + + } // End of DFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < N && nowY < N); + } // End range_check + +} // End of Main class \ No newline at end of file From 745703178223d1e391dbc55087afc6457b962e50 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 10 Aug 2022 22:02:11 +0900 Subject: [PATCH 141/822] kihun --- .../\353\260\261\354\244\200_16953_AB.py" | 32 +++++++++++++ ...10\354\240\204\354\230\201\354\227\255.py" | 45 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 "08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" create mode 100644 "08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" diff --git "a/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" "b/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" new file mode 100644 index 0000000..80964b3 --- /dev/null +++ "b/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" @@ -0,0 +1,32 @@ +from collections import deque + +A, B = map(int, input().split()) + +q = deque() + +# visited = [0] * (B + 1) 메모리 초과 나서 없애버림 +# 튜플 값을 받는 것으로 변경 + + +def bfs(n, i): + q.append((n, i)) + while q: + n, i = q.popleft() + if n == B: + print(i + 1) + exit() + if n > B: + # 연산이 두 개니까 break 하면 안됨 + continue + for f in (0, 1): + if f == 0: + newN = n * 2 + else: + newN = n * 10 + 1 + if 0 <= newN <= B: + q.append((newN, i + 1)) + + +result = bfs(A, 0) + +print(-1) diff --git "a/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" "b/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" new file mode 100644 index 0000000..dd06ea0 --- /dev/null +++ "b/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" @@ -0,0 +1,45 @@ +import sys + +sys.setrecursionlimit(10000) +input = sys.stdin.readline + +N = int(input()) + +matrix = [list(map(int, input().split())) for _ in range(N)] + +maxHeight = max(map(max, matrix)) + +dy = [0, 0, 1, -1] +dx = [1, -1, 0, 0] + + +def dfs(x, y, rain): + + for i in range(4): + nY = y + dy[i] + nX = x + dx[i] + + if ( + (0 <= nX < N) + and (0 <= nY < N) + and visited[nY][nX] == False + and matrix[nY][nX] > rain + ): + visited[nY][nX] = True + dfs(nX, nY, rain) + + +answer = 0 +for rain in range(maxHeight): + visited = [[False] * N for _ in range(N)] + area = 0 + for y in range(N): + for x in range(N): + if visited[y][x] == False and matrix[y][x] > rain: + visited[y][x] = True + area += 1 + dfs(x, y, rain) + + answer = max(answer, area) + +print(answer) From 1e1f9968d524e91ba31d547e251624b4e2aa9b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:14:42 +0900 Subject: [PATCH 142/822] =?UTF-8?q?Create=20=EC=95=84=EA=B8=B0=EC=83=81?= =?UTF-8?q?=EC=96=B42.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\270\260\354\203\201\354\226\2642.java" | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 "07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" diff --git "a/07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" "b/07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" new file mode 100644 index 0000000..4534480 --- /dev/null +++ "b/07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" @@ -0,0 +1,102 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +class Coo { + int x; + int y; + + Coo(int x, int y) { + this.x = x; + this.y = y; + } +} + +public class Main { + + static int N, M, cnt; + static int map[][] = new int[51][51]; + static int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; + static int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; + + public static void main(String[] args) throws Exception { + // 16953IOExce + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + // 상어만(1만) 돌리기 + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (map[i][j] == 1) { + bfs(i, j); + } + } + } + + // 최대값 구하기 + int tmp = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + tmp = Math.max(tmp, map[i][j]); + } + } + System.out.println(tmp-1); +// sb.append(tmp); +// bw.write(sb.toString()); bw.close(); + + } + + static void bfs(int i, int j) { + Queue q = new LinkedList<>(); + boolean visited[][] = new boolean[N][M]; + q.offer(new Coo(i, j)); // add 대신 offer + map[i][j] = 1; + + while (!q.isEmpty()) { + Coo p = q.poll(); + visited[p.x][p.y] = true; // 방문체크는 해줌 + + for (int a = 0; a < 8; a++) { + int nx = p.x + dx[a]; + int ny = p.y + dy[a]; + + if (rangeCheck(nx, ny) && !visited[nx][ny]) { + if(map[nx][ny] != 0) { // 0이 아니라는 건 전에 한번 왔었다는 것 + map[nx][ny] = Math.min(map[p.x][p.y] + 1, map[nx][ny]); + } + else { + map[nx][ny] = map[p.x][p.y] + 1; + } + q.offer(new Coo(nx, ny)); + visited[nx][ny] = true; + } + + } + + } + } + + static boolean rangeCheck(int nx, int ny) { + return (0 <= nx && nx < N && 0 <= ny && ny < M); + } + +} + + From b2ff8db8402106dbacb44b2dd7b82275cfec3fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:14:55 +0900 Subject: [PATCH 143/822] =?UTF-8?q?Rename=2007.28/=EC=95=84=EA=B8=B0?= =?UTF-8?q?=EC=83=81=EC=96=B42.java=20to=2007.28/=ED=99=A9=EC=A7=80?= =?UTF-8?q?=EC=9B=90/=EC=95=84=EA=B8=B0=EC=83=81=EC=96=B42.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\225\204\352\270\260\354\203\201\354\226\2642.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" => "07.28/\355\231\251\354\247\200\354\233\220/\354\225\204\352\270\260\354\203\201\354\226\2642.java" (100%) diff --git "a/07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" "b/07.28/\355\231\251\354\247\200\354\233\220/\354\225\204\352\270\260\354\203\201\354\226\2642.java" similarity index 100% rename from "07.28/\354\225\204\352\270\260\354\203\201\354\226\2642.java" rename to "07.28/\355\231\251\354\247\200\354\233\220/\354\225\204\352\270\260\354\203\201\354\226\2642.java" From 683581a8bbf0947e62d0275fcfdb9c9e78151c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:15:19 +0900 Subject: [PATCH 144/822] =?UTF-8?q?Rename=20=EC=95=84=EA=B8=B0=EC=83=81?= =?UTF-8?q?=EC=96=B42.java=20to=2017086=5F=EC=95=84=EA=B8=B0=EC=83=81?= =?UTF-8?q?=EC=96=B42.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../17086_\354\225\204\352\270\260\354\203\201\354\226\2642.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "07.28/\355\231\251\354\247\200\354\233\220/\354\225\204\352\270\260\354\203\201\354\226\2642.java" => "07.28/\355\231\251\354\247\200\354\233\220/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.java" (100%) diff --git "a/07.28/\355\231\251\354\247\200\354\233\220/\354\225\204\352\270\260\354\203\201\354\226\2642.java" "b/07.28/\355\231\251\354\247\200\354\233\220/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.java" similarity index 100% rename from "07.28/\355\231\251\354\247\200\354\233\220/\354\225\204\352\270\260\354\203\201\354\226\2642.java" rename to "07.28/\355\231\251\354\247\200\354\233\220/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.java" From 63842479a4f5e862c73d538afa9bb70b5d47873c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:16:09 +0900 Subject: [PATCH 145/822] Update readme.md --- "08.11/\355\231\251\354\247\200\354\233\220/readme.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/readme.md" "b/08.11/\355\231\251\354\247\200\354\233\220/readme.md" index e38b6a2..e94590b 100644 --- "a/08.11/\355\231\251\354\247\200\354\233\220/readme.md" +++ "b/08.11/\355\231\251\354\247\200\354\233\220/readme.md" @@ -2,4 +2,4 @@ 500000000 1000000000 // 2 2 5 // -1 --- long으로 안 하면 틀림 +* long으로 안 하면 틀림 From 45819d52f57aa0c8227194e179c1493fb8a76ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 12 Aug 2022 09:12:02 +0900 Subject: [PATCH 146/822] Create readme.md --- 08.15/readme.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 08.15/readme.md diff --git a/08.15/readme.md b/08.15/readme.md new file mode 100644 index 0000000..ed9dc33 --- /dev/null +++ b/08.15/readme.md @@ -0,0 +1,10 @@ +# 08.15(월) 스터디 + +16637 괄호 추가하기 +https://www.acmicpc.net/problem/16637 + +17070 파이프 옮기기1 + https://www.acmicpc.net/problem/17070 + + 17135 캐슬 디펜스 + https://www.acmicpc.net/problem/17135 From 0fc2fc8821d95f5914fcd0e4944ca4521ec2d2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:02:04 +0900 Subject: [PATCH 147/822] =?UTF-8?q?Create=2016637=5F=EA=B4=84=ED=98=B8=5F?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\260\200\355\225\230\352\270\260.cpp" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" diff --git "a/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" "b/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..9951cee --- /dev/null +++ "b/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +int calculator(int n1, int n2, char cal) { + switch (cal) { + case '+': + return n1 + n2; + case '-': + return n1 - n2; + case '*': + return n1 * n2; + } + return 0; +} + +int startCal(deque &dq) { + while (dq.size() > 1) { + int n1 = stoi(dq.front()); dq.pop_front(); + char cal = dq.front()[0]; dq.pop_front(); + int n2 = stoi(dq.front()); dq.pop_front(); + int result = calculator(n1, n2, cal); + dq.push_front(to_string(result)); + } + int total = stoi(dq.front()); + dq.pop_front(); + return total; +} + +int main() { + int N; cin >> N; + string str; cin >> str; + int maxTotal = INT_MIN; + for (int i = 0; i < (1 << N / 2); i++) { + deque dq; + dq.push_back(str.substr(0, 1)); + for (int j = 0; j < N / 2; j++) { //연속된 수 x + if (i & (1 << j)) { + if (j > 0 && (i & (1 << (j - 1)))) { + dq.clear(); + break; + } + int n1 = stoi(dq.back()); + dq.pop_back(); + char c = str[j*2+1]; + int n2 = str[j * 2 + 2] - '0'; + int result = calculator(n1, n2, c); + if (result < 0 && !dq.empty() && dq.back().compare("-")==0) { + dq.pop_back(); + dq.push_back("+"); + result = abs(result); + } + dq.push_back(to_string(result)); + } + else { + dq.push_back(str.substr(j*2+1,1)); + dq.push_back(str.substr(j * 2 + 2, 1)); + } + } + if (dq.size() > 0) { + int total = startCal(dq); + maxTotal = max(total, maxTotal); + } + } + cout << maxTotal << endl; + return 0; +} From 66a09870a9503db69d83d185e68ab90e9fc1067f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 12 Aug 2022 13:34:43 +0900 Subject: [PATCH 148/822] =?UTF-8?q?Create=2017070=5F=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=ED=94=84=5F=EC=98=AE=EA=B8=B0=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\354\230\256\352\270\260\352\270\260.cpp" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" diff --git "a/08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" "b/08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" new file mode 100644 index 0000000..fdc1702 --- /dev/null +++ "b/08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" @@ -0,0 +1,54 @@ +#include +#include +#include +using namespace std; +int main() { + int N; cin >> N; + vector> board; + vector> count; + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < N; k++) { + int n; cin >> n; + tmp.push_back(n); + } + board.push_back(tmp); + vector tmp1(N, 0); + count.push_back(tmp1); + } + if (board[N - 1][N - 1] == 1) { + cout << 0 << endl; + return 0; + } + queue> q; //x1,y1,x2,y2 + int dx[] = { 0,1,1 }; + int dy[] = { 1,0,1 }; + q.push({ 0,0, 0,1 }); + count[0][1] = 1; + while (!q.empty()) { + vector now = q.front(); + q.pop(); + if (now[1] != now[3] && now[3] < N - 1 && board[now[2]][now[3] + 1] == 0) { //가로 + q.push({ now[2],now[3], now[2],now[3] + 1 }); + count[now[2]][now[3] + 1]++; //+= count[now[2]][now[3]]; + } + if (now[0] != now[2] && now[2] < N - 1 && board[now[2] + 1][now[3]] == 0) { //세로 + q.push({ now[2],now[3], now[2] + 1, now[3] }); + count[now[2] + 1][now[3]] ++; + } + if (now[2] < N - 1 && now[3] < N - 1) { //대각선 + bool flag = true; + for (int i = 0; i < 3; i++) { + if (board[now[2] + dx[i]][now[3] + dy[i]] != 0) { + flag = false; + } + } + if (flag) { + q.push({ now[2],now[3], now[2] + 1,now[3] + 1 }); + count[now[2] + 1][now[3] + 1] ++; + } + } + } + cout << count[N - 1][N - 1] << endl; + return 0; +} From 35b92461f037e82aecae3139da552d9e33b33c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Fri, 12 Aug 2022 15:35:30 +0900 Subject: [PATCH 149/822] solve --- ...354\230\256\352\270\260\352\270\2601.java" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" diff --git "a/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" "b/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" new file mode 100644 index 0000000..b759354 --- /dev/null +++ "b/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" @@ -0,0 +1,62 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int[][] house = new int[17][17]; + static int N; + static int count = 0; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + house[i][j] = Integer.parseInt(token.nextToken()); + } + } + + + dfs(2, 1, 1); + + System.out.println(count); + + } + + static void dfs(int col, int row, int direction) { + if (col == N && row == N) { + count++; + return; + } + + switch (direction) { // 방향 + case 1: + if (col + 1 <= N && house[row][col + 1] == 0) { // 가로 + dfs(col + 1, row, 1); + } + break; + case 2: + if (row + 1 <= N && house[row + 1][col] == 0) {// 세로 + dfs(col, row + 1, 2); + } + break; + case 3: + if (row + 1 <= N && house[row + 1][col] == 0) {// 세로 + dfs(col, row + 1, 2); + } + if (col + 1 <= N && house[row][col + 1] == 0) {// 가로 + dfs(col + 1, row, 1); + } + break; + } + + // 대각선 + if (row + 1 <= N && col + 1 <= N && house[row][col + 1] == 0 && house[row + 1][col] == 0 + && house[row + 1][col + 1] == 0) { + dfs(col + 1, row + 1, 3); + } + } +} From 3d677f6ceb04219061669be2156bcc5a5f7dda0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sat, 13 Aug 2022 11:13:14 +0900 Subject: [PATCH 150/822] 100.0/100.0 --- .../1.java" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/1.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/1.java" new file mode 100644 index 0000000..a10d715 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/1.java" @@ -0,0 +1,19 @@ +class Solution { + + public int solution(int[] number) { + int answer = 0; + + for(int i = 0; i Date: Sat, 13 Aug 2022 11:13:36 +0900 Subject: [PATCH 151/822] 0.0/100 --- .../2.java" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/2.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/2.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/2.java" new file mode 100644 index 0000000..a4fe106 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/2.java" @@ -0,0 +1,67 @@ +import java.util.*; + +class Solution { + + static int answer = 0; + static int me[] = new int [5]; + static int bro[] = new int[5]; + static int me_int = 0; + static int bro_int = 0; + static int topping[]; + static boolean visited[]; + + public int solution(int[] top) { + topping = top; + visited = new boolean [top.length+1]; + binary_search(topping.length/2, topping.length); + + return answer; + } + + void binary_search(int start, int end){ // i의 시작과 끝을 받는다. 내 토핑 + // 종료 조건 + if (1 > start || start >= end){ + return; + } + + // 값 초기화 + Arrays.fill(me, 0); + Arrays.fill(bro, 0); + me_int = 0; + bro_int = 0; + + + // 토핑 담기 + for(int j=0; j Date: Sat, 13 Aug 2022 11:13:55 +0900 Subject: [PATCH 152/822] 93.8/100 --- .../3.java" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" new file mode 100644 index 0000000..a706e91 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" @@ -0,0 +1,63 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; + + +class Solution { + + static ArrayList> map = new ArrayList<>(); + static boolean visited[]; + static int[] answer = {}; + + public int[] solution(int N, int[][] roads, int[] sources, int dest) { + visited = new boolean[N+1]; + answer = new int [sources.length]; + for(int i=0; i<=N; i++){ + map.add(new ArrayList<>()); + } + // roads -> map 값 이동 + for(int i=0; i q= new LinkedList<>(); + visited[now]= true; + q.add(new P(now, 0)); + + while(!q.isEmpty()) { + P poll = q.poll(); + if (poll.now == dest) { + return poll.val; + } + for(int i=0; i Date: Sat, 13 Aug 2022 11:17:05 +0900 Subject: [PATCH 153/822] 100.0/100 --- .../\355\231\251\354\247\200\354\233\220/3.java" | 1 + 1 file changed, 1 insertion(+) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" index a706e91..2dabb1b 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" @@ -61,3 +61,4 @@ class P{ this.val = val; } } + From 71ae9dea2fed5e6b29c31ab061baadae3c8b3401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 13 Aug 2022 14:51:11 +0900 Subject: [PATCH 154/822] =?UTF-8?q?Create=201=EB=B2=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1\353\262\210.cpp" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" new file mode 100644 index 0000000..f97be5c --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" @@ -0,0 +1,19 @@ +#include +#include + +using namespace std; + +int solution(vector number) { + int answer = 0; + int N = number.size(); + for(int i = 0;i Date: Sat, 13 Aug 2022 14:56:31 +0900 Subject: [PATCH 155/822] =?UTF-8?q?Create=202=EB=B2=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2\353\262\210.cpp" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" new file mode 100644 index 0000000..015132b --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" @@ -0,0 +1,26 @@ +#include +#include +#include + +using namespace std; + +int solution(vector topping) { + int answer = 0; + map total; + for(int n : topping){ + total[n]++; + } + map right; + for(int n : topping){ + total[n]--; + right[n]++; + if(total[n] == 0){ + total.erase(n); + } + if(total.size() == right.size()){ + answer++; + } + } + + return answer; +} From 16dbe012b6084ad7ea57df94b011365f1add72e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 13 Aug 2022 15:05:47 +0900 Subject: [PATCH 156/822] =?UTF-8?q?Create=203=EB=B2=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3\353\262\210.cpp" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3\353\262\210.cpp" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3\353\262\210.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3\353\262\210.cpp" new file mode 100644 index 0000000..cd31eb9 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3\353\262\210.cpp" @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +vector solution(int n, vector> roads, vector sources, int destination) { + vector answer; + vector> connect(n + 1); + for (auto r : roads) { + connect[r[0]].push_back(r[1]); + connect[r[1]].push_back(r[0]); + } + vector distance(n + 1, -1); + queue> q; //위치, 거리 + q.push({ destination,0 }); + distance[destination] = 0; + while (!q.empty()) { + vector now = q.front(); q.pop(); + for (int n : connect[now[0]]) { + if (distance[n] < 0) { + q.push({ n,now[1] + 1 }); + distance[n] = now[1] + 1; + } + } + } + for (int s : sources) { + answer.push_back(distance[s]); + } + + return answer; +} From a5e4582b19d6c5b323d4f0547132d8474e4fa07c Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Sat, 13 Aug 2022 17:08:20 +0900 Subject: [PATCH 157/822] =?UTF-8?q?Create=20=ED=86=A0=ED=95=91=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\221\353\254\270\354\240\234.java" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" new file mode 100644 index 0000000..a640815 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" @@ -0,0 +1,74 @@ +import java.util.*; +class Solution { + static int leng; + static int answer =0; + public int solution(int[] topping) { + leng=topping.length; + if(leng==1){ + return 0; + } + int[] arr=new int[topping.length]; + System.arraycopy(topping,0,arr,0,topping.length ); + int top_num=count(arr); //토핑 개수 + + for(int i=0;i=top_num/2&&leng-i>=top_num/2){ + System.out.println("if문 안 "+i); + sol(i,topping,top_num); //cut 하는 위치 매개변수로 + } + } + } + return answer; + } + public static void sol(int cut,int[] topping,int top_num){ + HashMap hash=new HashMap<>(); + HashMap hash2=new HashMap<>(); + int cnt=0; + int cnt2=0; + + for(int i=0;i Date: Sat, 13 Aug 2022 17:09:44 +0900 Subject: [PATCH 158/822] =?UTF-8?q?Create=200=EB=A7=8C=EB=93=9C=EB=8A=94?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\212\224\353\254\270\354\240\234.java" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/0\353\247\214\353\223\234\353\212\224\353\254\270\354\240\234.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/0\353\247\214\353\223\234\353\212\224\353\254\270\354\240\234.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/0\353\247\214\353\223\234\353\212\224\353\254\270\354\240\234.java" new file mode 100644 index 0000000..b4f6f5b --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/0\353\247\214\353\223\234\353\212\224\353\254\270\354\240\234.java" @@ -0,0 +1,33 @@ +class Solution { + static int cnt =0; + static int answer=0; + static int leng; + public int solution(int[] number) { + + leng=number.length; + sol(0,number,0,0); + return answer; + } + public static void sol(int sum, int[] num,int start,int cnt) { + + if(cnt==3&&sum==0){ + answer++; + System.out.println("answer"); + return; + } + else if(cnt==3){ + System.out.println("else if"); + + return; + } + + for(int i=start;i Date: Sat, 13 Aug 2022 17:17:02 +0900 Subject: [PATCH 159/822] =?UTF-8?q?Create=20=ED=83=90=EC=83=89=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\203\211\353\254\270\354\240\234.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\203\220\354\203\211\353\254\270\354\240\234.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\203\220\354\203\211\353\254\270\354\240\234.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\203\220\354\203\211\353\254\270\354\240\234.java" new file mode 100644 index 0000000..c7a066f --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\203\220\354\203\211\353\254\270\354\240\234.java" @@ -0,0 +1,49 @@ +import java.util.*; + +class Solution { + static ArrayList> list; + public int[] solution(int n, int[][] roads, int[] sources, int destination) { + //source : 시작점 + // destination : 도착점 + int[] answer = new int[sources.length]; + list=new ArrayList<>(); + for(int i=0;i()); + } + for(int i=0;i q=new LinkedList<>(); + q.offer(start); + while(!q.isEmpty()){ + int now=q.poll(); + + for(int i:list.get(now)){ + if(visited[i]==0){ + if(i==des){ + return visited[now]+1; + } + else { + visited[i]=visited[now]+1; + q.offer(i); + } + } + } + + } + return -1; + + } +} From fd11cbc1f92c64b0d9419f4887c964f563c8c6d8 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Sat, 13 Aug 2022 17:17:34 +0900 Subject: [PATCH 160/822] =?UTF-8?q?=EC=95=88=EB=90=98=EB=8A=94=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=9E=85=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\206\240\355\225\221\353\254\270\354\240\234.java" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" index a640815..bb1c5f7 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/\355\206\240\355\225\221\353\254\270\354\240\234.java" @@ -1,3 +1,5 @@ +//안되는 코드~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + import java.util.*; class Solution { static int leng; From 1e22fbcd03fdefb99479263037bd59cf2fbc312c Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Sat, 13 Aug 2022 17:21:22 +0900 Subject: [PATCH 161/822] =?UTF-8?q?=EB=AA=A8=EC=9D=98=EA=B3=A0=EC=82=AC=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1: 100/100 2: 30/100 3: ㅠㅠ --- ...\202\254 2\355\232\214\354\260\250]no1.py" | 7 ++++ ...\202\254 2\355\232\214\354\260\250]no2.py" | 32 +++++++++++++++++ ...\202\254 2\355\232\214\354\260\250]no3.py" | 35 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220813_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no1.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no2.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no3.py" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220813_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no1.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220813_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no1.py" new file mode 100644 index 0000000..f886cd0 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220813_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no1.py" @@ -0,0 +1,7 @@ +from itertools import combinations + +def solution(number): + answer = 0 + for three_students in combinations(number, 3): + if sum(three_students) == 0 : answer+=1 + return answer \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no2.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no2.py" new file mode 100644 index 0000000..edbbdc0 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no2.py" @@ -0,0 +1,32 @@ +def count_not_zero(_arr) -> int: + count = 0 + for e in _arr: + if e>0: count +=1 + return count + +def check_available(_arr_a, _arr_b) -> bool: + val_exist_a = count_not_zero(_arr_a) + val_exist_b = count_not_zero(_arr_a) + if val_exist_a == val_exist_b : return True + return False + +def make_counting_arr(_topping, _max_val) -> list: + arr = [0]*(_max_val+1) # 또는 10,000 + for element in _topping: + arr[element] += 1 + return arr + +def solution(topping : list): + answer, max_val = 0, max(topping) + count_a, count_b = [0]*(max_val+1), make_counting_arr(topping, max_val) + cake_a, cake_b = [], topping + for i in range(len(topping)-1): + moving_element = cake_b.pop() + cake_a.append(moving_element) + count_a[moving_element] += 1 + count_b[moving_element] -= 1 + if check_available(count_a, count_b) : answer += 1 + return answer + + +print(solution([1,2,1,3,1,4,1,2])) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no3.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no3.py" new file mode 100644 index 0000000..e8b85e7 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220814_\353\252\250\354\235\230\352\263\240\354\202\254 2\355\232\214\354\260\250]no3.py" @@ -0,0 +1,35 @@ + +def dfs(_count, _node, _finish_node, _arr, _n) -> int: + min_answer, stack = 100000, [] + if _arr[_node][0] <= 0 : return -1 + stack.append(_node) + count = 0 + while stack: + present_node = stack.pop() + if present_node == _finish_node : + min_answer = min(min_answer, count) + count = 0 + for next_index in range(1, len(_arr[_node])): + if _arr[_node][next_index] > 0 : + stack.append(next_index) + _arr[_node][0] -= 1 + _arr[_node][next_index] = 0 + count +=1 + return -1 if min_answer==100000 else min_answer + + +def make_linked_matrix(_n, _arr) -> list: + arr = [[0] for _ in range(_n+1)] + for elements in _arr: + e1, e2 = elements[0], elements[1] + arr[e1][0], arr[e2][0] = arr[e1][0]+1, arr[e2][0]+1 + arr[e1].append(e2) + arr[e2].append(e1) + return arr + +def solution(n, roads, sources, destination): + answer = [] + arr = make_linked_matrix(n, roads) + for vertex in sources: + answer.append(dfs(0, vertex, destination, arr, n)) + return answer \ No newline at end of file From 14dd7a3ea53c1eaffc2c53b19a2ebce3ddc71217 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 13 Aug 2022 18:09:07 +0900 Subject: [PATCH 162/822] kihun --- .../1\353\262\210.py" | 10 ++++ .../2\353\262\210.py" | 44 ++++++++++++++ .../3\353\262\210.py" | 58 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" new file mode 100644 index 0000000..2eec258 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" @@ -0,0 +1,10 @@ +def solution(number): + answer = 0 + for a in range(len(number) - 2): + for b in range(a + 1, len(number) - 1): + for c in range(b + 1, len(number)): + temp = number[a] + number[b] + number[c] + if temp == 0: + answer += 1 + + return answer diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" new file mode 100644 index 0000000..e3a3f5e --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" @@ -0,0 +1,44 @@ +# 10점 +# def solution(topping): +# answer = 0 + +# for i in range(len(topping)): +# a = topping[:i] +# b = topping[i:] + +# setA = set(a) +# setB = set(b) + +# if len(setA) == len(setB): +# answer += 1 + +# return answer + + +def solution(topping): + answer = 0 + + a = dict() + b = dict() + + for t in topping: + if t not in b: + b[t] = 1 + else: + b[t] += 1 + + for i in range(len(topping)): + temp = topping[i] + b[temp] -= 1 + + if temp not in a: + a[temp] = 1 + else: + a[temp] += 1 + + if b[temp] == 0: + del b[temp] + if len(a) == len(b): + answer += 1 + + return answer diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" new file mode 100644 index 0000000..dfd5435 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" @@ -0,0 +1,58 @@ +# 18.8점 +# import sys + +# sys.setrecursionlimit(10**9) + +# def solution(n, roads, sources, destination): +# answer = [] +# matrix = [[] for _ in range(n + 1)] + +# for r in roads: +# a = r[0] +# b = r[1] +# matrix[r[0]].append(b) +# matrix[r[1]].append(a) + +# def dfs(source, depth): +# if destination in matrix[source]: +# return depth +# for i in matrix[source]: +# return dfs(i, depth + 1) +# return -1 + +# for s in sources: +# if s == destination: +# answer.append(0) +# else: +# answer.append(dfs(s, 1)) + +# return answer + +from collections import deque + + +def solution(n, roads, sources, destination): + answer = [] + matrix = [[] for _ in range(n + 1)] + + for r in roads: + a = r[0] + b = r[1] + matrix[a].append(b) + matrix[b].append(a) + + q = deque() + visited = [-1 for _ in range(n + 1)] + visited[destination] = 0 + q.append((destination, 0)) + while q: + now, depth = q.popleft() + for n in matrix[now]: + if visited[n] < 0: + q.append((n, depth + 1)) + visited[n] = depth + 1 + + for s in sources: + answer.append(visited[s]) + + return answer From a6905b849a0dbaa4fbc7d995703ad31287461b70 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 13 Aug 2022 18:14:27 +0900 Subject: [PATCH 163/822] =?UTF-8?q?=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Question1.java" | 41 +++++++++ .../Question2.java" | 65 ++++++++++++++ .../Question3.java" | 87 +++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" new file mode 100644 index 0000000..5af5c54 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" @@ -0,0 +1,41 @@ +package second; + + +public class Question1 { + + public static void main(String[] args) { + int[] number = { -1, 1, -1, 1 }; + Solution s1 = new Solution(); + System.out.println(s1.solution(number)); + } + +} + +class Solution { + static int answer; + static boolean[] visited; + static int[] number; + + public int solution(int[] number) { + answer = 0; + visited = new boolean[number.length]; + permulation(number, 0, 0, 0); + return answer; + } + + public void permulation(int[] number, int start, int size, int sum) { //숫자 조합 + if (size == 3) { //3개 뽑고 합이 0이면 answer++ + if (sum == 0) { + answer++; + } + return; + } + + for (int i = start; i < number.length; i++) { //start 변수를 선언해서 그 다음 반복문 실행 시 앞에 인덱스를 점프하고 실행 + if (!visited[i]) { //visited를 통해 중복으로 선택 불가능 + permulation(number, i + 1, size + 1, sum + number[i]); + visited[i] = false; + } + } + } +} diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" new file mode 100644 index 0000000..98c46ce --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" @@ -0,0 +1,65 @@ +package second; + + +public class Question2 { + + public static void main(String[] args) { + Solution2 s2 = new Solution2(); + int[] topping = { 1, 2, 1, 3, 1, 4, 1, 2 }; + System.out.println(s2.solution(topping)); + } + +} + +class Solution2 { + public int solution(int[] topping) { + int answer = 0; + + boolean[] cChecked = new boolean[10001]; //10000종류 토핑 + int[] chulsu = new int[1000000]; //topping길이 1,000,000 + + for (int i = 0; i < topping.length; i++) { //철수영역 + if (i == 0) { + chulsu[i] = 1; + cChecked[topping[i]] = true; + } else { + if (!cChecked[topping[i]]) { + cChecked[topping[i]] = true; + chulsu[i] = chulsu[i - 1] + 1; + } else { + chulsu[i] = chulsu[i - 1]; + } + } + } + + int[] brother = new int[1000000]; + boolean[] bChecked = new boolean[10001]; + + for (int i = topping.length - 1; i >= 0; i--) { //동생영역 + if (i == topping.length - 1) { + brother[i] = 1; + bChecked[topping[i]] = true; + } else { + if (!bChecked[topping[i]]) { + bChecked[topping[i]] = true; + brother[i] = brother[i + 1] + 1; + } else { + brother[i] = brother[i + 1]; + } + } + } + + for (int i = 0; i < topping.length - 1; i++) { //값 비교 + int cCount = chulsu[i]; + int bCount = brother[i + 1]; + + + if (cCount == bCount) { + answer++; + } + + } + + return answer; + } +} \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" new file mode 100644 index 0000000..78624ce --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" @@ -0,0 +1,87 @@ +package second; + +import java.util.*; + +public class Question3 { + + public static void main(String[] args) { + Solution3 s3 = new Solution3(); + int n = 5; + int[][] roads = { { 1, 2 }, { 1, 4 }, { 2, 4 }, { 2, 5 }, { 4, 5 } }; + int[] sources = { 1, 3, 5 }; + int destination = 5; + System.out.println(Arrays.toString(s3.solution(n, roads, sources, destination))); + } + +} + +class Solution3 { + boolean[] visited; //그래프 방문 체크 + int[] answer; + LinkedList[] graph; //그래프 + + public int[] solution(int n, int[][] roads, int[] sources, int destination) { + answer = new int[sources.length]; + + graph = new LinkedList[n+1];; //인접리스트로 구현, 인접배열 사용시 메모리초과 + + for (int i = 0; i <= n; i++) { + graph[i] = new LinkedList(); + } + + for (int i = 0; i < roads.length; i++) { //양방향 + graph[roads[i][0]].add(roads[i][1]); + graph[roads[i][1]].add(roads[i][0]); + } + + for (int i = 0; i < sources.length; i++) { //visited초기화 후에 bfs시작 + visited = new boolean[n + 1]; + answer[i] = (bfs(sources[i], destination,n)); + } + + return answer; + } + + public int bfs(int source, int destination,int n) { + + int count = 0; + boolean isReturn = false; //목적지 찾으면 바로 빠져나오는 flag + + Queue queue = new LinkedList(); + queue.offer(source); //초기 위치 세팅 + visited[source] = true; + + while (!queue.isEmpty()) { + + int qSize = queue.size(); + + for (int i = 0; i < qSize; i++) { //queue사이즈 만큼 반복 + int node = queue.poll(); + + if (node == destination) { //poll값이 목적지만 return + return count; + } + + for (Integer link : graph[node]) { //graph[node]에서 목적지 찾기 + if (!visited[link]) { + + if (link == destination) { //찾으면 바로 return -> 문제의 핵심 + count++; + return count; + } + visited[link] = true; //없으면 해당요소 queue에 추가 + queue.add(link); + } + } + } + count++; + + } + + if (!isReturn) { //찾지 못하면 -1 return + count = -1; + } + return count; + } + +} \ No newline at end of file From 74047291d31edbfe53a5a1397b00fd25fdf0dba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:24:51 +0900 Subject: [PATCH 164/822] =?UTF-8?q?100%=20100=EC=A0=90!!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\231\251\354\247\200\354\233\220/3.java" | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" index 2dabb1b..e15c919 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\355\231\251\354\247\200\354\233\220/3.java" @@ -3,7 +3,6 @@ import java.util.LinkedList; import java.util.Queue; - class Solution { static ArrayList> map = new ArrayList<>(); @@ -39,12 +38,16 @@ static int BFS(int now, int dest) { while(!q.isEmpty()) { P poll = q.poll(); - if (poll.now == dest) { + if (poll.now == dest) { return poll.val; } - for(int i=0; i Date: Sat, 13 Aug 2022 19:04:16 +0900 Subject: [PATCH 165/822] =?UTF-8?q?=EC=A0=80=EB=8A=94=20=EB=B0=94=EB=B3=B4?= =?UTF-8?q?=EC=9E=85=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Solution1.java" | 42 +++++++++ .../Solution2.java" | 71 ++++++++++++++ .../Solution3.java" | 92 +++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" new file mode 100644 index 0000000..521de4d --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" @@ -0,0 +1,42 @@ +public class Solution1 { + static int ans[] = new int[3]; + static int numArr[]; + static int N; + static int resultCount = 0; + + public static void main(String[] args) { + Solution1 s = new Solution1(); + + int number[] = {-3, -2, -1, 0, 1, 2, 3 }; + System.out.println(s.solution(number)); + } // End of main + + public int solution(int[] number) { + N = number.length; + numArr = number; + + DFS(0, 0); + return resultCount; + } // End of solution + + private static void DFS(int idx, int depth) { + if(depth == 3) { + int sum = 0; + for(int i=0; i<3; i++) { + sum += ans[i]; + } + + if(sum == 0) { + resultCount++; + } + + return; + } + + + for(int i=idx; i checkMap = new HashMap<>(); + public static void main(String[] args) { + Solution2 s = new Solution2(); + + int topping[] = { 1, 2, 1, 3, 1, 4, 1, 2 }; + System.out.println(s.solution(topping)); + } // End of main + + public int solution(int[] topping) { + int len = topping.length; + for(int i=0; i cheolsuSet = new TreeSet<>(); + TreeSet brotherSet = new TreeSet<>(); + + for(int i=0; i<=cutting; i++) { + cheolsuSet.add(topping[i]); + } + + for(int i=cutting+1; i> it = checkMap.entrySet().iterator(); + while(it.hasNext()) { + Entry entrySet = (Entry)it.next(); + int value = entrySet.getValue(); + + if(value % 2 == 1) { + oddNum++; + } + } + + if(oddNum % 2 == 1) { + return false; + } + + return true; + } // End of checking +} // End of Main class \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" new file mode 100644 index 0000000..46cce37 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" @@ -0,0 +1,92 @@ +import java.util.*; + +public class Solution3 { + static List> roadList; + static Integer dist[]; + static Integer dist2[]; + static int N; + + static class Road implements Comparable { + int roadNum; + int time; + + public Road(int roadNum, int time) { + this.roadNum = roadNum; + this.time = time; + } + + @Override + public int compareTo(Road o) { + return time - o.time; + } + } // End of Road + + public static void main(String[] args) { + Solution3 s = new Solution3(); + + int n = 5; + int roads[][] = { { 1, 2 }, { 1, 4 }, { 2, 4 }, { 2, 5 }, { 4, 5 } }; + int sources[] = { 1, 3, 5 }; + int destination = 5; + System.out.println(Arrays.toString(s.solution(n, roads, sources, destination))); + } // End of main + + public int[] solution(int n, int[][] roads, int[] sources, int destination) { + int answer[] = new int[sources.length]; + N = n; + roadList = new ArrayList<>(); + for (int i = 0; i <= N; i++) { + roadList.add(new ArrayList<>()); + } + + int len = roads.length; + for (int i = 0; i < len; i++) { + int parent = roads[i][0]; + int son = roads[i][1]; + + roadList.get(parent).add(new Road(son, 1)); + roadList.get(son).add(new Road(parent, 1)); + } + + // sources배열에서 destination까지 갈 수 있는 최단 거리 구하기 (다익스트라) + int j = 0; + for (int num : sources) { + + dist = new Integer[N + 1]; + answer[j] = dijkstra(num, destination); + j++; + } + + return answer; + } // End of solution + + private static int dijkstra(int startNum, int destination) { + PriorityQueue pque = new PriorityQueue(); + boolean visit[] = new boolean[N + 1]; + dist[startNum] = 0; + pque.offer(new Road(startNum, 0)); + + while (!pque.isEmpty()) { + Road r = pque.poll(); + int rnum = r.roadNum; + + if(rnum == destination) break; + if (!visit[rnum]) { + visit[rnum] = true; + + for (Road road : roadList.get(rnum)) { + if (!visit[road.roadNum] && dist[road.roadNum] == null + || (dist[road.roadNum] > (dist[rnum] + road.time))) { + dist[road.roadNum] = (dist[r.roadNum] + road.time); + pque.offer(new Road(road.roadNum, dist[road.roadNum])); + } + } + } + } + + if (dist[destination] == null) + return -1; + + return dist[destination]; + } // End of dijkstra +} // End of Solution class \ No newline at end of file From 221032497298f6ef487068ea40c886ec262f4222 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 13 Aug 2022 22:15:02 +0900 Subject: [PATCH 166/822] complete --- .../Solution1.java" | 74 +++++++++++++++++++ .../Solution2.java" | 56 ++++++++++++++ .../Solution3.java" | 72 ++++++++++++++++++ .../Solution4.java" | 21 ++++++ 4 files changed, 223 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution2.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution4.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" new file mode 100644 index 0000000..7e35810 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" @@ -0,0 +1,74 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +public class Solution1 { + public static void main(String[] args) { + Solution1 t = new Solution1(); + String x = "1000"; + String y = "2345"; + + System.out.println(t.solution(x, y)); + }// End of main + + public String solution(String X, String Y) { + char c1[] = X.toCharArray(); + char c2[] = Y.toCharArray(); + StringBuilder sb = new StringBuilder(); + + HashMap map1 = new HashMap(); + HashMap map2 = new HashMap(); + List resultList = new ArrayList<>(); + + int len1 = c1.length; + for(int i=0; i> it = map1.entrySet().iterator(); + while(it.hasNext()) { + Entry entrySet = (Entry)it.next(); + char key = entrySet.getKey(); + long value = entrySet.getValue(); + + if( map2.containsKey(key) ) { + + // 만약 겹치는 수가 있다. + // 그 키에 해당하는 value를 찾아서 갯수를 비교하고 작은 쪽을 list에 삽입 + long value2 = map2.get(key); + long min = Math.min(value, value2); + for(int i=0; i wantMap = new HashMap<>(); + int total = 0; + for(int i=0; i discountMap = new HashMap<>(); + for(int j=i; j> it = wantMap.entrySet().iterator(); + int sum = 0; + while(it.hasNext()) { + Entry entrySet = (Entry)it.next(); + String key = entrySet.getKey(); + int value = entrySet.getValue(); + + //key에 해당하는 값과 한번이라도 다를 경우, + if(discountMap.containsKey(key)) { + if(discountMap.get(key) != value ) { + break; + } + else sum += discountMap.get(key); + } + } + + + if(sum == total) { + result++; + } + } + + return result; + } // End of solution +} // End of Test2 class \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" new file mode 100644 index 0000000..d51d39d --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" @@ -0,0 +1,72 @@ +import java.util.LinkedList; +import java.util.Stack; + +class Solution3 { + public static void main(String[] args) { + Solution3 s = new Solution3(); + + int order[] = { 4, 3, 1, 2, 5 }; + System.out.println(s.solution(order)); + } // End of main + + public int solution(int[] order) { + // 보조컨테이너 벨트 -> 스택구조 + + // 1, 2, 3, 4, 5로 된 택배를 + // 4, 3, 1, 2, 5로 만들어라 가능한 갯수 + // 불가능할 경우, -1을 출력 + int len = order.length; + LinkedList list = new LinkedList<>(); + for (int i = 0; i < len; i++) { + list.add(i + 1); + } + + // target값과 list값을 확인 + // 같을 경우, result++ + // 다를 경우, stack확인 + + // 만약 stack이 비어있다. 바로 중지 + + // 컨베이어 벨트에서 나올 수 있는 값과 + // 다음 택배 번호가 다르다 + + int result = 0; + Stack stack = new Stack<>(); + for (int i = 0; i < len; i++) { + int target = order[i]; + + for(int j=0; j Date: Sat, 13 Aug 2022 22:16:08 +0900 Subject: [PATCH 167/822] complete --- .../\354\265\234\354\260\275\354\230\201/Solution1.java" | 0 .../\354\265\234\354\260\275\354\230\201/Solution2.java" | 0 .../\354\265\234\354\260\275\354\230\201/Solution3.java" | 0 .../\354\265\234\354\260\275\354\230\201/Solution4.java" | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" => "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" (100%) rename "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution2.java" => "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" (100%) rename "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" => "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" (100%) rename "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution4.java" => "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution4.java" (100%) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" similarity index 100% rename from "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution1.java" rename to "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution2.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" similarity index 100% rename from "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution2.java" rename to "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" similarity index 100% rename from "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution3.java" rename to "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution3.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution4.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution4.java" similarity index 100% rename from "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/Solution4.java" rename to "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/1\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution4.java" From b5824ecd49619045af6be882c5c99c47ed7f87ee Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 14 Aug 2022 03:32:41 +0900 Subject: [PATCH 168/822] complete --- ...353\263\270_\354\240\225\353\213\265.java" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" new file mode 100644 index 0000000..61445d4 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" @@ -0,0 +1,50 @@ + +// HashSet => 테스트 1 〉 통과 (1788.48ms, 395MB) +// TreeSet => 테스트 1 〉 통과 (9572.95ms, 402MB) + +// HashSet O(1) +// TreeSet O(logn) +// 성능은 HashSet이 더 좋음 +// 여기서는 Set을 쓰면 시간 초과 + +public class Solution2 { + public static void main(String[] args) { + Solution2 s = new Solution2(); + + int topping[] = { 1, 2, 1, 3, 1, 4, 1, 2 }; + System.out.println(s.solution(topping)); + } // End of main + + public int solution(int[] topping) { + int len = topping.length; + int result = 0; + int cheolsuArr[] = new int[len+1]; + int brotherArr[] = new int[len+1]; + + int cheolsuCount = 0; + int brotherCount = 0; + for (int i = 0; i < len; i++) { + if(cheolsuArr[topping[i]] == 0) { + cheolsuCount++; + } + cheolsuArr[topping[i]]++; + } + + + for(int i=0; i Date: Sun, 14 Aug 2022 12:19:52 +0900 Subject: [PATCH 169/822] complete --- ...olution2_Set\354\202\254\354\232\251.java" | 49 +++++++++++++++++++ ...\354\227\264\354\202\254\354\232\251.java" | 0 2 files changed, 49 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" rename "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" => "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\353\260\260\354\227\264\354\202\254\354\232\251.java" (100%) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" new file mode 100644 index 0000000..fd681e0 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" @@ -0,0 +1,49 @@ +import java.util.HashSet; + +// HashSet => 테스트 1 〉 통과 (1788.48ms, 395MB) +// TreeSet => 테스트 1 〉 통과 (9572.95ms, 402MB) + +// HashSet O(1) +// TreeSet O(logn) +// 성능은 HashSet이 더 좋음 +// 여기서는 Set을 쓰면 시간 초과 + +public class Solution2 { + public static void main(String[] args) { + Solution2 s = new Solution2(); + + int topping[] = { 1, 2, 1, 3, 1, 4, 1, 2 }; + System.out.println(s.solution(topping)); + } // End of main + + public int solution(int[] topping) { + int len = topping.length; + int result = 0; + int cheolsuArr[] = new int[len + 1]; + int brotherArr[] = new int[len + 1]; + + HashSet cheolsuSet = new HashSet<>(); + HashSet brotherSet = new HashSet<>(); + + for (int i = 0; i < len; i++) { + cheolsuSet.add(topping[i]); + cheolsuArr[topping[i]]++; + } + + for (int i = 0; i < len; i++) { + brotherSet.add(topping[i]); + + brotherArr[topping[i]]++; + cheolsuArr[topping[i]]--; + + if (cheolsuArr[topping[i]] == 0) { + cheolsuSet.remove(topping[i]); + } + + if (cheolsuSet.size() == brotherSet.size()) + result++; + } + + return result; + } // End of solution +} // End of Main class \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\353\260\260\354\227\264\354\202\254\354\232\251.java" similarity index 100% rename from "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\354\210\230\354\240\225\353\263\270_\354\240\225\353\213\265.java" rename to "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_\353\260\260\354\227\264\354\202\254\354\232\251.java" From 6bbd52f03346f595834774de4acabf0090babcd5 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 14 Aug 2022 12:38:17 +0900 Subject: [PATCH 170/822] complete --- .../Solution2_Set\354\202\254\354\232\251.java" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" index fd681e0..cce4966 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/2\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2_Set\354\202\254\354\232\251.java" @@ -6,11 +6,11 @@ // HashSet O(1) // TreeSet O(logn) // 성능은 HashSet이 더 좋음 -// 여기서는 Set을 쓰면 시간 초과 +// 여기서는 Set을 쓰면 시간 초과 (인줄 알았으나 그냥 로직이 문제였음) -public class Solution2 { +public class Solution2_Set사용 { public static void main(String[] args) { - Solution2 s = new Solution2(); + Solution2_Set사용 s = new Solution2_Set사용(); int topping[] = { 1, 2, 1, 3, 1, 4, 1, 2 }; System.out.println(s.solution(topping)); From 6fd4285de4ff2d3d739f98482bab5ba307c6b932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 14 Aug 2022 16:14:57 +0900 Subject: [PATCH 171/822] Create readme.md --- 08.18/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 08.18/readme.md diff --git a/08.18/readme.md b/08.18/readme.md new file mode 100644 index 0000000..cf2b3b1 --- /dev/null +++ b/08.18/readme.md @@ -0,0 +1,7 @@ +#08.18(목) + +17136 색종이 붙이기 +https://www.acmicpc.net/problem/17136 + +17281 야구공 +https://www.acmicpc.net/problem/17281 From 26e3de88bdeb17968fa30991fd3b32fd66744978 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 15 Aug 2022 14:18:49 +0900 Subject: [PATCH 172/822] =?UTF-8?q?=ED=8C=8C=EC=9D=B4=ED=94=84=20=EC=98=AE?= =?UTF-8?q?=EA=B8=B0=EA=B8=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dfs_recursive --- ... \354\230\256\352\270\260\352\270\2601.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" diff --git "a/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" "b/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" new file mode 100644 index 0000000..98eb302 --- /dev/null +++ "b/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" @@ -0,0 +1,23 @@ +def dfs(_x, _y, _shape): + global answer + if _x==n and _y==n: + answer+=1 + return + if _shape==0 or _shape==2: # 가로 모양으로 회전 + if _x+1<=n and arr[_y][_x+1]==0: dfs(_x+1, _y, 0) + if _shape==1 or _shape==2: # 세로 모양으로 회전 + if _y+1<=n and arr[_y+1][_x]==0: dfs(_x, _y+1, 1) + # 대각선 모양으로 회전 + if _x+1<=n and _y+1<=n and arr[_y][_x+1] == 0 and arr[_y+1][_x]==0 and arr[_y+1][_x+1]==0: + dfs(_x+1, _y+1, 2) + +n = int(input()) +arr = [[0]*(n+1)] +for row in range(n): # arr = [list(map(int, input().split())) for _ in range(n)] + temp_arr = [0] + temp_arr += list(map(int, input().split())) + arr.append(temp_arr) + +answer = 0 +dfs(2, 1, 0) +print(answer) \ No newline at end of file From 8b3bc7fac6048723b5225dba58b0e4038d35316a Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 15 Aug 2022 15:09:09 +0900 Subject: [PATCH 173/822] solve --- ...\353\224\224\355\216\234\354\212\244.java" | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 "08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" diff --git "a/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" "b/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" new file mode 100644 index 0000000..2673fb3 --- /dev/null +++ "b/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" @@ -0,0 +1,122 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int M; + static int D; + static int[] archers = new int[3]; + static boolean[][] visited; + static int max = Integer.MIN_VALUE; + static int[][] castle; + static int[][] temp; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + D = Integer.parseInt(token.nextToken()); + + castle = new int[N + 1][M + 1]; + temp = new int[N + 1][M + 1]; // 복사 배열 + + for (int i = 1; i <= N; i++) { + token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= M; j++) { + castle[i][j] = Integer.parseInt(token.nextToken()); + temp[i][j] = castle[i][j]; + } + } + + archers = new int[3]; + + combination(0, 1, archers, castle); + + System.out.println(max); + + } + + static void combination(int size, int start, int[] archers, int[][] castle) { // 궁수 자리 배치 + + if (size == 3) { + copy(); // 배열 초기화 + max = Math.max(max, defense(archers)); + return; + } + + for (int i = start; i <= M; i++) { + archers[size] = i; + combination(size + 1, i + 1, archers, castle); + } + } + + static int defense(int[] archers) { + int count = 0; + for (int n = 1; n <= N; n++) { // 총 N번 이동 + visited = new boolean[N + 1][M + 1]; + for (int k = 0; k < archers.length; k++) { + + int archerX = archers[k]; // 궁수의 x좌표 + int minD = Integer.MAX_VALUE; + int minR = Integer.MAX_VALUE; + int minC = Integer.MAX_VALUE; + + for (int i = 1; i <= N; i++) { // 시작점부터 1인곳을 탐색 + for (int j = 1; j <= M; j++) { + if (castle[i][j] == 1) { + int distance = Math.abs(i - (N + 1)) + Math.abs(j - archerX); // 거리계산 + if (minD >= distance) { + if (minD > distance) { // 최소거리보다 작으면 거리,x,y갱신 + minD = distance; + minR = i; + minC = j; + } else { + if (minC > j) { // 거리같으면 왼쪽부터 쏜다고했으니 왼쪽 좌표 갱신 + minR = i; + minC = j; + } + } + } + } + } + } + + if (minD <= D) { // 거리가 가장 최소이고 같으면 왼쪽인 좌표를 방문 + visited[minR][minC] = true; + } + } + + for (int i = 1; i <= N; i++) { // 궁수가 같은 적을 쏠수도 있기때문에 체크배열을 통해 count갱신 + for (int j = 1; j <= M; j++) { + if (visited[i][j]) { + castle[i][j] = 0; + count++; + } + } + } + + for (int i = 1; i <= M; i++) { // 적이 성에 도착 + castle[N][i] = 0; + } + + for (int i = N; i >= 1; i--) { // 윗줄 적을 아래로 1칸씩 + for (int j = 1; j <= M; j++) { + castle[i][j] = castle[i - 1][j]; + } + } + + } + return count; + } + + static void copy() { + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= M; j++) { + castle[i][j] = temp[i][j]; + } + } + } +} From 5e80d2c5ac36c1aa610a4083e1f985d28ef54a81 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 15 Aug 2022 15:56:50 +0900 Subject: [PATCH 174/822] kihun --- ...24\352\260\200\355\225\230\352\270\260.py" | 47 ++++++++++++++ ...4\354\230\256\352\270\260\352\270\2601.py" | 46 ++++++++++++++ ...54\353\224\224\355\216\234\354\212\244.py" | 63 +++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" create mode 100644 "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" create mode 100644 "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" diff --git "a/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" "b/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" new file mode 100644 index 0000000..82db939 --- /dev/null +++ "b/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" @@ -0,0 +1,47 @@ +import sys +from collections import deque + +sys.stdin = open("./input.txt", "r", encoding="utf-8") +input = sys.stdin.readline + +n = int(input()) +arr = input().rstrip() + + +def cal(a, b, op): + if op == "+": + return int(a) + int(b) + elif op == "-": + return int(a) - int(b) + return int(a) * int(b) + + +def calArr(arr): + result = arr[0] + for i in range(0, len(arr) - 2, 2): + b = arr[i + 2] + result = cal(result, b, arr[i + 1]) + return result + + +def dfs(index, nowArr): + # 마지막 수 일때는 순차 계산 + if index == n - 1: + temp = nowArr + [arr[index]] + return calArr(temp) + # 괄호 치기 + if index == n - 3: + # 괄호 없을 때, 기존식 + [ 숫자 + 연산자 ] + noBracket = nowArr + [arr[index], arr[index + 1]] + # 괄호 있을 때 + # 기존식 + [ a[i] + a[i+1] + a[i+2] , a[i+3] ] + temp = cal(arr[index], arr[index + 2], arr[index + 1]) + bracket = nowArr + [temp] + return max(dfs(index + 2, noBracket), calArr(bracket)) + noBracket = nowArr + [arr[index], arr[index + 1]] + temp = cal(arr[index], arr[index + 2], arr[index + 1]) + bracket = nowArr + [temp, arr[index + 3]] + return max(dfs(index + 2, noBracket), dfs(index + 4, bracket)) + + +print(dfs(0, [])) diff --git "a/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" "b/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" new file mode 100644 index 0000000..8675adc --- /dev/null +++ "b/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" @@ -0,0 +1,46 @@ +# pypy로 제출 +import sys + +sys.stdin = open("./input.txt", "r", encoding="utf-8") +input = sys.stdin.readline +n = int(input()) +matrix = [list(map(int, input().split())) for _ in range(n)] + + +def dfs(x, y, status): + global count + + if matrix[y][x] == 0 and y == n - 1 and x == n - 1: + count += 1 + # return 들어가면 시간초과 + + if status == 0 or status == 2: + nY = y + nX = x + 1 + if 0 <= nY < n and 0 <= nX < n and matrix[nY][nX] == 0: + dfs(nX, nY, 0) + if status == 1 or status == 2: + nY = y + 1 + nX = x + if 0 <= nY < n and 0 <= nX < n and matrix[nY][nX] == 0: + dfs(nX, nY, 1) + + nY = y + 1 + nX = x + 1 + if ( + 0 <= nY < n + and 0 <= nX < n + and matrix[nY][nX] == 0 + and matrix[nY][x] == 0 + and matrix[y][nX] == 0 + ): + dfs(nX, nY, 2) + + +count = 0 +dfs(1, 0, 0) + +print(count) + +# DP 풀이법 +# https://bit.ly/3QGoKuQ diff --git "a/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" "b/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" new file mode 100644 index 0000000..8514e56 --- /dev/null +++ "b/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" @@ -0,0 +1,63 @@ +import sys +import copy +from itertools import combinations + + +sys.stdin = open("./input.txt", "r", encoding="utf-8") +input = sys.stdin.readline + +n, m, d = map(int, input().split()) +matrix = [list(map(int, input().split())) for _ in range(n)] +answer = 0 + +archer = [i for i in range(m)] +archerPos = tuple(combinations(archer, 3)) + +# 사거리가 긴 경우 끝까지 탐색 +distance = -1 +# 보통의 사거리 +if d <= n: + distance = n - 1 - d + + +# (0,1,2) +for position in archerPos: + kill = 0 + copyMatrix = copy.deepcopy(matrix) + for _ in range(n): + killed = [] + for p in position: + enemyInRange = d + enemyX = m + enemyY = n + for y in range(n - 1, distance, -1): + for x in range(m): + if ( + copyMatrix[y][x] == 1 + and abs(y - n) + abs(x - p) <= enemyInRange + ): + # 1. 사정거리 안 + if abs(y - n) + abs(x - p) < enemyInRange: + enemyX = x + enemyY = y + enemyInRange = abs(y - n) + abs(x - p) + # 2. 사정거리 동일할 땐 제일 작은 x를 픽 + else: + if x < enemyX: + enemyX = x + enemyY = y + enemyInRange = abs(y - n) + abs(x - p) + + if enemyX != m: + killed.append((enemyY, enemyX)) + + if len(killed) > 0: + killed = list(set(killed)) + for k in killed: + copyMatrix[k[0]][k[1]] = 0 + kill += 1 + copyMatrix = [[0 for _ in range(m)]] + copyMatrix[0 : n - 1] + + answer = max(answer, kill) + +print(answer) From bdee74fb18edbc90e6b73c1642b4f01a5e4e3bca Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:25:15 +0900 Subject: [PATCH 175/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=8017070.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\20017070.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" diff --git "a/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" "b/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" new file mode 100644 index 0000000..b7a39de --- /dev/null +++ "b/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" @@ -0,0 +1,70 @@ +import java.util.Scanner; + + +public class 백준17070 { + static int n=0, cnt=0; + static int arr[][]; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + n=scan.nextInt(); + arr=new int [n+1][n+1]; + for(int i=1;i<=n;i++) { + for(int j=1;j<=n;j++) { + arr[i][j]=scan.nextInt(); + } + } + dfs(1,2,"hor"); + System.out.println(cnt); + } + public static void dfs(int x, int y, String dir) { + if(x==n&&y==n) { + cnt++; + return; + } + + if(dir.equals("hor")) { + int nx=x; + int ny=y+1; + int nx2=x+1; + int ny2=y+1; + if(nx<=n&&ny<=n&&arr[nx][ny]==0) { + dfs(nx,ny,"hor"); + + } + if(nx2<=n&&ny2<=n&&arr[x+1][y]==0&&arr[x][y+1]==0&&arr[nx2][ny2]==0) { + dfs(nx2,ny2,"dia"); + } + } + else if(dir.equals("ver")) { + int nx=x+1; + int ny=y; + int nx2=x+1; + int ny2=y+1; + if(nx<=n&&ny<=n&&arr[nx][ny]==0) { + dfs(nx,ny,"ver"); + } + if(nx2<=n&&ny2<=n&&arr[x+1][y]==0&&arr[x][y+1]==0&&arr[nx2][ny2]==0) { + dfs(nx2,ny2,"dia"); + } + } + else if(dir.equals("dia")) { + int nx=x; + int ny=y+1; + int nx2=x+1; + int ny2=y; + int nx3=x+1; + int ny3=y+1; + if(nx<=n&&ny<=n&&arr[nx][ny]==0) { + dfs(nx,ny,"hor"); + } + if(nx2<=n&&ny2<=n&&arr[nx2][ny2]==0) { + dfs(nx2,ny2,"ver"); + } + if(nx3<=n&&ny3<=n&&arr[x+1][y]==0&&arr[x][y+1]==0&&arr[nx3][ny3]==0) { + dfs(nx3,ny3,"dia"); + } + } + } + +} From f8356b745f76e8234fdedada93ea0ed27e26e4da Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Mon, 15 Aug 2022 16:54:05 +0900 Subject: [PATCH 176/822] complete --- ...354\235\200_\353\262\214\354\240\220.java" | 67 +++++++++++++++++++ ...\352\260\200\355\225\230\352\270\260.java" | 55 +++++++++++++++ ...\353\224\224\355\216\234\354\212\244.java" | 43 ++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 "08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" create mode 100644 "08.15/\354\265\234\354\260\275\354\230\201/Main_16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.java" create mode 100644 "08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" diff --git "a/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" "b/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" new file mode 100644 index 0000000..dda5acf --- /dev/null +++ "b/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" @@ -0,0 +1,67 @@ +import java.util.*; +import java.io.*; + +public class Main_16498_작은_벌점 { + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/16498.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int minPenaltyScore = (int) (2 * Math.pow(10, 9)); + + int cardHavingCount[] = new int[3]; + StringTokenizer st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + HashSet aSet = new HashSet<>(); + HashSet bSet = new HashSet<>(); + HashSet cSet = new HashSet<>(); + + cardHavingCount[0] = a; + cardHavingCount[1] = b; + cardHavingCount[2] = c; + int total = a + b + c; + int allCardArr[] = new int[total]; + + st = new StringTokenizer(br.readLine()); + for(int i=0; i numList; + static List opList; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/16637.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + numList = new ArrayList<>(); + opList = new ArrayList<>(); + + String str = br.readLine(); + for (int i = 0; i < N; i++) { + char ch = str.charAt(i); + + if (ch == '*' || ch == '+' || ch == '-') { + opList.add(ch); + } else { + numList.add(Character.getNumericValue(ch)); + } + } + + DFS(0, numList.get(0)); + System.out.println(result); + } // End of main + + private static int calc(int num1, int num2, char oper) { + if (oper == '*') { + return num1 * num2; + } else if (oper == '+') { + return num1 + num2; + } else { + return num1 - num2; + } + } // End of calc + + private static void DFS(int depth, int total) { + if (depth == opList.size()) { + result = Math.max(result, total); + return; + } + + DFS(depth + 1, calc(total, numList.get(depth + 1), opList.get(depth))); + + if(depth + 2 <= opList.size()) { + DFS(depth + 2, calc(total, calc(numList.get(depth + 1), numList.get(depth + 2), opList.get(depth + 1)), opList.get(depth) )); + } + + } // End of DFS +} // End of Main class \ No newline at end of file diff --git "a/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" "b/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" new file mode 100644 index 0000000..4f45401 --- /dev/null +++ "b/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" @@ -0,0 +1,43 @@ +import java.util.*; +import java.io.*; + +// 성을 적에게서 지키기 위해 궁수 3명을 배치하려고 한다. +// 궁수의 공격이 끝나면, 적이 이동한다. 적은 아래로 한 칸 이동하며, +// 성이 있는 칸으로 이동한 경우에는 게임에서 제외된다. 모든 적이 격자판에서 제외되면 게임이 끝난다. +public class Main_17135_캐슬디펜스 { + static int N, M, D; + static int arr[][]; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/17135.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); // 궁수의 공격 거리 제한 + + arr = new int[N][M]; + for(int i=0; i Date: Mon, 15 Aug 2022 16:54:45 +0900 Subject: [PATCH 177/822] =?UTF-8?q?Create=20=EA=B4=84=ED=98=B8=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 16637 괄호추가 --- ...4\204\355\230\270\354\266\224\352\260\200" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" diff --git "a/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" "b/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" new file mode 100644 index 0000000..73e8056 --- /dev/null +++ "b/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" @@ -0,0 +1,35 @@ +package swea; + +import java.util.Scanner; +import java.util.Stack; + +public class swea_16637_괄호추가하기 { + static char[] arr; + static int n, max; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + n = sc.nextInt(); + String input = sc.next(); + arr = input.toCharArray(); + max = Integer.MIN_VALUE; // 0 안됨 + dfs(2, Integer.parseInt(Character.toString(arr[0]))); // == -'0' + System.out.println(max); + } + static void dfs(int index, int curresult) { + if(index >= n) { + max = Math.max(curresult, max); + return; + } + dfs(index+2, cal(curresult, arr[index-1], arr[index]-'0')); // 괄호X -> 현재까지의 합과 현재 값(arr[index])를 연산(arr[index-1]) + if(index+2 < n) { + int temp = cal(arr[index] - '0', arr[index+1], arr[index+2]-'0'); + dfs(index+4, cal(curresult, arr[index-1], temp)); + } + } + static int cal(int num1, char op, int num2) { + if(op == '+') return num1 + num2; + else if(op == '*') return num1 * num2; + else return num1 - num2; + } +} From b764ab0c0f81066530e6e3924fbb126700869041 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:55:27 +0900 Subject: [PATCH 178/822] =?UTF-8?q?Create=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EC=98=AE=EA=B8=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 17070 파이프옮기기 --- ...4\204\354\230\256\352\270\260\352\270\260" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" diff --git "a/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" "b/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" new file mode 100644 index 0000000..61da095 --- /dev/null +++ "b/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" @@ -0,0 +1,54 @@ +package swea; + +import java.util.Scanner; + +public class swea_17070_파이프옮기기 { + static int cnt, n; + static int[][] arr; + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + n = sc.nextInt(); + arr = new int[n][n]; + for(int i=0; i Date: Mon, 15 Aug 2022 17:16:41 +0900 Subject: [PATCH 179/822] =?UTF-8?q?=EC=BA=90=EC=8A=AC=EB=94=94=ED=8E=9C?= =?UTF-8?q?=EC=8A=A4-=EC=88=98=EC=A0=95=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit . . . --- ...54\353\224\224\355\216\234\354\212\244.py" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" diff --git "a/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" "b/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" new file mode 100644 index 0000000..0beab2c --- /dev/null +++ "b/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" @@ -0,0 +1,59 @@ +from itertools import combinations +from collections import deque +from copy import deepcopy + +move = [(-1, 0), (0, -1), (1, 0)] # 좌, 상, 우 (왼쪽일수록 가장 우선순위 높음) + +def check_search_need(_arr) -> bool: + for row in _arr: + if 1 in row: + return True + return False + +def bfs(_distance, _x, _y, _arr) -> tuple: + start_pos = (_x, _y) + if _arr[start_pos[1]][start_pos[0]] ==1 : return start_pos + + queue = deque() + queue.append(start_pos) + while queue and check_search_need(_arr) : + present_pos = queue.pop() + #if _arr[present_pos[1]][present_pos[0]] == 1 : return present_pos + for _dis in range(1,_distance+1): + for dx, dy in move: + next_x, next_y = present_pos[0] + _dis*dx, present_pos[1] + _dis*dy + if 0 <= next_x < m and _y-_distance+1 <= next_y and not _arr[next_y][next_x] < 0: + if _arr[next_y][next_x] == 1 : return next_x, next_y + if _dis==1 : + queue.append((next_x, next_y)) + _arr[next_y][next_x] = -1 + return -1, -1 + + +def game(_distance, _defense_arr, _arr) -> int: + count, row_index = 0, n-1 + while _arr and row_index>=0 and check_search_need(_arr): # and (1 in _arr) + deleted_enemies = set() + for col_index in range(m): + if _defense_arr[col_index]: # 궁수 + pos = bfs(_distance, col_index, row_index, deepcopy(_arr)) + if not pos[0]<0 and not pos[1]<0: + deleted_enemies.add(pos) + for enemy in deleted_enemies: + _arr[enemy[1]][enemy[0]] = -1 + count+=1 + _arr.pop() + row_index-=1 + return count + +def solution(_n, _m, _d, _arr) -> int: + total_num = 0 + for combs in combinations(range(_m), 3): + defense = [True if i in combs else False for i in range(_m)] + total_num = max(total_num, game(_d, defense, deepcopy(_arr))) + return total_num + +n,m,d = map(int, input().split()) +arr = [list(map(int, input().split())) for _ in range(n)] +answer = solution(n, m, d, arr) +print(answer) From 2628644e9f8d4c0931e0967a7058156d6bc04de0 Mon Sep 17 00:00:00 2001 From: aqper <97psha@gmail.com> Date: Tue, 16 Aug 2022 09:09:37 +0900 Subject: [PATCH 180/822] =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" => "08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" (100%) diff --git "a/08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" "b/08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" similarity index 100% rename from "08.15/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" rename to "08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" From 5065f9a240bbe86e700b79f30f7818ff18d8aa64 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Tue, 16 Aug 2022 09:26:50 +0900 Subject: [PATCH 181/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=8016637.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\20016637.java" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" diff --git "a/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" "b/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" new file mode 100644 index 0000000..72daaea --- /dev/null +++ "b/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" @@ -0,0 +1,48 @@ +import java.util.Scanner; + +public class 백준16637 { + static String str; + static int n; + static int MAX=Integer.MIN_VALUE; + public static void main(String[] args) { + Scanner scan=new Scanner (System.in); + n=scan.nextInt(); + str=scan.next(); + + + sol(str.charAt(0)-'0',1); //괄호 안줄 때 + System.out.println(MAX); + + } + + public static void sol(int prev,int now){ + if(now==n){ + MAX=Math.max(prev,MAX); + return; + } + + //괄호 줄 때 + if(now<=n-4){ + int result=cal(prev,str.charAt(now),cal(str.charAt(now+1)-'0',str.charAt(now+2),str.charAt(now+3)-'0')); + sol(result,now+4); + } + // 괄호 안줄 때 + if(now<=n-2){ + int result2=cal(prev,str.charAt(now),str.charAt(now+1)-'0'); + sol(result2,now+2); + } + + } + public static int cal (int a,char s, int b){ + if(s=='+'){ + return a+b; + } + else if(s=='-'){ + return a-b; + } + else if(s=='*'){ + return a*b; + } + return 0; + } + } From 290decf96f47abee70748164c3f8e0a7ba0bf1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Tue, 16 Aug 2022 14:34:43 +0900 Subject: [PATCH 182/822] =?UTF-8?q?=EB=B0=B1=ED=8A=B8=EB=9E=98=ED=82=B9=20?= =?UTF-8?q?=EB=AA=BB=ED=95=B4=EB=A8=B9=EA=B2=A0=EC=96=B4=EC=9A=94=20?= =?UTF-8?q?=E3=85=9C=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\266\231\354\235\264\352\270\260.java" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "08.18/\355\231\251\354\247\200\354\233\220/\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" diff --git "a/08.18/\355\231\251\354\247\200\354\233\220/\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" "b/08.18/\355\231\251\354\247\200\354\233\220/\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" new file mode 100644 index 0000000..3b09483 --- /dev/null +++ "b/08.18/\355\231\251\354\247\200\354\233\220/\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" @@ -0,0 +1,91 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + // 각 크기별 색종이 개수 + static int map[] = {0, 5, 5, 5, 5, 5}; + static int arr[][]; + static int result=0, minValue = Integer.MAX_VALUE; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + arr = new int[10][10]; + StringTokenizer st; + for(int i=0; i<10; i++) { + st = new StringTokenizer(br.readLine()); + for(int j=0; j<10; j++) + arr[i][j] = Integer.parseInt(st.nextToken()); + } + dfs(0,0); + // 1로 모두 덮는 것이 불가능할 때 + if(minValue == Integer.MAX_VALUE) + System.out.println(-1); + else + System.out.println(minValue); + } + + public static void dfs(int currentX, int currentY) { + + // 세로 한칸에 해당하는 가로 탐색이 끝났을때 y 인덱스 + 1 + if(currentX == 10) { + dfs(0, currentY+1); + return; + } + // y 인덱스가 10 이면 탐색이 끝난 것 => currentX=9, currentY=9에서 currentX=10, currentY=9 -> currnetX=0 , currentY=10 호출 + if(currentY == 10) { + minValue = Math.min(minValue, result); + return; + } + // 0이면 해당 부분은 그냥 넘어간다. + if(arr[currentY][currentX] == 0) { + dfs(currentX+1, currentY); + return; + } + System.out.println("dfs (" + currentX + ", " + currentY + ")"); + // arr[currentY][currentX] == 1 이면 해당하는 부분부터 사이즈에 맞는 색종이를 붙여본다. + for(int size=5; size>0; size--) { + boolean isPossible = true; + + if(map[size] == 0 || currentY + size > 10 || currentX + size > 10) // 크기를 초과하면 continue로 가서 Size-1 + continue; + + for(int i=0; i Date: Tue, 16 Aug 2022 15:36:28 +0900 Subject: [PATCH 183/822] =?UTF-8?q?Create=2017281=5F=EC=95=BC=EA=B5=AC?= =?UTF-8?q?=EA=B3=B5.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\354\225\274\352\265\254\352\263\265.cpp" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" diff --git "a/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" "b/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" new file mode 100644 index 0000000..95e1f22 --- /dev/null +++ "b/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" @@ -0,0 +1,92 @@ +#include +#include +#include +using namespace std; + +int N; +vector> ening; +int order[51]; +bool visited[51] = { false }; +int maxScore = 0; +void getScore() { //점수구하기 + int score = 0; + int start = 0; + for (int i = 0; i < N; i++) { + int outCount = 0; + bool onGround[] = { false,false,false }; //1루, 2루, 3루 + while (true) { + if (outCount >= 3) { + break; + } + for (int k = start; k < ening[0].size(); k++) { + int s = ening[i][order[k]]; + if (s == 0) { + outCount++; + if (outCount >= 3) { + start = k + 1; + if (start == ening[0].size()) { + start = 0; + } + break; + } + } + else { + for (int k = 0; k < min(s, 3); k++) { //득점 + if (onGround[2 - k]) { + score++; + onGround[2 - k] = false; + } + } + for (int k = 2 - s; k >= 0; k--) { //이동 + if (onGround[k]) { + onGround[k + s] = true; + onGround[k] = false; + } + } + if (s == 4) { //타자 이동 + score++; + } + else { + onGround[s - 1] = true; + } + } + if (k == ening[0].size() - 1) { + k = -1; + } + } + } + } + maxScore = max(maxScore, score); +} + +void DFS(int Cnt) { + if (Cnt == ening[0].size()) { + getScore(); + return; + } + for (int i = 0; i < ening[0].size(); i++) { + if (!visited[i]) { + visited[i] = true; + order[i] = Cnt; + DFS(Cnt + 1); + visited[i] = false; + } + } +} + +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < 9; k++) { + int input; cin >> input; + tmp.push_back(input); + } + ening.push_back(tmp); + } + order[3] = 0; + visited[3] = true; + DFS(1); + cout << maxScore << endl; + return 0; +} From 461f8dbdf19e145d984cbf1870f4c40efa3a0649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 17 Aug 2022 09:17:02 +0900 Subject: [PATCH 184/822] =?UTF-8?q?Create=2017136=5F=EC=83=89=EC=A2=85?= =?UTF-8?q?=EC=9D=B4.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\354\203\211\354\242\205\354\235\264.cpp" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" diff --git "a/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" "b/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" new file mode 100644 index 0000000..fdcdfcb --- /dev/null +++ "b/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" @@ -0,0 +1,77 @@ +#include +#include +#include +#include +using namespace std; + +int N = 10; +vector> board(N); +int paper[] = { 5,5,5,5,5 }; +int minAnswer = INT_MAX; + +bool checkPaper(int x, int y, int count) { + for (int i = 0; i < count; i++) { + for (int k = 0; k < count; k++) { + if (board[x + i][y + k] == 0) { + return false; + } + } + } + return true; +} + +void changeBoard(int x, int y, int count, int flag) { + for (int i = 0; i < count; i++) { + for (int k = 0; k < count; k++) { + board[i + x][k + y] = flag; + } + } +} + +void dfs(int x,int y, int answer) { + if (minAnswer <= answer) { //가지치기 + return; + } + bool find = false; + for (; x < N; x++) { + for (; y < N; y++) { + if (board[x][y] == 1) { + find = true; + break; + } + if (x == N - 1 && y == N - 1) { + minAnswer = min(minAnswer, answer); + return; + } + } + if (find) break; + y = 0; + } + for (int t = 5; t > 0; t--) { + if (x + t > N || y + t > N || paper[t - 1] == 0) continue; //범위를 벗어나면 + if (checkPaper(x, y, t)) { //되는지 확인 + paper[t - 1]--; + changeBoard(x, y, t, 0); + dfs(x, y, answer + 1); + changeBoard(x, y, t, 1); + paper[t - 1]++; + } + } +} + +int main() { + for (int i = 0; i < N; i++) { + for (int k = 0; k < N; k++) { + int input; cin >> input; + board[i].push_back(input); + } + } + dfs(0,0,0); + if (minAnswer == INT_MAX) { + cout << -1 << endl; + } + else { + cout << minAnswer << endl; + } + return 0; +} From 1a9a79df410f68c1e4dd5e59140da6f238283643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 17 Aug 2022 10:35:09 +0900 Subject: [PATCH 185/822] =?UTF-8?q?Create=2017135=5F=EC=BA=90=EC=8A=AC=5F?= =?UTF-8?q?=EB=94=94=ED=8E=9C=EC=8A=A4.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\353\224\224\355\216\234\354\212\244.cpp" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" diff --git "a/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" "b/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" new file mode 100644 index 0000000..89ed44f --- /dev/null +++ "b/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" @@ -0,0 +1,91 @@ +#include +#include +#include +#include +using namespace std; + +int maxScore = 0; +int contact[] = { -1,-1,-1 }; +int N, M, D; +vector> board(16); +vector visited(16,false); + +int dx[] = { 0,-1 ,0 }; +int dy[] = { -1,0 ,1 }; + +int makeScore() { + int score = 0; + vector> cboard(board.begin(), board.end()); + for (int i = 0; i < N; i++) { + vector> remove; + for (int k = 0; k < 3; k++) { + queue> q; //x,y,count; + vector>check(N+1,vector(M,false)); + q.push({ N - i, contact[k], 0 }); + check[N - i][contact[k]] = true; + while (!q.empty()) { + vector now = q.front(); q.pop(); + if (cboard[now[0]][now[1]] == 1) { + remove.push_back({ now[0],now[1] }); + break; + } + if (now[2] == D) continue; + for (int t = 0; t < 3; t++) { + int xx = now[0] + dx[t]; + int yy = now[1] + dy[t]; + if (0 <= xx && xx <= N && 0 <= yy && yy < M) { + if (!check[xx][yy]) { + check[xx][yy] = true; + q.push({ xx,yy,now[2] + 1 }); + } + } + } + } + } + for (auto r : remove) { + if (cboard[r.first][r.second] == 1) { + cboard[r.first][r.second] = 0; + score++; + } + } + for (int t = 0; t < M; t++) { + if (cboard[N - i - 1][t] == 1) { + cboard[N - i - 1][t] = 0; + } + } + } + return score; +} + +void dfs(int index) { + if (index == 3) { + int score = makeScore(); + maxScore = max(maxScore, score); + return; + } + for (int i = 0; i < M; i++) { + if (!visited[i]) { + contact[index] = i; + visited[i] = true; + dfs(index + 1); + visited[i] = false; + contact[index] = -1; + } + } +} + +int main() { + cin >> N >> M >> D; + for (int i = 0; i < N; i++) { + for (int k = 0; k < M; k++) { + int input; cin >> input; + board[i].push_back(input); + } + } + for (int k = 0; k < M; k++) { + board[N].push_back(0); + } + dfs(0); + cout << maxScore << endl; + return 0; +} From 7a44a37f56ddc008ca370fbbd89eb0e1b1078d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 17 Aug 2022 14:27:37 +0900 Subject: [PATCH 186/822] solve --- ...\353\266\231\354\235\264\352\270\260.java" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "08.18/\354\241\260\354\210\230\354\227\260/17136_\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" diff --git "a/08.18/\354\241\260\354\210\230\354\227\260/17136_\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" "b/08.18/\354\241\260\354\210\230\354\227\260/17136_\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" new file mode 100644 index 0000000..a74d272 --- /dev/null +++ "b/08.18/\354\241\260\354\210\230\354\227\260/17136_\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" @@ -0,0 +1,92 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int[][] paper; //종이 + static int[] papers; //색종이 카운트 + static int result; //최소값 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + paper = new int[10][10]; + + for (int i = 0; i < paper.length; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 0; j < paper.length; j++) { + paper[i][j] = Integer.parseInt(token.nextToken()); + } + } + + papers = new int[6]; + for (int i = 1; i < papers.length; i++) { + papers[i] = 5; + } + + result = Integer.MAX_VALUE; + + search(0, 0, 0); + + if (result == Integer.MAX_VALUE) { //제한된 갯수보다 많이 붙인경우 + result = -1; + } + + System.out.println(result); + } + + static void search(int row, int col, int count) { + if (row >= 9 && col > 9) { //마지막점에 도달했을 때 result값 갱신 + result = Math.min(result, count); + return; + } + + if (result <= count) { //result값이 count값보다 작거나 같으면 탐색할 필요없으므로 다음 탐색 + return; + } + + if (col > 9) { //다음 행 검색 + search(row + 1, 0, count); + return; + } + + if (paper[row][col] == 1) { + for (int i = 5; i > 0; i--) { //5크기 종이부터 탐색 + if (papers[i] > 0 && attach(row, col, i)) { //남아있는 종이 수 && 배열의 범위 벗어나지 않는지 체크 + 다음 인덱스 값이 0인지 체크 + init(row, col, i, 0); + papers[i]--; //i 크기의 종이 수 감소 + search(row, col + 1, count + 1); + init(row, col, i, 1); + papers[i]++; + } + } + } else { + search(row, col + 1, count); //0이므로 다음 검색 + } + + } + + static void init(int row, int col, int size, int state) { //value 값 0으로 갱신 후 재귀함수 종료후에 1로 채우기 + for (int i = row; i < row + size; i++) { + for (int j = col; j < col + size; j++) { + paper[i][j] = state; + } + } + } + + static boolean attach(int row, int col, int size) { + for (int i = row; i < row + size; i++) { + for (int j = col; j < col + size; j++) { + if (i < 0 || i >= 10 || j < 0 || j >= 10) { + return false; + } + + if (paper[i][j] != 1) { + return false; + } + } + } + return true; + } +} From 0cfb26bd9308ae44cccaa0fa5c11105fbade8848 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 17 Aug 2022 21:50:14 +0900 Subject: [PATCH 187/822] kihun --- ...64\353\266\231\354\235\264\352\270\260.py" | 52 +++++++++++++++++++ ...1_\354\225\274\352\265\254\352\263\265.py" | 38 ++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 "08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17136_\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260.py" create mode 100644 "08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265.py" diff --git "a/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17136_\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260.py" "b/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17136_\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260.py" new file mode 100644 index 0000000..d84b0d0 --- /dev/null +++ "b/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17136_\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260.py" @@ -0,0 +1,52 @@ +import sys + +sys.stdin = open("./input.txt", "r", encoding="utf-8") +input = sys.stdin.readline + +matrix = [list(map(int, input().split())) for _ in range(10)] +paperList = [5, 5, 5, 5, 5] +total = 25 + + +def sizeCheck(y, x, size): + for j in range(y, y + size + 1): + for i in range(x, x + size + 1): + if matrix[j][i] != 1: + return False + return True + + +def dfs(y, x, count): + global paperList, total + if y >= 10: + total = min(total, count) + return + if x >= 10: + dfs(y + 1, 0, count) + return + if matrix[y][x] == 1: + for s in range(5): + if paperList[s] == 0: + continue + if y + s > 10 or x + s > 10: + continue + if not sizeCheck(y, x, s): + break + for j in range(y, y + s + 1): + for i in range(x, x + s + 1): + matrix[j][i] = 0 + paperList[s] -= 1 + dfs(y, x + s + 1, count + 1) + paperList[s] += 1 + for j in range(y, y + s + 1): + for i in range(x, x + s + 1): + matrix[j][i] = 1 + else: + dfs(y, x + 1, count) + + +dfs(0, 0, 0) +if total == 25: + print(-1) +else: + print(total) diff --git "a/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265.py" "b/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265.py" new file mode 100644 index 0000000..db22010 --- /dev/null +++ "b/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265.py" @@ -0,0 +1,38 @@ +# pypy로 제출 +import sys +import itertools + +sys.stdin = open("./input.txt", "r", encoding="utf-8") +input = sys.stdin.readline + +n = int(input()) +pList = list(itertools.permutations([i for i in range(1, 9)], 8)) +innings = [list(map(int, input().split())) for _ in range(n)] +maxValue = 0 + +for p in pList: + order = list(p[:3]) + [0] + list(p[3:]) + score = 0 + idx = 0 + for inning in innings: + outCount = 0 + base1, base2, base3 = 0, 0, 0 + while outCount < 3: + if inning[order[idx]] == 0: + outCount += 1 + elif inning[order[idx]] == 1: + score += base3 + base1, base2, base3 = 1, base1, base2 + elif inning[order[idx]] == 2: + score = score + base2 + base3 + base1, base2, base3 = 0, 1, base1 + elif inning[order[idx]] == 3: + score = score + base1 + base2 + base3 + base1, base2, base3 = 0, 0, 1 + elif inning[order[idx]] == 4: + score = score + base1 + base2 + base3 + 1 + base1, base2, base3 = 0, 0, 0 + idx = (idx + 1) % 9 + + maxValue = max(maxValue, score) +print(maxValue) From 8a8b6e97050744e5bdf34c49ae52090a6f02b552 Mon Sep 17 00:00:00 2001 From: dldkfma9577 Date: Thu, 18 Aug 2022 13:04:18 +0900 Subject: [PATCH 188/822] =?UTF-8?q?[UPDATE]=20=EC=9D=B4=EC=95=84=EB=A6=84?= =?UTF-8?q?=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\354\203\211\354\242\205\354\235\264.cpp" | 39 +++++++++------- ..._\354\225\274\352\265\254\352\263\265.cpp" | 44 +++++++++++-------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git "a/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" "b/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" index fdcdfcb..81435df 100644 --- "a/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" +++ "b/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" @@ -5,11 +5,12 @@ using namespace std; int N = 10; -vector> board(N); -int paper[] = { 5,5,5,5,5 }; -int minAnswer = INT_MAX; +vector> board(N); +int paper[] = { 5,5,5,5,5 }; // ϴ +int minAnswer = INT_MAX; //ٿ ּ -bool checkPaper(int x, int y, int count) { +//count ũ ̸ ϼ ִ Ȯ +bool checkPaper(int x, int y, int count) { for (int i = 0; i < count; i++) { for (int k = 0; k < count; k++) { if (board[x + i][y + k] == 0) { @@ -20,6 +21,7 @@ bool checkPaper(int x, int y, int count) { return true; } +//x,y count ũ ̸ ̰ų ų (flag = 0 : / flag = 1 : ) void changeBoard(int x, int y, int count, int flag) { for (int i = 0; i < count; i++) { for (int k = 0; k < count; k++) { @@ -29,17 +31,17 @@ void changeBoard(int x, int y, int count, int flag) { } void dfs(int x,int y, int answer) { - if (minAnswer <= answer) { //가지치기 + if (minAnswer <= answer) { //ġ return; } - bool find = false; + bool find = false; //board 1 ãҴ for (; x < N; x++) { for (; y < N; y++) { - if (board[x][y] == 1) { + if (board[x][y] == 1) { //ã find = true; break; } - if (x == N - 1 && y == N - 1) { + if (x == N - 1 && y == N - 1) { // -> minAnswer minAnswer = min(minAnswer, answer); return; } @@ -47,27 +49,30 @@ void dfs(int x,int y, int answer) { if (find) break; y = 0; } - for (int t = 5; t > 0; t--) { - if (x + t > N || y + t > N || paper[t - 1] == 0) continue; //범위를 벗어나면 - if (checkPaper(x, y, t)) { //되는지 확인 - paper[t - 1]--; - changeBoard(x, y, t, 0); - dfs(x, y, answer + 1); - changeBoard(x, y, t, 1); - paper[t - 1]++; + for (int t = 5; t > 0; t--) { //5 1 ã + // ų ̰ + if (x + t > N || y + t > N || paper[t - 1] == 0) continue; + if (checkPaper(x, y, t)) { //Ǵ Ȯ + paper[t - 1]--; // + changeBoard(x, y, t, 0); // ̱ + dfs(x, y, answer + 1); //Ž + changeBoard(x, y, t, 1); // + paper[t - 1]++; // } } } int main() { + //Է for (int i = 0; i < N; i++) { for (int k = 0; k < N; k++) { int input; cin >> input; board[i].push_back(input); } } + // dfs(0,0,0); - if (minAnswer == INT_MAX) { + if (minAnswer == INT_MAX) { // Ұ cout << -1 << endl; } else { diff --git "a/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" "b/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" index 95e1f22..4e7db82 100644 --- "a/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" +++ "b/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" @@ -4,23 +4,25 @@ using namespace std; int N; -vector> ening; -int order[51]; -bool visited[51] = { false }; -int maxScore = 0; -void getScore() { //점수구하기 - int score = 0; - int start = 0; - for (int i = 0; i < N; i++) { - int outCount = 0; - bool onGround[] = { false,false,false }; //1루, 2루, 3루 +vector> ening; //각 이닝 +int order[51]; //타자 순서 +bool visited[51] = { false }; //타자를 넣었는지 +int maxScore = 0; //최대 점수 + + //점수구하기 +void getScore() { + int score = 0; //현재 점수 + int start = 0; //현재 시작 타자 + for (int i = 0; i < N; i++) { //이닝 + int outCount = 0; //이번 이닝에서 out당한 개수 + bool onGround[] = { false,false,false }; //1루, 2루, 3루에 사람이 있는지 while (true) { - if (outCount >= 3) { + if (outCount >= 3) { //3진 아웃 -> 이닝 교채 break; } for (int k = start; k < ening[0].size(); k++) { int s = ening[i][order[k]]; - if (s == 0) { + if (s == 0) { //아웃 outCount++; if (outCount >= 3) { start = k + 1; @@ -31,8 +33,9 @@ void getScore() { //점수구하기 } } else { + //이미 그라운드에 있는 주자 이동 for (int k = 0; k < min(s, 3); k++) { //득점 - if (onGround[2 - k]) { + if (onGround[2 - k]) { //사람이 있으면 score++; onGround[2 - k] = false; } @@ -43,13 +46,14 @@ void getScore() { //점수구하기 onGround[k] = false; } } - if (s == 4) { //타자 이동 + //타자 이동 + if (s == 4) { //홈런 score++; } else { onGround[s - 1] = true; } - } + } //k가 끝에 도달하면 처음부터 if (k == ening[0].size() - 1) { k = -1; } @@ -59,9 +63,9 @@ void getScore() { //점수구하기 maxScore = max(maxScore, score); } -void DFS(int Cnt) { - if (Cnt == ening[0].size()) { - getScore(); +void DFS(int Cnt) { //각 타자 순서 구하기 + if (Cnt == ening[0].size()) { //모든 타자를 구했으면 + getScore(); //점수구하기 return; } for (int i = 0; i < ening[0].size(); i++) { @@ -75,6 +79,7 @@ void DFS(int Cnt) { } int main() { + //입력 cin >> N; for (int i = 0; i < N; i++) { vector tmp; @@ -84,7 +89,8 @@ int main() { } ening.push_back(tmp); } - order[3] = 0; + //시작 + order[3] = 0; //4번 타자 정함 visited[3] = true; DFS(1); cout << maxScore << endl; From bbd526ef51762b9d2ca73f7d4404cf2ef6b8be62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:06:17 +0900 Subject: [PATCH 189/822] Create readme.md --- 08.22/readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 08.22/readme.md diff --git a/08.22/readme.md b/08.22/readme.md new file mode 100644 index 0000000..3c4365e --- /dev/null +++ b/08.22/readme.md @@ -0,0 +1,8 @@ +# 08.22(월) + + +3954 Vrainf**k 인터프리터 +https://www.acmicpc.net/problem/3954 + +17406 배열 돌리기 4 +https://www.acmicpc.net/problem/17406 From 58915986d2f479871a60e7c77846337512ce2643 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 18 Aug 2022 15:57:16 +0900 Subject: [PATCH 190/822] =?UTF-8?q?=EC=95=BC=EA=B5=AC=EA=B3=B5.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 파이썬에게 나쁜 문제 --- .../README.md" | 3 ++ ...1]\354\225\274\352\265\254\352\263\265.py" | 38 ++++++++++++++++ ...34\352\260\204\354\264\210\352\263\274.py" | 43 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 "08.18/\354\235\264\354\247\200\354\234\244/README.md" create mode 100644 "08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265.py" create mode 100644 "08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265_\354\213\234\352\260\204\354\264\210\352\263\274.py" diff --git "a/08.18/\354\235\264\354\247\200\354\234\244/README.md" "b/08.18/\354\235\264\354\247\200\354\234\244/README.md" new file mode 100644 index 0000000..1fd488b --- /dev/null +++ "b/08.18/\354\235\264\354\247\200\354\234\244/README.md" @@ -0,0 +1,3 @@ +## 야구공 - python
+![야구공](https://user-images.githubusercontent.com/50359789/185314102-44ceabc1-c843-42b3-bdd1-209519c97e2a.PNG) +- 파이썬의 최후.. diff --git "a/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265.py" "b/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265.py" new file mode 100644 index 0000000..baa5b97 --- /dev/null +++ "b/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265.py" @@ -0,0 +1,38 @@ + +from itertools import permutations + +n = int(input()) +p = list(permutations([x for x in range(1, 9)], 8)) +board = [list(map(int, input().split(' '))) for x in range(n)] +answer = 0 + +for i in set(p): + order = list(i[:3]) + [0] + list(i[3:]) + score = 0 + index = 0 + for inning in range(n): + out = 0 + base1, base2, base3 = 0, 0, 0 + while out != 3: + if board[inning][order[index]] == 0: + out += 1 + elif board[inning][order[index]] == 1: + score += base3 + base1, base2, base3 = 1, base1, base2 + elif board[inning][order[index]] == 2: + score += (base2 + base3) + base1, base2, base3 = 0, 1, base1 + elif board[inning][order[index]] == 3: + score += (base1 + base2 + base3) + base1, base2, base3 = 0, 0, 1 + elif board[inning][order[index]] == 4: + score += (base1 + base2 + base3 + 1) + base1, base2, base3 = 0, 0, 0 + index += 1 + if index == 9: + index = 0 + + answer = max(answer, score) +print(answer) + +# https://bladejun.tistory.com/113 \ No newline at end of file diff --git "a/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265_\354\213\234\352\260\204\354\264\210\352\263\274.py" "b/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265_\354\213\234\352\260\204\354\264\210\352\263\274.py" new file mode 100644 index 0000000..a6d5cce --- /dev/null +++ "b/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265_\354\213\234\352\260\204\354\264\210\352\263\274.py" @@ -0,0 +1,43 @@ +import sys +sys.stdin = open("input.txt") + +from itertools import permutations + +MAX_PLAYER_NUM = 9 +GET_SCORE = 4 + +def count_score(_arrange, _n, _arr) -> int: + arrange_index, score, out, = 0, 0, 0 + for game_index in range(_n): + field, out = [0]*4, 0 + while out<3: + player_index = _arrange[arrange_index] + play_hit = _arr[game_index][player_index] + if play_hit==0 : + out +=1 + field[0] = 0 + else : + field[0] = 1 + for i in range(3, -1, -1): + if field[i] and i + play_hit >= GET_SCORE: + score += 1 + field[i] = 0 + if i + play_hit < GET_SCORE: + field[i + play_hit], field[i] = field[i], 0 + arrange_index = (arrange_index+1)%MAX_PLAYER_NUM + return score + +def solution(_n, _arr) -> int: + max_count = 0 + for arrange in permutations([i for i in range(1,9)],8) : + arrange_list = list(arrange) + arrange_list.insert(3, 0) + max_count = max(max_count, count_score(arrange_list, _n, _arr)) + return max_count + + +n = int(input()) +arr = [list(map(int, input().split())) for _ in range(n)] +answer = solution(n, arr) +print(answer) + From d40848c1e4d91767a0109aefdd1efbdb56bfd26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 18 Aug 2022 17:35:40 +0900 Subject: [PATCH 191/822] =?UTF-8?q?Create=2017406=5F=EB=B0=B0=EC=97=B4?= =?UTF-8?q?=EB=8F=8C=EB=A6=AC=EA=B8=B04.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\217\214\353\246\254\352\270\2604.cpp" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "08.22/\354\235\264\354\225\204\353\246\204/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.cpp" diff --git "a/08.22/\354\235\264\354\225\204\353\246\204/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.cpp" "b/08.22/\354\235\264\354\225\204\353\246\204/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.cpp" new file mode 100644 index 0000000..c059ed0 --- /dev/null +++ "b/08.22/\354\235\264\354\225\204\353\246\204/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.cpp" @@ -0,0 +1,83 @@ +#include +#include +#include +#include +using namespace std; + +int N, M, K; +vector> board; +vector> change; +int dx[] = { 1,0,-1,0 }; +int dy[] = { 0,1,0,-1 }; +int minAnswer = INT_MAX; + +//바꾸는 함수 +void swap(int x1, int y1, int x2, int y2, vector> ©) { + int tmp = copy[x1][y1]; + copy[x1][y1] = copy[x2][y2]; + copy[x2][y2] = tmp; +} + +//돌리는 함수 +void rotation(int x,int y,int s, vector> ©) { + int endx[] = { x + s,x + s,x - s,x - s }; + int endy[] = { y - s,y + s,y + s,y - s }; + int index = 0; + x -= s; y -= s; + for (int i = 0; i < s * 8 -1; i++) { + if (x == endx[index] && y == endy[index]) { + index++; + } + int xx = x + dx[index]; + int yy = y + dy[index]; + swap(x, y, xx, yy, copy); + x = xx; y = yy; + } +} + +//최소 값 구하는 함수 +void minScore(vector> ©) { + for (int i = 1; i <= N; i++) { + int sum = 0; + for (int k = 1; k <= M; k++) { + sum += copy[i][k]; + if (minAnswer < sum) { + break; + } + } + minAnswer = min(minAnswer, sum); + } +} + +int main() { + //입력 + cin >> N >> M >> K; + board.push_back({}); + for (int i = 1; i <= N; i++) { + vector tmp; + tmp.push_back(0); + for (int k = 1; k <= M; k++) { + int input; cin >> input; + tmp.push_back(input); + } + board.push_back(tmp); + } + vector order; + for (int i = 0; i < K; i++) { + int x, y, s; cin >> x >> y >> s; + change.push_back({ x,y,s }); + order.push_back(i); + } + //시작 + do { //순열 + vector> copy(board.begin(), board.end()); + for (int i = 0; i < K; i++) { + for (int k = 1; k <= change[order[i]][2]; k++) { + rotation(change[order[i]][0], change[order[i]][1], k,copy); + } + } + minScore(copy); + } while (next_permutation(order.begin(), order.end())); + cout << minAnswer << endl; + return 0; +} From 9d8ec8d5f9643acac0ccff9e998474db0ff78725 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:10:10 +0900 Subject: [PATCH 192/822] =?UTF-8?q?Create=20=EC=83=89=EC=A2=85=EC=9D=B4?= =?UTF-8?q?=EB=B6=99=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 오답, 반례 확인, 수정 중 --- ...5\264\353\266\231\354\235\264\352\270\260" | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 "08.18/\354\240\225\355\230\270\354\241\260/\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260" diff --git "a/08.18/\354\240\225\355\230\270\354\241\260/\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260" "b/08.18/\354\240\225\355\230\270\354\241\260/\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260" new file mode 100644 index 0000000..f473686 --- /dev/null +++ "b/08.18/\354\240\225\355\230\270\354\241\260/\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260" @@ -0,0 +1,218 @@ + +package baekjoon; + +import java.util.Scanner; + +public class swea_17136_색종이접기 { + static int[][] map; + static int[] count; + static int ans; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + ans = 0; + map = new int[10][10]; + count = new int[5]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + map[i][j] = sc.nextInt(); + } + } + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + if (map[i][j] == 1) { + if (check5(map, i, j) && count[4] <= 5) { + changevalue(i, j, 5); + count[4]++; + } + } + } + for (int j = 0; j < 10; j++) { + if (map[i][j] == 1) { + if (check4(map, i, j) && count[3] <= 5) { + changevalue(i, j, 4); + count[3]++; + } + } + } + for (int j = 0; j < 10; j++) { + if (map[i][j] == 1) { + if (check3(map, i, j) && count[2] <= 5) { + changevalue(i, j, 3); + count[2]++; + } + } + } + for (int j = 0; j < 10; j++) { + if (map[i][j] == 1) { + if (check2(map, i, j) && count[1] <= 5) { + changevalue(i, j, 2); + count[1]++; + } + } + } + for (int j = 0; j < 10; j++) { + if (map[i][j] == 1) { + map[i][j] = 0; + count[0]++; + } + } + } + for (int i = 0; i < count.length; i++) { + ans += count[i]; + } + Loop1: for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + if (map[i][j] == 1 || count[0] > 5) { + ans = -1; + break Loop1; + } + + } + } +// result(map, count, 0, 0, 0); + System.out.println(ans); + + } +// +// static void result(int[][] arr, int[] cnt, int i, int j, int answer) { +// if (i == 9 && j == 9) { +// for (int k = 0; k < cnt.length; k++) { +// answer += cnt[i]; +// } +// if (answer < ans) +// ans = answer; +// Loop1: for (int r = 0; r < 10; r++) { +// for (int c = 0; c < 10; c++) { +// if (arr[r][c] == 1 || cnt[0] > 5) { +// ans = -1; +// break Loop1; +// } +// } +// } +// return; +// } +// +// for (; i < 10; i++) { +// for (; j < 10; j++) { +// if (arr[i][j] == 1) { +// if (cnt[4] < 5 && check5(arr, i, j)) { +// changevalue(i, j, 5); +// cnt[4]++; +// if (i < 5 && j < 5) { +// i = i + 5; +// j = j + 5; +// } +// result(arr, cnt, i, j, answer); +// } +// if (cnt[3] < 5 && check4(arr, i, j)) { +// changevalue(i, j, 4); +// cnt[3]++; +// if (i < 4 && j < 4) { +// i = i + 4; +// j = j + 4; +// } +// result(arr, cnt, i, j, answer); +// } +// if (cnt[2] < 5 && check3(arr, i, j)) { +// changevalue(i, j, 3); +// cnt[2]++; +// if (i < 3 && j < 3) { +// i = i + 3; +// j = j + 3; +// } +// result(arr, cnt, i, j, answer); +// } +// if (cnt[1] < 5 && check5(arr, i, j)) { +// changevalue(i, j, 2); +// cnt[1]++; +// if (i < 2 && j < 2) { +// i = i + 2; +// j = j + 2; +// } +// result(arr, cnt, i, j, answer); +// } +// if (map[i][j] == 1) { +// map[i][j] = 0; +// cnt[0]++; +// } +// +// } +// } +// } +// } + + static boolean check5(int[][] arr, int r, int c) { + int cnt = 0; + if (r <= 5 && c <= 5) { + for (int i = r; i < r + 5; i++) { + for (int j = c; j < c + 5; j++) { + if (arr[i][j] == 1) + cnt++; + } + } + } + if (cnt == 25) + return true; + else + return false; + } + + static boolean check4(int[][] arr, int r, int c) { + int cnt = 0; + if (r <= 6 && c <= 6) { + for (int i = r; i < r + 4; i++) { + for (int j = c; j < c + 4; j++) { + if (arr[i][j] == 1) + cnt++; + } + } + } + if (cnt == 16) + return true; + else + return false; + } + + static boolean check3(int[][] arr, int r, int c) { + int cnt = 0; + if (r <= 7 && c <= 7) { + for (int i = r; i < r + 3; i++) { + for (int j = c; j < c + 3; j++) { + if (arr[i][j] == 1) + cnt++; + } + } + } + if (cnt == 9) + return true; + else + return false; + } + + static boolean check2(int[][] arr, int r, int c) { + int cnt = 0; + if (r <= 8 && c <= 8) { + for (int i = r; i < r + 2; i++) { + for (int j = c; j < c + 2; j++) { + if (arr[i][j] == 1) + cnt++; + } + } + } + if (cnt == 4) + return true; + else + return false; + } + + static void changevalue(int i, int j, int n) { + for (int k = i; k < i + n; k++) { + for (int h = j; h < j + n; h++) { + map[k][h] = 0; + } + } + } +} From 4dc79e4609d79da13cc3334fa46ff27f6cd0d5e3 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:10:39 +0900 Subject: [PATCH 193/822] =?UTF-8?q?Create=20=EC=95=BC=EA=B5=AC=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 야구공 --- .../\354\225\274\352\265\254\352\263\265" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "08.18/\354\240\225\355\230\270\354\241\260/\354\225\274\352\265\254\352\263\265" diff --git "a/08.18/\354\240\225\355\230\270\354\241\260/\354\225\274\352\265\254\352\263\265" "b/08.18/\354\240\225\355\230\270\354\241\260/\354\225\274\352\265\254\352\263\265" new file mode 100644 index 0000000..a5d9ff5 --- /dev/null +++ "b/08.18/\354\240\225\355\230\270\354\241\260/\354\225\274\352\265\254\352\263\265" @@ -0,0 +1,91 @@ +package baekjoon; + +import java.util.*; +import java.io.*; +public class 야구공_17281_ans { + + static int N, ans = -1; + static boolean[] selected = new boolean[10]; + static int[] players = new int[10]; + static int[][] arr; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + StringTokenizer st; + arr = new int[N][10]; + for(int i=0;i Date: Fri, 19 Aug 2022 13:40:11 +0900 Subject: [PATCH 194/822] =?UTF-8?q?Create=201=5F=EC=BD=9C=EB=9D=BC?= =?UTF-8?q?=EB=B3=91.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1_\354\275\234\353\235\274\353\263\221.cpp" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1_\354\275\234\353\235\274\353\263\221.cpp" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1_\354\275\234\353\235\274\353\263\221.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1_\354\275\234\353\235\274\353\263\221.cpp" new file mode 100644 index 0000000..7eb450e --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/1_\354\275\234\353\235\274\353\263\221.cpp" @@ -0,0 +1,14 @@ +#include +#include + +using namespace std; + +int solution(int a, int b, int n) { + int answer = 0; + while (n / a) { + int plus = b * (n / a); + answer += plus; + n = n % a + plus; + } + return answer; +} From cac4e9910b5961c1132d7933d44a3dd22e8138d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 19 Aug 2022 13:40:45 +0900 Subject: [PATCH 195/822] =?UTF-8?q?Create=202=5F=ED=96=84=EB=B2=84?= =?UTF-8?q?=EA=B1=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\355\226\204\353\262\204\352\261\260.cpp" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2_\355\226\204\353\262\204\352\261\260.cpp" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2_\355\226\204\353\262\204\352\261\260.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2_\355\226\204\353\262\204\352\261\260.cpp" new file mode 100644 index 0000000..e3a1425 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/2_\355\226\204\353\262\204\352\261\260.cpp" @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include + +using namespace std; + +int solution(vector ingredient) { + int answer = 0; + stack s; s.push(0); + //s에 1,2가 있고 배열에 3,1이 있는 경우 햄버거 가능 + for (int i = 0; i < ingredient.size()-1; i++) { + if (ingredient[i] == 3 && ingredient[i + 1] == 1) { + if (s.top() == 2) { + s.pop(); + if (s.top() == 1) { + s.pop(); + answer++; + i++; + continue; + } + else { + s.push(2); + } + } + } + s.push(ingredient[i]); + } + return answer; +} From e64d36cf559d38ebb4d5c76c8d1e5dabdc699bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 19 Aug 2022 13:41:00 +0900 Subject: [PATCH 196/822] =?UTF-8?q?Create=203=5F=EC=A0=81=EC=A7=84?= =?UTF-8?q?=EC=B9=A8=ED=88=AC.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\247\204\354\271\250\355\210\254.cpp" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" new file mode 100644 index 0000000..e9662a2 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +using namespace std; + +int solution(int distance, vector> scope, vector> times) { + map m; + for (int i = 0; i < scope.size(); i++) { + m[scope[i][0]] = i; + } + sort(scope.begin(), scope.end()); + for (vector s : scope) { + int index = m[s[0]]; + for (int i = min(s[0], s[1]); i <= max(s[0], s[1]); i++) { + int per = i % (times[index][0] + times[index][1]); + if (per != 0 && per <= times[index][0]) { + return i; + } + } + } + + return distance; +} From c095936bbc7b878f1b646cc0614c7c0ba84ee3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Fri, 19 Aug 2022 17:49:31 +0900 Subject: [PATCH 197/822] solve --- ...353\217\214\353\246\254\352\270\2604.java" | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 "08.22/\354\241\260\354\210\230\354\227\260/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.java" diff --git "a/08.22/\354\241\260\354\210\230\354\227\260/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.java" "b/08.22/\354\241\260\354\210\230\354\227\260/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.java" new file mode 100644 index 0000000..c811ed1 --- /dev/null +++ "b/08.22/\354\241\260\354\210\230\354\227\260/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.java" @@ -0,0 +1,179 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int M; + static int K; + static int[][] arr; + static int[][] copied; + static int[][] rotateArr; + static boolean[] visited; + static int min = Integer.MAX_VALUE; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + K = Integer.parseInt(token.nextToken()); + + arr = new int[N + 1][M + 1]; + copied = new int[N + 1][M + 1]; + + for (int i = 1; i <= N; i++) { + token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= M; j++) { + int value = Integer.parseInt(token.nextToken()); + arr[i][j] = value; + copied[i][j] = value; + + } + } + + rotateArr = new int[K][3]; + + for (int i = 0; i < K; i++) { + token = new StringTokenizer(br.readLine()); + rotateArr[i][0] = Integer.parseInt(token.nextToken()); + rotateArr[i][1] = Integer.parseInt(token.nextToken()); + rotateArr[i][2] = Integer.parseInt(token.nextToken()); + + } + + visited = new boolean[K]; + int[] order = new int[K]; + + combination(0, order); + + System.out.println(min); + + } + + static void init() { + for (int i = 1; i < arr.length; i++) { + for (int j = 1; j < arr[i].length; j++) { + arr[i][j] = copied[i][j]; + } + } + } + + static void combination(int size, int[] order) { + if (size == K) { + init(); + rotate(order); + min = Math.min(min, getMin()); + return; + } + + for (int i = 0; i < K; i++) { + if (!visited[i]) { + visited[i] = true; + order[size] = i; + combination(size + 1, order); + visited[i] = false; + } + } + } + + static void rotate(int[] order) { + for (int i = 0; i < order.length; i++) { + int direction = 1; + int[][] temp = new int[N + 1][M + 1]; + + int r = rotateArr[order[i]][0]; + int c = rotateArr[order[i]][1]; + int s = rotateArr[order[i]][2]; + + int row = r - s; + int col = c - s; + int target = arr[row + 1][col]; + + while (true) { + + if (row == r && col == c) { + temp[row][col] = arr[row][col]; + break; + } + + temp[row][col] = target; + + switch (direction) { + case 1: + if (col == c + s || temp[row][col + 1] != 0) { + direction = 2; + row++; + target = arr[row - 1][col]; + + } else { + col++; + target = arr[row][col - 1]; + + } + break; + + case 2: + if (row == r + s || temp[row + 1][col] != 0) { + direction = 3; + col--; + target = arr[row][col + 1]; + + } else { + row++; + target = arr[row - 1][col]; + + } + break; + case 3: + if (col == c - s || temp[row][col - 1] != 0) { + direction = 4; + row--; + target = arr[row + 1][col]; + + } else { + col--; + target = arr[row][col + 1]; + + } + break; + case 4: + if (row == r - s || temp[row - 1][col] != 0) { + direction = 1; + col++; + target = arr[row+1][col]; + + } else { + row--; + target = arr[row + 1][col]; + + } + break; + } + + } + + + for (int j = r - s; j <= r + s; j++) { + for (int k = c - s; k <= c + s; k++) { + arr[j][k] = temp[j][k]; + } + } + + } + } + + static int getMin() { + int rowMin = Integer.MAX_VALUE; + for (int i = 1; i < arr.length; i++) { + int sum = 0; + for (int j = 1; j < arr[i].length; j++) { + sum += arr[i][j]; + } + rowMin = Math.min(rowMin, sum); + } + return rowMin; + } +} From 831fd4dc9be8941f8025b4ff312f944d43c8f76c Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Sat, 20 Aug 2022 06:44:42 +0900 Subject: [PATCH 198/822] solve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2미완 . . --- ...202\254 3\355\232\214\354\260\250]no.1.py" | 7 ++++++ ...202\254 3\355\232\214\354\260\250]no.2.py" | 21 ++++++++++++++++ ...202\254 3\355\232\214\354\260\250]no.3.py" | 25 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.1.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.3.py" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.1.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.1.py" new file mode 100644 index 0000000..272844f --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.1.py" @@ -0,0 +1,7 @@ +def solution(a, b, n): + answer = 0 + while n>=a: + q, r = n // a, n % a + answer += q*b + n = r + q*b + return answer \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" new file mode 100644 index 0000000..4d97456 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" @@ -0,0 +1,21 @@ +# 빵 : 1, 야채 : 2, 고기 : 3 => 유일한 포장 조건 : 1-3-2-1 +HAMBURGER_LEN = 4 + +def checkIsHamburger(_stack) -> bool: + if len(_stack) bool: + patrol_index = _arr[_position] -1 + work_time, play_time = _times[patrol_index][0], _times[patrol_index][1] + if 0 <_time%(work_time + play_time)<=work_time : return False + else : return True + +def makeSorted(_val1, _val2) -> (int, int): + if _val1 < _val2 : return _val1, _val2 + else : return _val2, _val1 + +def makeInfoArr(_scope, _arr) -> list: + for patrol_index in range(len(_scope)): + start_range, finish_range = makeSorted(_scope[patrol_index][0], _scope[patrol_index][1]) + for i in range(start_range,finish_range+1): + _arr[i] = patrol_index + 1 + return _arr + +def solution(distance, scope, times): + arr = makeInfoArr(scope, [0]*distance) + for move_index in range(distance): + if not arr[move_index] : continue + if not checkIsAvailable(move_index, arr, move_index, times) : + return move_index + return distance From 1b52cdaa6d25455922d5031f1e4fbd52437ed8f0 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Sat, 20 Aug 2022 17:24:48 +0900 Subject: [PATCH 199/822] =?UTF-8?q?Create=201=EB=B2=88=EB=AC=B8=EC=A0=9C.j?= =?UTF-8?q?ava?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\262\210\353\254\270\354\240\234.java" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/1\353\262\210\353\254\270\354\240\234.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/1\353\262\210\353\254\270\354\240\234.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/1\353\262\210\353\254\270\354\240\234.java" new file mode 100644 index 0000000..4673dc9 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\352\266\214\354\243\274\355\230\204/1\353\262\210\353\254\270\354\240\234.java" @@ -0,0 +1,20 @@ +class Solution { + static int ans; + public int solution(int a, int b, int n) { + cola(a,b,n,0); + return ans; + } + + public static void cola (int a, int b, int n,int sum) { + if(n 1회 했을 때 받는 병 => 다시 n으로 재귀 +//n =20 a=2 b=1 From ecfbc72419c0b7d629c9412fe0f23af5a645db67 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Sat, 20 Aug 2022 19:41:03 +0900 Subject: [PATCH 200/822] =?UTF-8?q?4=EB=B2=88=EB=AC=B8=EC=A0=9C-=EB=B6=80?= =?UTF-8?q?=EB=B6=84=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...202\254 3\355\232\214\354\260\250]no.3.py" | 9 ++-- ...54 3\355\232\214\354\260\250]no.4_idea.py" | 18 ++++++++ ...3\355\232\214\354\260\250]no.4_sol_bad.py" | 46 +++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_idea.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_sol_bad.py" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.3.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.3.py" index 481ff9b..91e35f6 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.3.py" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.3.py" @@ -1,6 +1,7 @@ +# 영역 카운팅(=도착=~까지)은 "인덱스 끝" 기준 / 따라서 index = '0' ~ 'd' (distance = d) def checkIsAvailable(_position, _arr, _time, _times) -> bool: - patrol_index = _arr[_position] -1 + patrol_index = _arr[_position] -1 # 순찰병 번호 = 인덱스 + 1 work_time, play_time = _times[patrol_index][0], _times[patrol_index][1] if 0 <_time%(work_time + play_time)<=work_time : return False else : return True @@ -12,13 +13,13 @@ def makeSorted(_val1, _val2) -> (int, int): def makeInfoArr(_scope, _arr) -> list: for patrol_index in range(len(_scope)): start_range, finish_range = makeSorted(_scope[patrol_index][0], _scope[patrol_index][1]) - for i in range(start_range,finish_range+1): - _arr[i] = patrol_index + 1 + for i in range(start_range,finish_range+1): # start_scope <= x <= finish scope + _arr[i] = patrol_index + 1 # 순찰병 번호 = 인덱스 + 1 return _arr def solution(distance, scope, times): arr = makeInfoArr(scope, [0]*distance) - for move_index in range(distance): + for move_index in range(distance): # time = move_index (화랑이가 1m/s로 고정되어 있기 때문) if not arr[move_index] : continue if not checkIsAvailable(move_index, arr, move_index, times) : return move_index diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_idea.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_idea.py" new file mode 100644 index 0000000..cef7c65 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_idea.py" @@ -0,0 +1,18 @@ +def makeAdjacencyList(_arr) -> dict: + graph = dict() + for element in _arr: + e1, e2 = element[0], element[1] + graph[e1] = graph.get(e1, []) + [e2] + graph[e2] = graph.get(e2, []) + [e1] + return graph + +def solution(n, lighthouse): + answer_list, max_lightInfo = [False]*(n+1), [0,0] + graph = makeAdjacencyList(lighthouse) + graph_keys = graph.keys() + for key in graph_keys: + neighbors = graph.get(key, []) + len_neighbors = len(neighbors) + if len_neighbors == 1 and not answer_list[neighbors[0]]: + answer_list[neighbors[0]] = True + return answer_list.count(True) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_sol_bad.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_sol_bad.py" new file mode 100644 index 0000000..607cedc --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.4_sol_bad.py" @@ -0,0 +1,46 @@ + +def makeAdjacencyList(_arr) -> dict: + graph = dict() + for element in _arr: + e1, e2 = element[0], element[1] + graph[e1] = graph.get(e1, []) + [e2] + graph[e2] = graph.get(e2, []) + [e1] + return graph + +def dfs(_node, _graph:dict, _visited, _need_lights) -> int: + global answer + neighbors = _graph.get(_node) + if len(neighbors) == 1: + lights[neighbors[0]] = True + _need_lights[neighbors[0]] = False + # _need_lights[_node] = False + if True not in _need_lights : + answer = min(answer, lights.count(True)) + for neighbors_of_light in _graph.get(neighbors[0]): + _need_lights[neighbors_of_light] = False + return 1 + for next_node in neighbors: + # if lights[next_node] : + # _need_lights[_node] = False + if not _visited[next_node]: + _visited[next_node] = True + dfs(next_node, _graph, _visited, _need_lights) + if _need_lights[_node]: + lights[_node] = True + dfs(next_node, _graph, _visited, _need_lights) + lights[_node] = False + return 0 + +def solution(n, lighthouse): + graph = makeAdjacencyList(lighthouse) + visited = [False]*(n+1) + need_lights = [True]*(n+1) + + visited[1] = True + dfs(1, graph, visited, need_lights) + return + +lights = [False]*(100000+1) +answer = 100000 + + From 8236fbf1d23161775a41319ba15d2782dae14afe Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 20 Aug 2022 20:16:07 +0900 Subject: [PATCH 201/822] =?UTF-8?q?=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\240\234_\354\210\234\354\227\264.java" | 103 ++++++++++++++++++ .../Question1.java" | 29 +++++ .../Question2.java" | 43 ++++++++ .../Question3.java" | 40 +++++++ .../Question4.java" | 92 ++++++++++++++++ 5 files changed, 307 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/4\353\262\210\353\254\270\354\240\234_\354\210\234\354\227\264.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question4.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/4\353\262\210\353\254\270\354\240\234_\354\210\234\354\227\264.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/4\353\262\210\353\254\270\354\240\234_\354\210\234\354\227\264.java" new file mode 100644 index 0000000..e5fdb4c --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/4\353\262\210\353\254\270\354\240\234_\354\210\234\354\227\264.java" @@ -0,0 +1,103 @@ +package third; + +import java.util.ArrayList; +import java.util.List; + +public class Copy { + + public static void main(String[] args) { + Copy4 s4 = new Copy4(); + int n = 8; + int[][] lighthouse = {{1,2},{1,3},{1,4},{5,6},{5,7},{5,8}}; + System.out.println(s4.solution(n,lighthouse)); + + } + +} + +class Copy4 { + static List[] lhList; + static int N; + static boolean[] visited; + static int[] linked; + static int answer; + static boolean check; + + public int solution(int n, int[][] lighthouse) { + answer = 0; + lhList = new ArrayList[n+1]; + linked = new int[n+1]; + N = n; + + for (int i = 0; i < n+1; i++) { + lhList[i] = new ArrayList(); + } + + for (int i = 0; i < lighthouse.length; i++) { + lhList[lighthouse[i][0]].add(lighthouse[i][1]); + lhList[lighthouse[i][1]].add(lighthouse[i][0]); + } + + check = false; + + for (int i = 1; i <= n; i++) { + int comb[] = new int[i]; + visited = new boolean[n+1]; + combination(1,0,comb,0); + + if (check) { + break; + } + } + + + return answer; + } + + public void combination(int start,int size,int[] comb,int sum) { + + if(size == comb.length) { + if (sum == N) { + boolean isLight = check(comb); + if (isLight) { + answer = comb.length; + check = true; + } + } + return; + } + + for (int i = start; i <= N; i++) { + if (!visited[i]) { + visited[i] = true; + comb[size] = i; + combination(i+1,size+1,comb,sum+lhList[i].size()+1); + visited[i] = false; + } + } + } + + public boolean check(int[] comb) { + linked = new int[N+1]; + int count = 0; + for (int i = 0; i < comb.length; i++) { + if (linked[comb[i]] != 1) { + linked[comb[i]] = 1; + count++; + } + + for (int value : lhList[comb[i]]) { + if (linked[value] != 1) { + linked[value] = 1; + count++; + } + } + } + + if (count == N) { + return true; + } + + return false; + } +} \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" new file mode 100644 index 0000000..eb1b274 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question1.java" @@ -0,0 +1,29 @@ +package third; + +public class Question1 { + + public static void main(String[] args) { + Solution s1 = new Solution(); + int a = 3; + int b = 1; + int n = 20; + System.out.println(s1.solution(a, b, n)); + } + +} + +class Solution { + public int solution(int a, int b, int n) { + int answer = 0; + while (true) { + int cola = (n / a) * b; //콜라로 교환 + n %= a; //빈병 + answer += cola; //콜라 갯수 만큼 더하기 + n += cola; + if (cola <= 0) { //교환할 수 있는 콜라가 0개면 무한루프 탈출 + break; + } + } + return answer; + } +} \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" new file mode 100644 index 0000000..90cc361 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question2.java" @@ -0,0 +1,43 @@ +package third; + +import java.util.Stack; + +public class Question2 { + + public static void main(String[] args) { + Solution2 s2 = new Solution2(); + int[] ingredient = { 2,1,1,2,3,1,2,3,1}; + System.out.println(s2.solution(ingredient)); + } + +} + +class Solution2 { + public int solution(int[] ingredient) { + int answer = 0; + Stack burger = new Stack<>(); //햄버거 + for (int i = 0; i < ingredient.length; i++) { + if (burger.size() >= 3) { //재료가 3개이상 쌓이면 햄버거를 포장할 수 있는 여부를 판단할 수 있음 + if (ingredient[i] == 1) { //1이 들어왔을 때 앞에 3개 요소를 비교후 햄버거 순서이면 pop 아니면 다시 push + int order3 = burger.pop(); + int order2 = burger.pop(); + int order1 = burger.pop(); + if (order1 == 1 && order2 == 2 && order3 == 3) { //순서에 맞으면 +1 + answer++; + } else { + burger.push(order1); + burger.push(order2); + burger.push(order3); + burger.push(1); + } + } else { //1이 아니라면 재료 추가 + burger.push(ingredient[i]); + } + } else { //재료가 3개이하라면 재료 추가 + burger.push(ingredient[i]); + } + } + + return answer; + } +} diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" new file mode 100644 index 0000000..eb64d47 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question3.java" @@ -0,0 +1,40 @@ +package third; + +public class Question3 { + + public static void main(String[] args) { + Solution3 s3 = new Solution3(); + int distance = 12; + int[][] scope = { { 7, 8 }, { 4, 6 }, { 11, 10 } }; + int[][] times = { { 2, 2 }, { 2, 4 }, { 3, 3 } }; + System.out.println(s3.solution(distance, scope, times)); + } +} + +class Solution3 { + public int solution(int distance, int[][] scope, int[][] times) { + int answer = distance; + int[] hwarang = new int[distance + 1]; // 위치가 1부터 시작이기 때문에 +1 + + for (int i = 0; i < scope.length; i++) { + int start = Math.min(scope[i][0], scope[i][1]); // 정렬되어있지 않기 때문에 시작점 종점 세팅 + int end = Math.max(scope[i][0], scope[i][1]); + for (int j = start; j <= end; j++) { //범위 만큼 반복 + int location = j % (times[i][0] + times[i][1]); //시간범위 넘어가면 다시 0부터 초기화 + if (location != 0) { //location이 0이되면 해당 시간때는 휴식상태 + if (location - times[i][0] <= 0) { //근무시간보다 작거나 같을 경우에는 근무상태 + hwarang[j] = 1; + } + } + } + } + + for (int i = 1; i < hwarang.length; i++) { //해당 m일때 근무하고 있는지 체크 + if (hwarang[i] == 1) { + answer = i; + break; + } + } + return answer; + } +} \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question4.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question4.java" new file mode 100644 index 0000000..67ee19e --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\241\260\354\210\230\354\227\260/Question4.java" @@ -0,0 +1,92 @@ +package third; + +import java.util.*; + +public class Question4 { + + public static void main(String[] args) { + Solution4 s4 = new Solution4(); + int n = 10; + int[][] lighthouse = { { 4, 1 }, { 5, 1 }, { 5, 6 }, { 7, 6 }, { 1, 2 }, { 1, 3 }, { 6, 8 }, { 2, 9 },{ 9, 10 } }; + //{ 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 5, 6 }, { 5, 7 }, { 5, 8 } + System.out.println(s4.solution(n, lighthouse)); + } + +} + +class Solution4 { + + static List[] lh; + static int[] matched; + static boolean[] visited; + static List indexList; + + public int solution(int n, int[][] lighthouse) { + int answer = 0; + + lh = new ArrayList[n + 1]; + matched = new int[n+1]; + Arrays.fill(matched, -1); + + for (int i = 1; i <= n; i++) { + lh[i] = new ArrayList(); + } + + for (int i = 0; i < lighthouse.length; i++) { + lh[lighthouse[i][0]].add(lighthouse[i][1]); + lh[lighthouse[i][1]].add(lighthouse[i][0]); + } + + for (int i = 1; i <= n; i++) { + if (lh[i].size() == 1) continue; + visited = new boolean[n+1]; + if (matching(i)) { + answer++; + } + } + + + for (int i = 0; i < matched.length; i++) { + if (check(matched[i],n)) { + answer--; + } + } + + + return answer; + } + + public boolean matching(int value) { + for (Integer node : lh[value]) { + if (visited[node]) continue; + visited[node] = true; + if (matched[node] == -1 || matching(matched[node])) { + matched[node] = value; + return true; + } + + } + return false; + } + + public boolean check(int value, int n) { + boolean[] checked = new boolean[n+1]; + if (value != -1) { + + int count = lh[value].size(); + for (Integer node : lh[value]) { + for (int i = 0; i < matched.length; i++) { + if (node == matched[i] && !checked[node]) { + count--; + } + } + } + + if (count == 0) { + return true; + } + } + + return false; + } +} \ No newline at end of file From 6d3b46a15acac5f37885e58cb854b14766fb8b1d Mon Sep 17 00:00:00 2001 From: dldkfma9577 Date: Sat, 20 Aug 2022 20:38:49 +0900 Subject: [PATCH 202/822] =?UTF-8?q?[=EC=9D=B4=EC=95=84=EB=A6=84]=203?= =?UTF-8?q?=EB=B2=88=20=EB=AC=B8=EC=A0=9C=20=EC=A3=BC=EC=84=9D=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\240\201\354\247\204\354\271\250\355\210\254.cpp" | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" index e9662a2..7a1dfe5 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\225\204\353\246\204/3_\354\240\201\354\247\204\354\271\250\355\210\254.cpp" @@ -6,20 +6,19 @@ using namespace std; int solution(int distance, vector> scope, vector> times) { - map m; + map m; //time index for (int i = 0; i < scope.size(); i++) { m[scope[i][0]] = i; } - sort(scope.begin(), scope.end()); + sort(scope.begin(), scope.end()); //ġ for (vector s : scope) { int index = m[s[0]]; for (int i = min(s[0], s[1]); i <= max(s[0], s[1]); i++) { - int per = i % (times[index][0] + times[index][1]); - if (per != 0 && per <= times[index][0]) { - return i; + int per = i % (times[index][0] + times[index][1]); //ħϴ ð + if (per != 0 && per <= times[index][0]) { //ð 1 ~ ٹ : Ŵ + return i; //߰ Ű ش ġ return } } } - return distance; } From e706af1ee867555a0eae2b92971b488fc2805e43 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Sat, 20 Aug 2022 20:51:33 +0900 Subject: [PATCH 203/822] =?UTF-8?q?=EC=95=84=EB=A6=84=EC=9D=B4=EA=B0=80=20?= =?UTF-8?q?=EA=B3=A0=EC=B3=90=EC=A4=80=20=ED=96=84=EB=B2=84=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" index 4d97456..23f45e8 100644 --- "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\235\264\354\247\200\354\234\244/[20220820_\353\252\250\354\235\230\352\263\240\354\202\254 3\355\232\214\354\260\250]no.2.py" @@ -13,9 +13,7 @@ def solution(ingredient): answer = 0 stack = [] for element in ingredient: - if not stack and element==1 : stack.append(element) - if stack : - stack.append(element) - if element==1 and checkIsHamburger(stack): - answer += 1 + stack.append(element) + if element == 1 and checkIsHamburger(stack): + answer += 1 return answer From f4ec8242ddb0b46351137f54215aaaf8308769a4 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 20 Aug 2022 21:16:04 +0900 Subject: [PATCH 204/822] =?UTF-8?q?=EC=BD=9C=EB=9D=BC=EB=8F=84=20=EB=AA=BB?= =?UTF-8?q?=ED=91=B8=EB=8A=94=20=EB=B0=94=EB=B3=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Solution1.java" | 27 +++++++ .../Solution2.java" | 77 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" new file mode 100644 index 0000000..55db9a3 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution1.java" @@ -0,0 +1,27 @@ +public class Solution1 { + public static void main(String[] args) { + Solution1 s = new Solution1(); + int a = 3; // 콜라를 받기 위해 마트에 주어야 하는 병 수 + int b = 1; // 빈병 a개를 가져다 주면 마늩가 주는 콜라 병 수 + int n = 20; // 가지고 있는 빈 병의 수 + + System.out.println(s.solution(a, b, n)); + } // End of main + + public int solution(int a, int b, int n) { + int totalCola = 0; + + if(n < a) { + return totalCola; + } + + while ( n >= a ) { // 보유중인 빈병과 콜라의 개수가 a개 미만이면, 멈춤 + + int cola = (n / a) * b; // 빈병으로 콜라 생성 + totalCola += cola; // 전체 받은 콜라 합산 + n = cola + (n % a); // 교환한 콜라병의 수 + 교환하지 못하고 남은 콜라 병의 수 + } + + return totalCola; + } // End of solution +} // End of Solution class \ No newline at end of file diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" new file mode 100644 index 0000000..9285c0d --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\265\234\354\260\275\354\230\201/Solution2.java" @@ -0,0 +1,77 @@ +import java.util.*; + +public class Solution2 { + static Stack ingredientStack = new Stack<>(); + static int totalBurger; + + public static void main(String[] args) { + Solution2 s = new Solution2(); + + int[] ingredient = {1, 3, 2, 1, 2, 1, 3, 1, 2}; + System.out.println(s.solution(ingredient)); + } // End of main + + // 포장하는 햄버거의 개수를 return + public int solution(int[] ingredient) { + totalBurger = 0; + int len = ingredient.length; + for (int i = 0; i < len; i++) { + ingredientStack.add(ingredient[i]); + + if (ingredientStack.size() >= 4) { + checking(); + } + } + + return totalBurger; + } // End of solution + + private static void checking() { + Stack tempStack = new Stack<>(); // 햄버거 순서가 맞지 않을 가능성을 대비해서 미리 배열을 만들어 둠 + boolean isPossible = true; + + for (int j = 0; j < 4; j++) { + int num = ingredientStack.peek(); + + if (j == 0) { + if (num == 1) { + tempStack.add(ingredientStack.pop()); // 맞으면 값을 빼서 temp에 저장 + } else { + isPossible = false; + break; + } + } else if (j == 1) { + if (num == 3) { + tempStack.add(ingredientStack.pop()); // 맞으면 값을 빼서 temp에 저장 + } else { + isPossible = false; + break; + } + } else if (j == 2) { + if (num == 2) { + tempStack.add(ingredientStack.pop()); // 맞으면 값을 빼서 temp에 저장 + } else { + isPossible = false; + break; + } + } else { + if (num == 1) { + tempStack.add(ingredientStack.pop()); // 맞으면 값을 빼서 temp에 저장 + totalBurger++; + return; + } else { + isPossible = false; + } + } + } + + // 만들 수 없는 경우, + if (!isPossible) { + // 덱을 다시 원래대로 + while (!tempStack.isEmpty()) { + ingredientStack.add(tempStack.pop()); + } + } + + } // End of checking +} // End of Solution class \ No newline at end of file From 3ac272811790ed7be99044f550ccc66358775fa8 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 20 Aug 2022 23:50:24 +0900 Subject: [PATCH 205/822] kihun --- .../1\353\262\210.py" | 9 ++ .../2\353\262\210.py" | 40 +++++++++ .../3\353\262\210.py" | 57 +++++++++++++ .../4\353\262\210.py" | 82 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" create mode 100644 "\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/4\353\262\210.py" diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" new file mode 100644 index 0000000..76050f4 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/1\353\262\210.py" @@ -0,0 +1,9 @@ +def solution(a, b, n): + sumValue = 0 + # n은 빈 병 + while n // a > 0: + nowEmpty = n // a + nowLeft = n % a + nowEmpty * b + sumValue += nowEmpty * b + n = nowLeft + return sumValue diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" new file mode 100644 index 0000000..62159d8 --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/2\353\262\210.py" @@ -0,0 +1,40 @@ +# 47.1점, 시간초과 +def solution(ingredient): + # 1:빵 2:야채 3:고기 + # 빵-야채-고기-빵 / 1 2 3 1 + answer = 0 + burger = [1, 2, 3, 1] + stack = [] + bIdx = 0 + i = 0 + while i < len(ingredient): + if i >= 3 and ingredient[i] == burger[3]: + if ingredient[i - 3 : i + 1] == burger[:]: + answer += 1 + ingredient = ingredient[: i - 3] + ingredient[i + 1 :] + i = 0 + i += 1 + return answer + + +# 100점 +def solution(ingredient): + # 1:빵 2:야채 3:고기 + # 빵-야채-고기-빵 / 1 2 3 1 + answer = 0 + burger = [1, 2, 3, 1] + i = 0 + while i < len(ingredient): + if i >= 3 and ingredient[i] == burger[3]: + if ingredient[i - 3 : i + 1] == burger[:]: + answer += 1 + ingredient.pop(i - 3) + ingredient.pop(i - 3) + ingredient.pop(i - 3) + ingredient.pop(i - 3) + if i - 5 < 0: + i = -1 + else: + i -= 5 + i += 1 + return answer diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" new file mode 100644 index 0000000..5a457ee --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/3\353\262\210.py" @@ -0,0 +1,57 @@ +distance = 12 +scope = [[7, 8], [4, 6], [11, 10]] +times = [[2, 2], [2, 4], [3, 3]] + +# distance = 10 +# scope = [[3, 4], [5, 8]] +# times = [[2, 5], [4, 3]] + +# 14.3점 시간초과 +def solution(distance, scope, times): + guardNum = len(scope) + guard = [[] for _ in range(guardNum)] + scopeRange = [[] for _ in range(guardNum)] + result = [] + + for i in range(guardNum): + scope[i].sort() + scopeRange[i] += [x for x in range(scope[i][0], scope[i][1] + 1)] + guard[i] += [x for x in range(1, times[i][0] + 1)] + tempGuard = guard[i][:] + for g in tempGuard: + j = 1 + while j * (times[i][0] + times[i][1]) + g <= distance: + guard[i].append(j * (times[i][0] + times[i][1]) + g) + j += 1 + for s in scopeRange[i]: + if s in guard[i]: + result.append(s) + break + + if not result: + answer = distance + else: + answer = min(result) + return answer + + +# 35.7점 +def solution(distance, scope, times): + for i in range(len(scope)): + minScope = min(scope[i]) + maxScope = max(scope[i]) + + loop = times[i][0] + times[i][1] + loopCount = minScope // loop + startScope = minScope - loop * loopCount + endScope = maxScope - loop * loopCount + + if startScope <= times[i][0]: + return minScope + if endScope > loop: + return maxScope + + return distance + + +print(solution(distance, scope, times)) diff --git "a/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/4\353\262\210.py" "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/4\353\262\210.py" new file mode 100644 index 0000000..868b1de --- /dev/null +++ "b/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\252\250\354\235\230\352\263\240\354\202\254/3\354\260\250_\353\254\270\354\240\234\354\247\221/\354\206\241\352\270\260\355\233\210/4\353\262\210.py" @@ -0,0 +1,82 @@ +# 6.3점 +# import itertools + +# n = 8 +# lighthouse = [[1, 2], [1, 3], [1, 4], [1, 5], [5, 6], [5, 7], [5, 8]] + +n = 10 +lighthouse = [[4, 1], [5, 1], [5, 6], [7, 6], [1, 2], [1, 3], [6, 8], [2, 9], [9, 10]] + +# def solution(n, lighthouse): +# node = [[] for _ in range(n + 1)] +# numbers = [i for i in range(1, n + 1)] +# for light in lighthouse: +# node[light[0]].append(light[1]) +# node[light[1]].append(light[0]) + +# for i in range(1, n + 1): +# combiList = [list(x) for x in itertools.combinations(numbers, i)] +# for combi in combiList: +# temp = [] +# for x in combi: +# temp.append(x) +# temp += node[x] +# temp = set(temp) +# temp = list(temp) +# if temp == numbers: +# return i +# return n + + +import sys + + +def solution(n, lighthouse): + sys.setrecursionlimit(10**9) + node = [[] for _ in range(n + 1)] + numbers = [i for i in range(1, n + 1)] + visited = [False for _ in range(n + 1)] + global result + result = [] + answer = 0 + + for light in lighthouse: + node[light[0]].append(light[1]) + node[light[1]].append(light[0]) + + def dfs(depth, temp, index): + global result + if depth == n: + check = [] + for j in temp: + # 자기 자신을 켜주고 포함된 연결된 노드도 켜줌 + check += [j] + check += node[j] + check = set(check) + check = list(check) + if check == numbers: + result.append(len(temp)) + return + return + + for i in range(index, n + 1): + # temp 리스트에 포함시키는 경우 + visited[i] = True + temp.append(i) + dfs(depth + 1, temp, i + 1) + + # 포함 안 시키는 경우 / 원상복구 + visited[i] = False + temp.pop() + dfs(depth + 1, temp, i + 1) + + dfs(0, [], 1) + + if not result: + answer = n + else: + answer = min(result) + return answer + + +print(solution(n, lighthouse)) From b3eb7b4eb63f784ba119963ea9ed2b947a8cec90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 21 Aug 2022 21:43:55 +0900 Subject: [PATCH 206/822] Create readme.md --- 0825/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 0825/readme.md diff --git a/0825/readme.md b/0825/readme.md new file mode 100644 index 0000000..7a29906 --- /dev/null +++ b/0825/readme.md @@ -0,0 +1,7 @@ +# 08.25(목) + +17471 게리맨더링 +https://www.acmicpc.net/problem/17471 + +17472 다리 만들기 2 +https://www.acmicpc.net/problem/17472 From 5452483bc558cb264f96284adea9d661dbead027 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 22 Aug 2022 18:09:37 +0900 Subject: [PATCH 207/822] kihun --- ...4\353\217\214\353\246\254\352\270\2604.py" | 37 +++++++++ ...60\355\224\204\353\246\254\355\204\260.py" | 82 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 "08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.py" create mode 100644 "08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3954_Brain_fk\354\235\270\355\204\260\355\224\204\353\246\254\355\204\260.py" diff --git "a/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.py" "b/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.py" new file mode 100644 index 0000000..e2a0586 --- /dev/null +++ "b/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.py" @@ -0,0 +1,37 @@ +import sys +import itertools +import copy + +sys.stdin = open("input.txt", "r", encoding="utf-8") + +n, m, k = map(int, input().split()) +matrix = [list(map(int, input().split())) for _ in range(n)] +rotateList = [list(map(int, input().split())) for _ in range(k)] +minValue = 999999999 + +for permute in itertools.permutations(rotateList, k): + tempMatrix = copy.deepcopy(matrix) + for p in permute: + r, c, s = p + r -= 1 + c -= 1 + for i in range(s, 0, -1): + temp = tempMatrix[r - i][c + i] + # 윗줄, 오른쪽으로 한칸씩 + tempMatrix[r - i][c - i + 1 : c + i + 1] = tempMatrix[r - i][c - i : c + i] + # 왼쪽줄, 위로 한칸씩 + for y in range(r - i, r + i): + tempMatrix[y][c - i] = tempMatrix[y + 1][c - i] + # 아랫줄, 왼쪽으로 한칸씩 + tempMatrix[r + i][c - i : c + i] = tempMatrix[r + i][c - i + 1 : c + i + 1] + # 오른쪽줄, 아래로 한칸씩 + for y in range(r + i, r - i, -1): + tempMatrix[y][c + i] = tempMatrix[y - 1][c + i] + # 마지막 값 끼워넣기 + tempMatrix[r - i + 1][c + i] = temp + for line in tempMatrix: + sumValue = sum(line) + if minValue > sumValue: + minValue = sumValue + +print(minValue) diff --git "a/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3954_Brain_fk\354\235\270\355\204\260\355\224\204\353\246\254\355\204\260.py" "b/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3954_Brain_fk\354\235\270\355\204\260\355\224\204\353\246\254\355\204\260.py" new file mode 100644 index 0000000..012520d --- /dev/null +++ "b/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3954_Brain_fk\354\235\270\355\204\260\355\224\204\353\246\254\355\204\260.py" @@ -0,0 +1,82 @@ +import sys + +# https://conak-diary.tistory.com/103 +sys.stdin = open("input.txt", "r", encoding="utf-8") + +t = int(input()) + + +def runCode(code): + global pointer, memorySize, inputIndex, inputSize, codeIndex, codeSize, maxCodeIndex + if code == "+": + memoryList[pointer] += 1 + if memoryList[pointer] == 256: + memoryList[pointer] = 0 + elif code == "-": + memoryList[pointer] -= 1 + if memoryList[pointer] == -1: + memoryList[pointer] = 255 + elif code == "<": + pointer -= 1 + if pointer == -1: + pointer = memorySize - 1 + elif code == ">": + pointer += 1 + if pointer == memorySize: + pointer = 0 + elif code == "[": + if memoryList[pointer] == 0: + codeIndex = jumpList[codeIndex] + elif code == "]": + if memoryList[pointer] != 0: + codeIndex = jumpList[codeIndex] + elif code == ".": + pass + elif code == ",": + if inputIndex < inputSize: + memoryList[pointer] = ord(inputList[inputIndex]) + inputIndex += 1 + else: + memoryList[pointer] = 255 + codeIndex += 1 + maxCodeIndex = max(maxCodeIndex, codeIndex) + + +def loopCheck(): + global codeIndex, codeSize, maxCodeIndex + count = 0 + while codeIndex < codeSize: + count += 1 + runCode(codeList[codeIndex]) + if count >= 50000000: + print("Loops", jumpList[maxCodeIndex], maxCodeIndex) + return + print("Terminates") + return + + +for test_case in range(t): + memorySize, codeSize, inputSize = map(int, input().split()) + codeList = list(input()) + inputList = list(input()) + + memoryList = [0] * memorySize + jumpList = [0] * codeSize + saveList = [-1] * (codeSize // 2) + pointer = 0 + codeIndex = 0 + inputIndex = 0 + maxCodeIndex = 0 + + count = 0 + for i in range(len(codeList)): + if codeList[i] == "[": + saveList[count] = i + count += 1 + elif codeList[i] == "]": + count -= 1 + jumpList[saveList[count]] = i + jumpList[i] = saveList[count] + saveList[count] = -1 + + loopCheck() From f1fe45ac9102dbd909feb909e8ddef331fb1323c Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 22 Aug 2022 19:50:50 +0900 Subject: [PATCH 208/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=8017406.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\20017406.java" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "08.22/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017406.java" diff --git "a/08.22/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017406.java" "b/08.22/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017406.java" new file mode 100644 index 0000000..9be3cb4 --- /dev/null +++ "b/08.22/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017406.java" @@ -0,0 +1,108 @@ +package etc; + +import java.util.Scanner; + +public class 백준17406 { +static int k,min=Integer.MAX_VALUE,n,m; +static boolean [] visited; +static int[] tmp_order; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + n=scan.nextInt(); + m=scan.nextInt(); + k=scan.nextInt(); //회전 연산의 개수 + visited=new boolean[k]; + tmp_order=new int[k]; + int arr[][]=new int[n][m]; + int rot[][]=new int[k][3]; + + for(int i=0;i y1; i--) { + copy_arr[x1][i] = copy_arr[x1][i - 1]; + } + + for(int i = x2; i > x1; i--) { + if(i == x1 + 1) { //마지막 + copy_arr[i][y2] = a; + } + else copy_arr[i][y2] = copy_arr[i - 1][y2]; + } + + for(int i = y1; i < y2; i++) { + if(i == y2 - 1) { + copy_arr[x2][i] = b; + } + else copy_arr[x2][i] = copy_arr[x2][i + 1]; + } + + for(int i = x1; i < x2; i++) { + if(i == x2 - 1) { + copy_arr[i][y1] = c; + } + else copy_arr[i][y1] = copy_arr[i + 1][y1]; + } + + rotation(x1 + 1, y1 + 1, x2 - 1, y2 - 1, copy_arr); + } + +} From 5634c3508aee31c997072b58e95f5eb275b550a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 22 Aug 2022 20:37:38 +0900 Subject: [PATCH 209/822] Update readme.md --- 0825/readme.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/0825/readme.md b/0825/readme.md index 7a29906..32a296f 100644 --- a/0825/readme.md +++ b/0825/readme.md @@ -1,7 +1,5 @@ # 08.25(목) -17471 게리맨더링 -https://www.acmicpc.net/problem/17471 - -17472 다리 만들기 2 -https://www.acmicpc.net/problem/17472 +1. https://www.acmicpc.net/problem/14889 스타트와 링크 +2. https://www.acmicpc.net/problem/14501 퇴사 +3. https://www.acmicpc.net/problem/14502 연구소 From 3238d9bbdc5f5edcc83b78ff59edd51e3fda822d Mon Sep 17 00:00:00 2001 From: dldkfma9577 Date: Tue, 23 Aug 2022 22:04:19 +0900 Subject: [PATCH 210/822] =?UTF-8?q?[=EC=9D=B4=EC=95=84=EB=A6=84]=2014501?= =?UTF-8?q?=5F=ED=87=B4=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {0825 => 08.25}/readme.md | 0 .../14501_\355\207\264\354\202\254.cpp" | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+) rename {0825 => 08.25}/readme.md (100%) create mode 100644 "08.25/\354\235\264\354\225\204\353\246\204/14501_\355\207\264\354\202\254.cpp" diff --git a/0825/readme.md b/08.25/readme.md similarity index 100% rename from 0825/readme.md rename to 08.25/readme.md diff --git "a/08.25/\354\235\264\354\225\204\353\246\204/14501_\355\207\264\354\202\254.cpp" "b/08.25/\354\235\264\354\225\204\353\246\204/14501_\355\207\264\354\202\254.cpp" new file mode 100644 index 0000000..774e2e4 --- /dev/null +++ "b/08.25/\354\235\264\354\225\204\353\246\204/14501_\355\207\264\354\202\254.cpp" @@ -0,0 +1,24 @@ +#include +#include +using namespace std; +int main() { + int N; cin >> N; + vector> board; + vector maxMoney(N + 1,0); + for (int i = 0; i < N; i++) { + int T, P; cin >> T >> P; + board.push_back({ T,P }); + } + for (int i = N - 1; i >= 0; i--) { + int now; + if (i + board[i][0] > N) { + now = 0; + } + else { + now = maxMoney[i + board[i][0]] + board[i][1]; + } + maxMoney[i] = max(now, maxMoney[i + 1]); + } + cout << maxMoney[0] << endl; + return 0; +} \ No newline at end of file From 9233c1392fdaeb1413c993c26fc75ba1cbdc8082 Mon Sep 17 00:00:00 2001 From: dldkfma9577 Date: Tue, 23 Aug 2022 22:55:18 +0900 Subject: [PATCH 211/822] =?UTF-8?q?[=EC=9D=B4=EC=95=84=EB=A6=84]=2014889?= =?UTF-8?q?=5F=EC=8A=A4=ED=83=80=ED=8A=B8=EC=99=80=20=EB=A7=81=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\231\200 \353\247\201\355\201\254.cpp" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "08.25/\354\235\264\354\225\204\353\246\204/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.cpp" diff --git "a/08.25/\354\235\264\354\225\204\353\246\204/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.cpp" "b/08.25/\354\235\264\354\225\204\353\246\204/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.cpp" new file mode 100644 index 0000000..434d86e --- /dev/null +++ "b/08.25/\354\235\264\354\225\204\353\246\204/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.cpp" @@ -0,0 +1,69 @@ +#include +#include +#include +#include +using namespace std; + +bool visited[21] = { false }; +int selected[11] = { 0 }; +vector> board; +int minDiff = INT_MAX; +int N; +void getDiff() { + vector deSelected; + int index = 0; + for (int i = 0; i < N; i++) { + if (i == selected[index]) { + index++; + } + else { + deSelected.push_back(i); + } + } + int sumSel = 0; + int sumDeSel = 0; + for (int i = 0; i < N / 2; i++) { + for (int k = 0; k < N / 2; k++) { + if (i == k) continue; + sumSel += board[selected[i]][selected[k]]; + sumDeSel += board[deSelected[i]][deSelected[k]]; + } + } + minDiff = min(minDiff, abs(sumSel - sumDeSel)); +} + +void makeSelect(int count) { + if (minDiff == 0) return; + if (count == N / 2) { + getDiff(); + return; + } + int limit = 0; + if (count != 0) { + limit = selected[count - 1] + 1; + } + for (int i = limit; i < N; i++) { + if (!visited[i]) { + visited[i] = true; + selected[count] = i; + makeSelect(count + 1); + visited[i] = false; + } + } +} + + +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < N; k++) { + int input; cin >> input; + tmp.push_back(input); + } + board.push_back(tmp); + } + makeSelect(0); + cout << minDiff << endl; + return 0; +} \ No newline at end of file From 12a441fe05b76e55d2153ed8369923ea48275f73 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 23 Aug 2022 23:27:01 +0900 Subject: [PATCH 212/822] solve --- ...354\231\200 \353\247\201\355\201\254.java" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "08.25/\354\241\260\354\210\230\354\227\260/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.java" diff --git "a/08.25/\354\241\260\354\210\230\354\227\260/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.java" "b/08.25/\354\241\260\354\210\230\354\227\260/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.java" new file mode 100644 index 0000000..6948168 --- /dev/null +++ "b/08.25/\354\241\260\354\210\230\354\227\260/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.java" @@ -0,0 +1,89 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int[][] team; + static boolean[] visited; + static int[] start; + static int[] link; + static int min = Integer.MAX_VALUE; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + N = Integer.parseInt(br.readLine()); + team = new int[N + 1][N + 1]; //1부터 시작인덱스 + + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + team[i][j] = Integer.parseInt(token.nextToken()); + } + } + + visited = new boolean[N + 1]; + + combination(1,0); + + System.out.println(min); + } + + static void combination(int index, int size) { + + if (min == 0) { //최솟값이 0이면 탐색종료 + return; + } + + if (size == N / 2) { //N/2일 때 팀 인원 배치한것을 기준으로 계산 시작 + min = Math.min(min,getMin()); + return; + } + + for (int i = index; i <= N; i++) { + if (!visited[i]) { + visited[i] = true; + combination(i+1,size + 1); + visited[i] = false; + } + } + } + + static int getMin() { + + int diff = Integer.MAX_VALUE; + + start = new int[N / 2]; + link = new int[N / 2]; + + int sIndex = 0; + int lIndex = 0; + + for (int i = 1; i < visited.length; i++) { //true인 곳은 start false인 곳은 link + if (visited[i]) { + start[sIndex] = i; + sIndex++; + }else { + link[lIndex] = i; + lIndex++; + } + } + + int sSum = 0; + int lSum = 0; + + for (int i = 0; i < start.length; i++) { //team[i][i]는 0이므로 이중포문으로 팀 능력치 계산 + for (int j = 0; j < start.length; j++) { + sSum += team[start[i]][start[j]]; + lSum += team[link[i]][link[j]]; + } + } + + diff = Math.abs(sSum - lSum); + + return diff; + + } +} From c94470fda7a135c522a7c130ea4d527f81e4c310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 24 Aug 2022 11:08:44 +0900 Subject: [PATCH 213/822] =?UTF-8?q?Create=2014502=5F=EC=97=B0=EA=B5=AC?= =?UTF-8?q?=EC=86=8C.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\354\227\260\352\265\254\354\206\214.cpp" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "08.25/\354\235\264\354\225\204\353\246\204/14502_\354\227\260\352\265\254\354\206\214.cpp" diff --git "a/08.25/\354\235\264\354\225\204\353\246\204/14502_\354\227\260\352\265\254\354\206\214.cpp" "b/08.25/\354\235\264\354\225\204\353\246\204/14502_\354\227\260\352\265\254\354\206\214.cpp" new file mode 100644 index 0000000..708ec6f --- /dev/null +++ "b/08.25/\354\235\264\354\225\204\353\246\204/14502_\354\227\260\352\265\254\354\206\214.cpp" @@ -0,0 +1,84 @@ +#include +#include +#include +using namespace std; + +vector> board; +int wallX[3] = { 0 }; +int wallY[3] = { 0 }; +int N, M; +int maxSafe = 0; +vector> virus; + +void getSafe() { + vector> copy_board(board.begin(), board.end()); + queue> q; //x,y + for (auto v : virus) { + q.push({ v.first,v.second }); + } + int dx[] = { -1,0,1,0 }; + int dy[] = { 0,1,0,-1 }; + while (!q.empty()) { + int x = q.front()[0]; + int y = q.front()[1]; q.pop(); + for (int i = 0; i < 4; i++) { + int xx = x + dx[i]; + int yy = y + dy[i]; + if (0 <= xx && xx < N && 0 <= yy && yy < M) { + if (copy_board[xx][yy] == 0) { + q.push({ xx,yy }); + copy_board[xx][yy] = 2; + } + } + } + } + int count = 0; + for (int i = 0; i < N; i++) { + for (int k = 0; k < M; k++) { + if (copy_board[i][k] == 0) { + count++; + } + } + } + maxSafe = max(maxSafe, count); +} + +void getWall(int count) { + if (count == 3) { + getSafe(); + return; + } + if (maxSafe == M * N) return; + int x = count == 0 ? 0 : wallX[count - 1]; + int y = count == 0 ? 0 : wallY[count - 1] + 1; + for (int i = x; i < N; i++) { + for (; y < M; y++) { + if (board[i][y] == 0) { + wallX[count] = i; wallY[count] = y; + board[i][y] = 1; + getWall(count + 1); + board[i][y] = 0; + } + } + y = 0; + } + +} + +int main() { + cin >> N >> M; + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < M; k++) { + int input; cin >> input; + tmp.push_back(input); + if (input == 2) { + virus.push_back({ i,k }); + } + } + board.push_back(tmp); + } + getWall(0); + cout << maxSafe << endl; + return 0; +} From ab694b2da312bf6d1bbb599569ae48ceee13706a Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 24 Aug 2022 23:35:48 +0900 Subject: [PATCH 214/822] solve --- ...\354\227\260\352\265\254\354\206\214.java" | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 "08.25/\354\241\260\354\210\230\354\227\260/14502_\354\227\260\352\265\254\354\206\214.java" diff --git "a/08.25/\354\241\260\354\210\230\354\227\260/14502_\354\227\260\352\265\254\354\206\214.java" "b/08.25/\354\241\260\354\210\230\354\227\260/14502_\354\227\260\352\265\254\354\206\214.java" new file mode 100644 index 0000000..5d49a7c --- /dev/null +++ "b/08.25/\354\241\260\354\210\230\354\227\260/14502_\354\227\260\352\265\254\354\206\214.java" @@ -0,0 +1,111 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int M; + static int[][] laboratory; + static int[][] copy; + static List virusList; + static int[] dx = { 0, 0, -1, 1 }; + static int[] dy = { -1, 1, 0, 0 }; + static boolean[][] visited; + static int max = Integer.MIN_VALUE; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + + laboratory = new int[N][M]; + copy = new int[N][M]; //깊은 복사 배열 + virusList = new ArrayList(); + + for (int i = 0; i < N; i++) { + token = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + laboratory[i][j] = Integer.parseInt(token.nextToken()); + copy[i][j] = laboratory[i][j]; + if (laboratory[i][j] == 2) { //바이러스 좌표 넣기 + virusList.add(new Point(j, i)); + } + } + } + + setting(0, 0); + + System.out.println(max); + + } + + static void copy(int[][] temp) { //복사 + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + temp[i][j] = laboratory[i][j]; + } + } + } + + static void setting(int size, int start) { + if (size == 3) { //벽을 3개 쳤을 때 최댓값 + max = Math.max(virus(),max); + return; + } + + for (int i = start; i < N * M; i++) { //0,0부터 laboratory[i][j]가 0인 곳에 벽 설치하기 + int row = i / M; + int col = i % M; + if (laboratory[row][col] == 0) { + laboratory[row][col] = 1; + setting(size + 1, i + 1); + laboratory[row][col] = 0; + } + } + } + + static int virus() { + int count = 0; + Queue queue = new LinkedList(); + visited = new boolean[N][M]; + + int temp[][] = new int[N][M]; + + copy(temp); //임시 배열 복사 + + for (int i = 0; i < virusList.size(); i++) { //바이러스 좌표를 queue에 poll + queue.add(new Point(virusList.get(i).x, virusList.get(i).y)); + visited[virusList.get(i).y][virusList.get(i).x] = true; + } + + while (!queue.isEmpty()) { //바이러스 퍼지는 메소드 + Point point = queue.poll(); + for (int i = 0; i < dx.length; i++) { + int x = point.x + dx[i]; + int y = point.y + dy[i]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && temp[y][x] == 0) { + visited[y][x] = true; + temp[y][x] = 2; + queue.add(new Point(x,y)); + } + } + + + } + + for (int i = 0; i < N; i++) { //안전영역 구하기 + for (int j = 0; j < M; j++) { + if (temp[i][j] == 0 ) { + count++; + } + } + } + + return count; + } +} From 3a4938ac35f65244393768d911fe87ed45b759b8 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Wed, 24 Aug 2022 23:56:24 +0900 Subject: [PATCH 215/822] complete --- .../Main_14501_\355\207\264\354\202\254.java" | 37 +++++ ...\354\227\260\352\265\254\354\206\214.java" | 132 ++++++++++++++++++ ...\354\231\200\353\247\201\355\201\254.java" | 77 ++++++++++ 3 files changed, 246 insertions(+) create mode 100644 "08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" create mode 100644 "08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" create mode 100644 "08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" diff --git "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" new file mode 100644 index 0000000..d38c93c --- /dev/null +++ "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" @@ -0,0 +1,37 @@ +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/14501 +public class Main_14501_퇴사 { + static int[][] arr; + static int N; + static int max = -1; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/14501.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + arr = new int[N][2]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + arr[i][0] = Integer.parseInt(st.nextToken()); + arr[i][1] = Integer.parseInt(st.nextToken()); + } + + DP(0, 0); + System.out.println(max); + } // End of main + + private static void DP(int depth, int total) { + if (depth == N) { + max = Math.max(max, total); + return; + } else if (depth > N) { + return; + } + + DP(depth + 1, total); + DP(depth + arr[depth][0], total + arr[depth][1]); + } // End of DP +} // End of Main class \ No newline at end of file diff --git "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" new file mode 100644 index 0000000..6a092ab --- /dev/null +++ "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" @@ -0,0 +1,132 @@ +import java.util.*; +import java.io.*; + +// 문제 : https://www.acmicpc.net/problem/14502 +// 목표 : 0은 빈칸, 1은 벽, 2는 바이러스가 있는 곳. +// 벽이 없으면 바이러스는 모든 빈칸으로 펴저나갈 수 있다. + +public class Main_14502_연구소 { + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + static int arr[][]; + + static int result = Integer.MIN_VALUE / 16; + static int nowX, nowY, N, M; + + static class Node { + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_14502.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 가로 + M = Integer.parseInt(st.nextToken());// 세로 + + arr = new int[N][M]; + + // 연구소와 똑같은 지도 배열 생성. + for(int i=0; i que = new LinkedList<>(); + + //벽을 만들어놓은 배열을 그대로 지도로 카피 + for(int i=0; i= 0 && nowX < N && nowY >= 0 && nowY < M); + } // End of Range_check + +} // End of class \ No newline at end of file diff --git "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" new file mode 100644 index 0000000..0102b02 --- /dev/null +++ "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" @@ -0,0 +1,77 @@ +import java.util.*; +import java.io.*; + +public class Main_14889_스타트와링크 { + static int arr[][]; + static boolean visit[]; + static int N; + + static int result = Integer.MAX_VALUE; // 최소값 결과 값 + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_14889.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + arr = new int[N][N]; + visit = new boolean[N]; + + for(int i=0; i Date: Thu, 25 Aug 2022 00:23:24 +0900 Subject: [PATCH 216/822] complete --- .../Main_14501_\355\207\264\354\202\254.java" | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" index d38c93c..e7baa12 100644 --- "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" +++ "b/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" @@ -5,7 +5,7 @@ public class Main_14501_퇴사 { static int[][] arr; static int N; - static int max = -1; + static int result = -1; public static void main(String[] args) throws Exception { System.setIn(new FileInputStream("res/14501.txt")); @@ -19,19 +19,19 @@ public static void main(String[] args) throws Exception { arr[i][1] = Integer.parseInt(st.nextToken()); } - DP(0, 0); - System.out.println(max); + quit(0, 0); + System.out.println(result); } // End of main - private static void DP(int depth, int total) { - if (depth == N) { - max = Math.max(max, total); + private static void quit(int day, int totalPrice) { + if (day == N) { + result = Math.max(result, totalPrice); return; - } else if (depth > N) { + } else if (day > N) { return; } - DP(depth + 1, total); - DP(depth + arr[depth][0], total + arr[depth][1]); + quit(day + 1, totalPrice); // depth는 날짜를 의미하는데, 해당 날짜에 상담을 하지 않고, 넘기는 경우의 수 + quit(day + arr[day][0], totalPrice + arr[day][1]); // 해당 날짜에 상담을 진행하는 경우의 수 } // End of DP } // End of Main class \ No newline at end of file From 3e7f348d80eec708e2d690c2459e39eeca081c3c Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Thu, 25 Aug 2022 00:39:48 +0900 Subject: [PATCH 217/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=80=2014502.jav?= =?UTF-8?q?a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 14502.java" | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 "08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 14502.java" diff --git "a/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 14502.java" "b/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 14502.java" new file mode 100644 index 0000000..787f845 --- /dev/null +++ "b/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 14502.java" @@ -0,0 +1,98 @@ +package etc; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; +class pos{ + int x; + int y; + pos(int x,int y){ + this.x=x; + this.y=y; + } +} +public class 백준14502 { + static int max=Integer.MIN_VALUE; + static int n,m; + static int wall_num=0; + static int[][] arr; + static ArrayList vir; + static int [] dx= {-1,1,0,0}; + static int [] dy= {0,0,-1,1}; + public static void main(String[] args) { + // 1: 벽 2: 바이러스 벽 세개 세울수 있음 안전영역의 최댓값 + Scanner scan=new Scanner(System.in); + n=scan.nextInt(); + m=scan.nextInt(); + arr=new int[n][m]; + vir=new ArrayList(); + for(int i=0;i q=new LinkedList<>(); + q.offer(new pos(x,y)); + + while(!q.isEmpty()) { + pos now=q.poll(); + for(int i=0;i<4;i++) { + int nx=now.x+dx[i]; + int ny=now.y+dy[i]; + if(nx>=0&&ny>=0&&nx Date: Thu, 25 Aug 2022 02:43:12 +0900 Subject: [PATCH 218/822] =?UTF-8?q?Create=20=EC=8A=A4=ED=83=80=ED=8A=B8?= =?UTF-8?q?=EC=99=80=EB=A7=81=ED=81=AC=5F14889?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 최종 --- ...354\231\200\353\247\201\355\201\254_14889" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "08.25/\354\240\225\355\230\270\354\241\260/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" diff --git "a/08.25/\354\240\225\355\230\270\354\241\260/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" "b/08.25/\354\240\225\355\230\270\354\241\260/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" new file mode 100644 index 0000000..aed538d --- /dev/null +++ "b/08.25/\354\240\225\355\230\270\354\241\260/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" @@ -0,0 +1,73 @@ +package baekjoon; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class 스타트와링크_14889 { + + static int[][] arr; + static boolean[] vis; + static int N; + static int ans = Integer.MAX_VALUE;; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + arr = new int[N][N]; + vis = new boolean[N]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + combination(0, 0); + System.out.println(ans); + } + + static void combination(int index, int cnt) { + if (cnt== N/2) { + cal(); + return; + } + + // 조합으로 팀 나눠줌 + for (int i = index; i < N; i++) { + if (vis[i] == false) { + vis[i] = true; + combination(i+ 1, cnt+1); + vis[i] = false; + } + + } + } + + static void cal() { + int startteam=0; // 초기화 시점 신경쓸것!!!!! + int linkteam=0; + + for (int i = 0; i < N - 1; i++) { // 순열을 따로 만들어주지 않고 팀이 배정되면 그 안에서 for문으로 해결 + for (int j = i + 1; j < N; j++) { + if (vis[i] == true && vis[j] == true) { // vis == ture면 startteam, false면 linkteam으로 배정 + startteam += arr[i][j]; + startteam += arr[j][i]; + } else if (vis[i] == false && vis[j] == false) { + linkteam += arr[i][j]; + linkteam += arr[j][i]; + } + } + } + int result = Math.abs(startteam - linkteam); + + if (result == 0) { + System.out.println(result); + System.exit(0); + } + ans = Math.min(ans, result); + } +} From 02f9bf74ef406e1dd3a9cc9c04cbd0585c214c80 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 25 Aug 2022 02:43:30 +0900 Subject: [PATCH 219/822] =?UTF-8?q?=EC=B5=9C=EC=A2=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\231\200\353\247\201\355\201\254_14889" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" diff --git "a/08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" "b/08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" new file mode 100644 index 0000000..aed538d --- /dev/null +++ "b/08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" @@ -0,0 +1,73 @@ +package baekjoon; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class 스타트와링크_14889 { + + static int[][] arr; + static boolean[] vis; + static int N; + static int ans = Integer.MAX_VALUE;; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + arr = new int[N][N]; + vis = new boolean[N]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + combination(0, 0); + System.out.println(ans); + } + + static void combination(int index, int cnt) { + if (cnt== N/2) { + cal(); + return; + } + + // 조합으로 팀 나눠줌 + for (int i = index; i < N; i++) { + if (vis[i] == false) { + vis[i] = true; + combination(i+ 1, cnt+1); + vis[i] = false; + } + + } + } + + static void cal() { + int startteam=0; // 초기화 시점 신경쓸것!!!!! + int linkteam=0; + + for (int i = 0; i < N - 1; i++) { // 순열을 따로 만들어주지 않고 팀이 배정되면 그 안에서 for문으로 해결 + for (int j = i + 1; j < N; j++) { + if (vis[i] == true && vis[j] == true) { // vis == ture면 startteam, false면 linkteam으로 배정 + startteam += arr[i][j]; + startteam += arr[j][i]; + } else if (vis[i] == false && vis[j] == false) { + linkteam += arr[i][j]; + linkteam += arr[j][i]; + } + } + } + int result = Math.abs(startteam - linkteam); + + if (result == 0) { + System.out.println(result); + System.exit(0); + } + ans = Math.min(ans, result); + } +} From 96f293709b2a436bf2303dd5056b961544bf9581 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 25 Aug 2022 02:43:53 +0900 Subject: [PATCH 220/822] =?UTF-8?q?Delete=20=EC=8A=A4=ED=83=80=ED=8A=B8?= =?UTF-8?q?=EC=99=80=EB=A7=81=ED=81=AC=5F14889?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\231\200\353\247\201\355\201\254_14889" | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 "08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" diff --git "a/08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" "b/08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" deleted file mode 100644 index aed538d..0000000 --- "a/08.25/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" +++ /dev/null @@ -1,73 +0,0 @@ -package baekjoon; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.IOException; -import java.util.StringTokenizer; - -public class 스타트와링크_14889 { - - static int[][] arr; - static boolean[] vis; - static int N; - static int ans = Integer.MAX_VALUE;; - - public static void main(String[] args) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - N = Integer.parseInt(br.readLine()); - - arr = new int[N][N]; - vis = new boolean[N]; - - for (int i = 0; i < N; i++) { - StringTokenizer st = new StringTokenizer(br.readLine(), " "); - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - } - } - - combination(0, 0); - System.out.println(ans); - } - - static void combination(int index, int cnt) { - if (cnt== N/2) { - cal(); - return; - } - - // 조합으로 팀 나눠줌 - for (int i = index; i < N; i++) { - if (vis[i] == false) { - vis[i] = true; - combination(i+ 1, cnt+1); - vis[i] = false; - } - - } - } - - static void cal() { - int startteam=0; // 초기화 시점 신경쓸것!!!!! - int linkteam=0; - - for (int i = 0; i < N - 1; i++) { // 순열을 따로 만들어주지 않고 팀이 배정되면 그 안에서 for문으로 해결 - for (int j = i + 1; j < N; j++) { - if (vis[i] == true && vis[j] == true) { // vis == ture면 startteam, false면 linkteam으로 배정 - startteam += arr[i][j]; - startteam += arr[j][i]; - } else if (vis[i] == false && vis[j] == false) { - linkteam += arr[i][j]; - linkteam += arr[j][i]; - } - } - } - int result = Math.abs(startteam - linkteam); - - if (result == 0) { - System.out.println(result); - System.exit(0); - } - ans = Math.min(ans, result); - } -} From dd9cd82e2c8ee4c13ca24208bb0b9c7b43406d86 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 25 Aug 2022 02:44:47 +0900 Subject: [PATCH 221/822] =?UTF-8?q?=ED=87=B4=EC=82=AC=5F14501?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\207\264\354\202\254_14501" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "08.25/\354\240\225\355\230\270\354\241\260/\355\207\264\354\202\254_14501" diff --git "a/08.25/\354\240\225\355\230\270\354\241\260/\355\207\264\354\202\254_14501" "b/08.25/\354\240\225\355\230\270\354\241\260/\355\207\264\354\202\254_14501" new file mode 100644 index 0000000..339442b --- /dev/null +++ "b/08.25/\354\240\225\355\230\270\354\241\260/\355\207\264\354\202\254_14501" @@ -0,0 +1,41 @@ +package baekjoon; + +import java.util.*; +import java.io.*; + +public class 퇴사_14501 { + static int[] t, p; + static boolean[] vis; + static int N, ans, result; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + t = new int[N + 1]; + p = new int[N + 1]; + vis = new boolean[N]; + ans = Integer.MIN_VALUE; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + t[i] = Integer.parseInt(st.nextToken()); + p[i] = Integer.parseInt(st.nextToken()); + } + + combination(0, 0); + System.out.println(ans); + } + + static void combination(int day, int sum) { + if (day == N) { + ans = Math.max(ans, sum); + return; + } + if (day > N) + return; + combination(day + t[day], sum + p[day]); + combination(day + 1, sum); + } +} From 9deeade95663ab79fe9859526b54b7678d1ec3dd Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 25 Aug 2022 02:46:23 +0900 Subject: [PATCH 222/822] =?UTF-8?q?=EC=97=B0=EA=B5=AC=EC=86=8C=5F14502?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\227\260\352\265\254\354\206\214_14502" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "08.25/\354\240\225\355\230\270\354\241\260/\354\227\260\352\265\254\354\206\214_14502" diff --git "a/08.25/\354\240\225\355\230\270\354\241\260/\354\227\260\352\265\254\354\206\214_14502" "b/08.25/\354\240\225\355\230\270\354\241\260/\354\227\260\352\265\254\354\206\214_14502" new file mode 100644 index 0000000..3074c0a --- /dev/null +++ "b/08.25/\354\240\225\355\230\270\354\241\260/\354\227\260\352\265\254\354\206\214_14502" @@ -0,0 +1,108 @@ +package baekjoon; + +import java.util.*; +import java.io.*; + +public class 연구소_14502 { + static int[] dx = {1, -1, 0, 0}; + static int[] dy = {0, 0, 1, -1}; + static int[][] arr, copy; + static boolean[][] vis; + static int n, m, ans; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + + arr = new int[n][m]; + ans = Integer.MIN_VALUE; + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < m; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + dfs(0); + System.out.println(ans); + } + + //벽 놓을 자리 3개 뽑음 + static void dfs(int index) { + if (index == 3) { + bfs(); + return; + } + for (int i = 0; i < n; i++) { //순서대로 가는데 굳이 vis할 필요 없음 + for (int j = 0; j < m; j++) { + if (arr[i][j] == 0) { + arr[i][j] = 1; + dfs(index + 1); + arr[i][j] = 0; + + } + } + } + } + + //벽 놓은 이후 바이러스 퍼짐 + static void bfs() { + vis = new boolean[n][m]; + copy = new int[n][m]; + for(int i=0; i q = new LinkedList<>(); + for(int i=0; i Date: Thu, 25 Aug 2022 09:28:51 +0900 Subject: [PATCH 223/822] kihun --- ...244\200_14501_\355\207\264\354\202\254.py" | 31 ++++++++++ ...2_\354\227\260\352\265\254\354\206\214.py" | 56 +++++++++++++++++++ ...70\354\231\200\353\247\201\355\201\254.py" | 46 +++++++++++++++ ...354\231\200\353\247\201\355\201\254DFS.py" | 38 +++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14501_\355\207\264\354\202\254.py" create mode 100644 "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14502_\354\227\260\352\265\254\354\206\214.py" create mode 100644 "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.py" create mode 100644 "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254DFS.py" diff --git "a/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14501_\355\207\264\354\202\254.py" "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14501_\355\207\264\354\202\254.py" new file mode 100644 index 0000000..39f572f --- /dev/null +++ "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14501_\355\207\264\354\202\254.py" @@ -0,0 +1,31 @@ +import sys + +sys.stdin = open("input.txt", + "r", encoding="utf-8") + +n = int(input()) +matrix = [list(map(int, input().split())) for _ in range(n)] +maxValue = -999999999 + + +def dfs(index, tempSum): + global maxValue + if index >= n: + if maxValue < tempSum: + maxValue = tempSum + return + return + day = matrix[index][0] + pay = matrix[index][1] + # 안 더하고 돌림 + dfs(index + 1, tempSum) + + # 범위 안이라면 더하고 돌림 + if index + day <= n: + tempSum += pay + dfs(index + day, tempSum) + + +dfs(0, 0) + +print(maxValue) diff --git "a/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14502_\354\227\260\352\265\254\354\206\214.py" "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14502_\354\227\260\352\265\254\354\206\214.py" new file mode 100644 index 0000000..e67bf92 --- /dev/null +++ "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14502_\354\227\260\352\265\254\354\206\214.py" @@ -0,0 +1,56 @@ +import sys +import copy +from collections import deque +sys.stdin = open("input.txt", "r", encoding="utf-8") + +input = sys.stdin.readline +n, m = map(int, input().split()) +matrix = [list(map(int, input().split())) for _ in range(n)] + +maxValue = -999999999 +dy = [0, 0, 1, -1] +dx = [1, -1, 0, 0] + + +def bfs(): + global maxValue + q = deque() + temp = copy.deepcopy(matrix) + for y in range(n): + for x in range(m): + if temp[y][x] == 2: + q.append((y, x)) + while q: + y, x = q.popleft() + for i in range(4): + nY = y + dy[i] + nX = x + dx[i] + if 0 <= nY < n and 0 <= nX < m and temp[nY][nX] == 0: + temp[nY][nX] = 2 + q.append((nY, nX)) + + count = 0 + for y in range(n): + for x in range(m): + if temp[y][x] == 0: + count += 1 + + if maxValue < count: + maxValue = count + + +def pickThree(count): + if count == 3: + bfs() + return + for y in range(n): + for x in range(m): + if matrix[y][x] == 0: + matrix[y][x] = 1 + pickThree(count + 1) + matrix[y][x] = 0 + + +pickThree(0) + +print(maxValue) diff --git "a/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.py" "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.py" new file mode 100644 index 0000000..7392263 --- /dev/null +++ "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.py" @@ -0,0 +1,46 @@ +import sys +import itertools + +sys.stdin = open("C:/SSAFY/clone/Algorithm_SSAFY/input.txt", + "r", encoding="utf-8") + +input = sys.stdin.readline + +n = int(input()) +matrix = [list(map(int, input().split())) for _ in range(n)] +allMembers = [i for i in range(n)] +visited = [False for _ in range(n)] +half = n // 2 +minValue = 999999999 + +teamList = [list(combi) for combi in itertools.combinations(allMembers, half)] + +idx = 0 +halfTeamList = len(teamList) // 2 + + +def teamDiff(teamA, teamB): + totalA, totalB = 0, 0 + aCombi = list(itertools.combinations(teamA, 2)) + bCombi = list(itertools.combinations(teamB, 2)) + + for i in range(len(aCombi)): + totalA += matrix[aCombi[i][0]][aCombi[i][1]] + \ + matrix[aCombi[i][1]][aCombi[i][0]] + totalB += matrix[bCombi[i][0]][bCombi[i][1]] + \ + matrix[bCombi[i][1]][bCombi[i][0]] + + return abs(totalA - totalB) + + +for team in teamList: + if idx == halfTeamList: + break + otherTeam = [x for x in allMembers if x not in team] + diff = teamDiff(team, otherTeam) + + if diff < minValue: + minValue = diff + idx += 1 + +print(minValue) diff --git "a/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254DFS.py" "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254DFS.py" new file mode 100644 index 0000000..5aaca3d --- /dev/null +++ "b/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254DFS.py" @@ -0,0 +1,38 @@ +import sys + +sys.stdin = open("C:/SSAFY/clone/Algorithm_SSAFY/input.txt", + "r", encoding="utf-8") + +input = sys.stdin.readline + +n = int(input()) +matrix = [list(map(int, input().split())) for _ in range(n)] +visited = [False for _ in range(n)] +half = n // 2 +minValue = 999999999 + + +def dfs(depth, idx): + global minValue + + if depth == half: + totalA, totalB = 0, 0 + for i in range(n): + for j in range(n): + if visited[i] and visited[j]: + totalA += matrix[i][j] + elif not visited[i] and not visited[j]: + totalB += matrix[i][j] + temp = abs(totalA - totalB) + if temp < minValue: + minValue = temp + + for i in range(idx, n): + visited[i] = True + dfs(depth + 1, i + 1) + visited[i] = False + + +dfs(0, 0) + +print(minValue) From 3e0381d85ff53ab1b3beae551a87ccd80235c250 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 25 Aug 2022 09:39:23 +0900 Subject: [PATCH 224/822] solve --- .../14501_\355\207\264\354\202\254.java" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "08.25/\354\241\260\354\210\230\354\227\260/14501_\355\207\264\354\202\254.java" diff --git "a/08.25/\354\241\260\354\210\230\354\227\260/14501_\355\207\264\354\202\254.java" "b/08.25/\354\241\260\354\210\230\354\227\260/14501_\355\207\264\354\202\254.java" new file mode 100644 index 0000000..24a8d26 --- /dev/null +++ "b/08.25/\354\241\260\354\210\230\354\227\260/14501_\355\207\264\354\202\254.java" @@ -0,0 +1,51 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int[][] consult; + static int max = Integer.MIN_VALUE; + static boolean[] visited; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + + consult = new int[N + 1][2]; //퇴사날이 1일부터이므로 N+1배열 생성 + + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + consult[i][0] = Integer.parseInt(token.nextToken()); + consult[i][1] = Integer.parseInt(token.nextToken()); + } + int[] arr = new int[8]; + + for (int i = 1; i <= N; i++) { + combination(i,0); + } + + + System.out.println(max); + + } + + static void combination(int day, int sum) { + int T = consult[day][0]; + int P = consult[day][1]; //해당 날에 상담 걸리는 날 + + if (day + T > N + 1) { //상담하는데 필요한 시간이 퇴사전 날을 넘어가면 그 전날까지 상담요소 걸리는 합을 max에 갱신 + max = Math.max(max,sum); + return; + } else if (day + T == N + 1) {//상담마지막이 퇴사전날이라면 해당 날에 비용까지 더해서 max에 갱신 + max = Math.max(max,sum+P); + return; + } + + for (int i = day + T; i <= N; i++) { //i는 해당 날짜 + 상담하는게 걸리는시간으로 시작 + combination(i,sum+P); + } + } + +} \ No newline at end of file From d039300723b805020987edf382a9ceb275088745 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 25 Aug 2022 18:10:25 +0900 Subject: [PATCH 225/822] solve --- .../[14501]\355\207\264\354\202\254.py" | 16 ++++++++++++++ ...0\354\231\200 \353\247\201\355\201\254.py" | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 "08.25/\354\235\264\354\247\200\354\234\244/[14501]\355\207\264\354\202\254.py" create mode 100644 "08.25/\354\235\264\354\247\200\354\234\244/[14889]\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.py" diff --git "a/08.25/\354\235\264\354\247\200\354\234\244/[14501]\355\207\264\354\202\254.py" "b/08.25/\354\235\264\354\247\200\354\234\244/[14501]\355\207\264\354\202\254.py" new file mode 100644 index 0000000..8f05f9d --- /dev/null +++ "b/08.25/\354\235\264\354\247\200\354\234\244/[14501]\355\207\264\354\202\254.py" @@ -0,0 +1,16 @@ +# import sys; input = sys.stdin.readline +import sys; sys.stdin = open("input.txt") +n= int(input()) +n_list = [list(map(int, input().split())) for _ in range(n)] + +dp = [0] * (n+1) + +for i in range(n-1, -1, -1): + d, p = n_list[i][0], n_list[i][1] + if d + i <= n: + dp[i] = max(p + dp[d+i], dp[i+1]) + else: + dp[i] = dp[i+1] + +print(dp[0]) + diff --git "a/08.25/\354\235\264\354\247\200\354\234\244/[14889]\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.py" "b/08.25/\354\235\264\354\247\200\354\234\244/[14889]\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.py" new file mode 100644 index 0000000..6774fb2 --- /dev/null +++ "b/08.25/\354\235\264\354\247\200\354\234\244/[14889]\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.py" @@ -0,0 +1,22 @@ +# import sys; input = sys.stdin.readline +import sys; sys.stdin = open("input.txt") +from itertools import combinations + +def solution(_n, _arr) -> int: + comb_min, comb_list = 100000, list(range(_n)) + for start_member in list(combinations(comb_list, _n//2)): + start_total = link_total = 0 + link_member = list(set(comb_list) - set(start_member)) + for i, j in list(combinations(start_member, 2)): + start_total += _arr[i][j] + start_total += _arr[j][i] + for i, j in list(combinations(link_member, 2)): + link_total += _arr[i][j] + link_total += _arr[j][i] + comb_min = min(comb_min, abs(start_total - link_total)) + return comb_min + +n = int(input()) +arr = [list(map(int, input().split())) for _ in range(n)] +answer = solution(n, arr) +print(answer) \ No newline at end of file From f7abb6c4ac173565b84da014b93c31b1caf206bc Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Thu, 25 Aug 2022 19:55:18 +0900 Subject: [PATCH 226/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=8014501.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\20014501.java" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014501.java" diff --git "a/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014501.java" "b/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014501.java" new file mode 100644 index 0000000..c7610c1 --- /dev/null +++ "b/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014501.java" @@ -0,0 +1,43 @@ +import java.util.*; +public class Main { + + public static Scanner scan =new Scanner(System.in); + public static int n,m,t; + public static boolean[] visited; //정점을 방문 했는지 true/false + public static StringBuilder sb=new StringBuilder(); + public static int[] MAX,T,P; + static int ans,blue,white,cnt1,cnt2; + public static void main(String[] args) { + //입력 + n=scan.nextInt(); //한변의 길이 + MAX=new int[n+2]; + T=new int[n+1]; + P=new int[n+1]; + for(int i=1;i Date: Thu, 25 Aug 2022 19:55:57 +0900 Subject: [PATCH 227/822] =?UTF-8?q?Create=20=EB=B0=B1=EC=A4=8014889.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\20014889.java" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014889.java" diff --git "a/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014889.java" "b/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014889.java" new file mode 100644 index 0000000..c30f3fb --- /dev/null +++ "b/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014889.java" @@ -0,0 +1,59 @@ +import java.util.*; +public class Main { + + public static Scanner scan =new Scanner(System.in); + public static StringBuilder sb=new StringBuilder(); + public static int[][] arr; + public static boolean [] visited; + public static int [] choice; + static int N,T,num=0,ans=0,min=101; + static boolean flag; + public static void main(String[] args) { + //입력 + N=scan.nextInt(); + arr= new int[N+1][N+1]; + visited=new boolean[N+1]; + for(int i=1;i Date: Thu, 25 Aug 2022 21:42:24 +0900 Subject: [PATCH 228/822] Create readme.md --- 08.28/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 08.28/readme.md diff --git a/08.28/readme.md b/08.28/readme.md new file mode 100644 index 0000000..761d9f8 --- /dev/null +++ b/08.28/readme.md @@ -0,0 +1,3 @@ +# 08.28(일) + +SWEA 기출 3문제 From 8a4c419e212eef2bc8e57f2609e481362fddd0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 26 Aug 2022 21:21:50 +0900 Subject: [PATCH 229/822] Update readme.md --- 08.28/readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/08.28/readme.md b/08.28/readme.md index 761d9f8..647ce5a 100644 --- a/08.28/readme.md +++ b/08.28/readme.md @@ -1,3 +1,4 @@ # 08.28(일) SWEA 기출 3문제 +https://swexpertacademy.com/main/talk/codeBattle/battleDetail.do?categoryId=AYLNSmY6An0DFASv&battleMainPageIndex=1 From 0fabec374b2749187e31008d82ad043df72463ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 27 Aug 2022 20:28:42 +0900 Subject: [PATCH 230/822] =?UTF-8?q?Create=20=ED=97=8C=ED=84=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\227\214\355\204\260.cpp" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "08.28/\354\235\264\354\225\204\353\246\204/\355\227\214\355\204\260.cpp" diff --git "a/08.28/\354\235\264\354\225\204\353\246\204/\355\227\214\355\204\260.cpp" "b/08.28/\354\235\264\354\225\204\353\246\204/\355\227\214\355\204\260.cpp" new file mode 100644 index 0000000..835b64b --- /dev/null +++ "b/08.28/\354\235\264\354\225\204\353\246\204/\355\227\214\355\204\260.cpp" @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +int dx[] = { 0,1,0,-1 }; +int dy[] = { 1,0,-1,0 }; +vector> board; +vector ghost[5]; //유령 위치 +vector customer[5]; //고객 위치 +vector isGhost(5); //유령 잡았는지 +vector isCustomer(5); //유령 잡았는지 +int minTime = INT_MAX; //제일 작은 시간 +int customerSize = 0; +int N, M; + +void init() { + board.clear(); + minTime = INT_MAX; + isGhost = vector(5, false); + isCustomer = vector(5, false); + customerSize = 0; +} + +void getMinTime(int time, int x, int y) { + if (customerSize == 0 || time >= minTime) { + minTime = min(minTime, time); + return; + } + for (int i = 1; i <= M; i++) { //유령 + if (!isGhost[i]) { + isGhost[i] = true; + int xx = ghost[i][0]; + int yy = ghost[i][1]; + int dif = abs(xx - x) + abs(yy - y); + board[xx][yy] = 0; + getMinTime(time + dif, xx, yy); + board[xx][yy] = i; + isGhost[i] = false; + } + } + for (int i = 1; i <= M; i++) { //고객 + if (isGhost[i] && !isCustomer[i]) { + customerSize--; + isCustomer[i] = true; + int xx = customer[i][0]; + int yy = customer[i][1]; + int dif = abs(xx - x) + abs(yy - y); + board[xx][yy] = 0; + getMinTime(time + dif, xx, yy); + board[xx][yy] = i; + isCustomer[i] = false; + customerSize++; + } + } +} + +int main() { + int T; cin >> T; + for (int t = 1; t <= T; t++) { + cin >> N; + init(); + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < N; k++) { + int input; cin >> input; + tmp.push_back(input); + if (input < 0) { + customer[abs(input)] = { i,k }; + customerSize++; + } + else if (input > 0) { + ghost[input] = { i,k }; + } + } + board.push_back(tmp); + } + M = customerSize; + getMinTime(0, 0, 0); + cout << "#" << t << " " << minTime << endl; + } + return 0; +} From 3e0392af337028d974cbdd8b8b32258ad42dd9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 27 Aug 2022 21:38:48 +0900 Subject: [PATCH 231/822] =?UTF-8?q?Create=20=EB=82=9A=EC=8B=9C=ED=84=B0=20?= =?UTF-8?q?=EC=9E=90=EB=A6=AC=EC=9E=A1=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\246\254\354\236\241\352\270\260.cpp" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "08.28/\354\235\264\354\225\204\353\246\204/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.cpp" diff --git "a/08.28/\354\235\264\354\225\204\353\246\204/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.cpp" "b/08.28/\354\235\264\354\225\204\353\246\204/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.cpp" new file mode 100644 index 0000000..b40feb4 --- /dev/null +++ "b/08.28/\354\235\264\354\225\204\353\246\204/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.cpp" @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +using namespace std; +int minMoved, N; +vector> door; +vector visited; + +void getWent(vector& fishing, int moved,int count) { + if (moved >= minMoved || count == 3) { + minMoved = min(minMoved, moved); + return; + } + for (int i = 0; i < 3; i++) { + if (!visited[i]) { + visited[i] = true; + vector copy_fishing(fishing.begin(), fishing.end()); + int man = door[i][1]; + int nowMoved = moved; + while (man) { + int left = INT_MAX, right = INT_MAX; + for (int k = 0; k <= N; k++) { + if (left == INT_MAX && door[i][0] - k > 0) { + if (!copy_fishing[door[i][0] - k]) { + left = k; + } + } + if (right == INT_MAX && door[i][0] + k <= N) { + if (!copy_fishing[door[i][0] + k]) { + right = k; + } + } + if (left < INT_MAX || right < INT_MAX) break; + } + if (left == right && man == 1) { + //left + copy_fishing[door[i][0] - left] = true; + nowMoved += left + 1; + getWent(copy_fishing, nowMoved,count+1); + nowMoved -= left + 1; + copy_fishing[door[i][0] - left] = false; + //right + copy_fishing[door[i][0] + right] = true; + nowMoved += right + 1; + } + else if(left < INT_MAX){ + copy_fishing[door[i][0] - left] = true; + nowMoved += left+1; + }else{ + copy_fishing[door[i][0] + right] = true; + nowMoved += right + 1; + } + man--; + } + getWent(copy_fishing, nowMoved, count + 1); + visited[i] = false; + } + } +} + +void init() { + minMoved = INT_MAX; + door.clear(); + visited = { false,false,false }; +} + +int main() { + int T; cin >> T; + for (int t = 1; t <= T; t++) { + init(); + cin >> N; + for (int i = 0; i < 3; i++) { + int fish, man; + cin >> fish >> man; + door.push_back({ fish,man }); + } + vector fishing(N+1, 0); + getWent(fishing, 0,0); + cout << "#" << t << " " << minMoved << endl; + } + return 0; +} From 6cdd6f4f62eb888001a09644f5f69ef72ecf442f Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 28 Aug 2022 12:47:14 +0900 Subject: [PATCH 232/822] complete --- .../Main_15172_\355\227\214\355\204\260.java" | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 "08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" diff --git "a/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" "b/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" new file mode 100644 index 0000000..035cbe7 --- /dev/null +++ "b/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" @@ -0,0 +1,224 @@ +import java.io.*; +import java.util.*; + +// https://swexpertacademy.com/main/solvingProblem/solvingProblem.do +// 모든 몬스터를 없애고 고객들에게 확인시켜 작업을 완료하는 데 가장 빠른 시간을 구하는 프로그램을 작성해라. + +// 몬스터를 처리하는 순서는 상관이 없다. 고객들에게 확인시켜 주는 순서도 상관이 없다. +// 몬스터를 처리했다고 해서 바로 그 몬스터를 처리해 달라고 요청한 고객에게 돌아가 확인할 필요도 없다. +public class Main_15172_헌터 { + static int[][] map; + static int[][] tempMap; + + static int N; + static int[] dirX = {0, 0, -1, 1}; // 헌터는 상하좌우로 움직인다. + static int[] dirY = {1, -1, 0, 0}; + + static int[] orderArr; // 경우의 수를 담을 배열 + static List allList; // 전체 몬스터와 고객들이 들어갈 리스트 + static int totalCount; // 총 몬스터와 고객의 수 + + static boolean[] isVisited; // 방문 여부 배열 + static boolean[] monsterisVisited; // 몬스터 처치 여부 배열 + static int result; // 최종 결과 값 + + static class Coordinates { + int x; + int y; + int dist; + + public Coordinates(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } // End of Coordinates class + + static class HunterCoordinates { + int x; + int y; + int totalDist; + + public HunterCoordinates(int x, int y, int totalDist) { + this.x = x; + this.y = y; + this.totalDist = totalDist; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public int getTotalDist() { + return totalDist; + } + + public void setTotalDist(int totalDist) { + this.totalDist = totalDist; + } + } // End of HunterCoordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/15172.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int TC = Integer.parseInt(br.readLine()); + for (int t = 1; t <= TC; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); // 변수들 초기화 + int clientCount = 0; // 고객의 수를 확인할 변수 + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + tempMap[i][j] = map[i][j]; + + if (map[i][j] > 0) { + clientCount = Math.max(clientCount, map[i][j]); + allList.add(map[i][j]); + } else if (map[i][j] < 0) { + allList.add(map[i][j]); + } + } + } + + Collections.sort(allList); + totalCount = allList.size(); + + isVisited = new boolean[totalCount]; + monsterisVisited = new boolean[clientCount]; // 몬스터 방문여부를 체크할 배열 + orderArr = new int[totalCount]; // 방문 순서 경우의 수를 담을 배열 고객의 수의 2배 값으로 배열 크기 할당. + DFS(0, totalCount); // 경우의 수 만들기 + + sb.append(result).append('\n'); + } // End of for(TC) + + bw.write(sb.toString()); + bw.close(); + } // End of main + + // 첫번쨰 해결해야할 과제는 올바른 방문 순서를 만들어서 모든 경우의 수를 만들기 + // 배열의 0번째는 무조건 몬스터가 들어와야 하고, 고객을 방문할 때는 해당 몬스터를 방문한 후에 고객을 방문할 수 있음 + private static void DFS(int depth, int depthLimit) { // 방문 순서를 조합하는 백트래킹 + if (depth == depthLimit) { + HunterCoordinates hunter = new HunterCoordinates(0, 0, 0); // 첫 번째 사냥꾼의 시작 위치는 항상 0, 0 거리도 0 + + int count = 0; + for (int i = 0; i < totalCount; i++) { + int num = orderArr[i]; + if (i == 0) { + hunter = BFS(hunter.getX(), hunter.getY(), num, hunter.getTotalDist()); + count += hunter.getTotalDist(); + } else { + hunter = BFS(hunter.getX(), hunter.getY(), num, hunter.getTotalDist()); + count += hunter.getTotalDist(); + } + } + + copy(); // 배열 다시 원상 복귀 + result = Math.min(result, count); + return; + } + + // 음수는 고객, 양수는 몬스터 + for (int i = 0; i < depthLimit; i++) { + int num = allList.get(i); + + if (num < 0 && !monsterisVisited[(Math.abs(num) - 1)]) { // 고객일 때 요청한 몬스터가 죽지 않았으면 방문할 수 없다. + continue; + } + + if (isVisited[i]) continue; + isVisited[i] = true; + + if (num > 0) { // num이 양수 즉, 몬스터 일 때, + monsterisVisited[num - 1] = true; + orderArr[depth] = num; + DFS(depth + 1, depthLimit); + monsterisVisited[num - 1] = false; + } else { // num이 음수 즉, 고객일 때 + orderArr[depth] = num; + DFS(depth + 1, depthLimit); + } + + isVisited[i] = false; + } + + } // End of DFS + + private static HunterCoordinates BFS(int x, int y, int target, int totalDist) { + HunterCoordinates hunter = new HunterCoordinates(x, y, totalDist); + + if (tempMap[x][y] == target) { + tempMap[x][y] = 0; + return hunter; + } + + boolean[][] isVisited = new boolean[N][N]; + Queue que = new LinkedList<>(); + isVisited[x][y] = true; + que.offer(new Coordinates(x, y, 0)); + + while (!que.isEmpty()) { + Coordinates cor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = cor.x + dirX[i]; + int nowY = cor.y + dirY[i]; + int dist = cor.dist; + + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY]) { + isVisited[nowX][nowY] = true; + if (tempMap[nowX][nowY] == target) { + tempMap[nowX][nowY] = 0; // 방문한 타겟들은 0처리 + hunter.setTotalDist(dist + 1); + hunter.setX(nowX); + hunter.setY(nowY); + return hunter; + } + + que.offer(new Coordinates(nowX, nowY, dist + 1)); + } + + } + } + + return hunter; + } // End of BFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { // 변수 초기화 메소드 + map = new int[N][N]; + tempMap = new int[N][N]; + allList = new ArrayList<>(); + result = Integer.MAX_VALUE / 4; // 오버플로우 방지 + } // End of init + + private static void copy() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + tempMap[i][j] = map[i][j]; + } + } + } // End of copy +} // End of Main class \ No newline at end of file From 4d932fb5384353692535b90c9155605b53a3a15e Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 28 Aug 2022 12:50:30 +0900 Subject: [PATCH 233/822] solve --- .../Shuffle-O-Matic.java" | 178 +++++++++++ ...\353\246\254\354\236\241\352\270\260.java" | 289 ++++++++++++++++++ .../\355\227\214\355\204\260.java" | 158 ++++++++++ 3 files changed, 625 insertions(+) create mode 100644 "08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" create mode 100644 "08.28/\354\241\260\354\210\230\354\227\260/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.java" create mode 100644 "08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" new file mode 100644 index 0000000..a5181bd --- /dev/null +++ "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" @@ -0,0 +1,178 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Solution3 { + + static int N; + static int[][] field; // 필드 + static boolean[] hunted; // 몬스터가 잡혔는지 체크 배열 + static boolean[] existed; // 몬스터가 존재하는지 체크 배열 + static int[][] customers; // 고객 좌표 + static int[][] monsters; // 몬스터 좌표 + static int[] dx = { 0, 0, -1, 1 }; // 좌표이동 + static int[] dy = { -1, 1, 0, 0 }; + static int hunterX; // 헌터의 x좌표 + static int hunterY; // 헌터의 y좌표 + static List list; // 몬스터 + 고객 리스트 + static boolean[] checked; // 순열 조합 체크 배열 + static int minTime; // 최소 시간 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + N = Integer.parseInt(br.readLine()); + field = new int[N + 1][N + 1]; + monsters = new int[5][2]; + existed = new boolean[5]; + list = new ArrayList(); + customers = new int[5][2]; + int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 + + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + field[i][j] = Integer.parseInt(token.nextToken()); + + if (field[i][j] != 0) { + size = Math.max(size, Math.abs(field[i][j])); + if (field[i][j] < 0) { // 고객좌표 + customers[Math.abs(field[i][j])][0] = i; + customers[Math.abs(field[i][j])][1] = j; + list.add(field[i][j]); + + } else { // 몬스터 좌표 + monsters[field[i][j]][0] = i; + monsters[field[i][j]][1] = j; + existed[field[i][j]] = true; // 몬스터 존재 체크 + list.add(field[i][j]); + } + } + + } + } + + hunted = new boolean[5]; + + int orderSize = size * 2; // 순열 크기 + + minTime = Integer.MAX_VALUE; + + checked = new boolean[list.size()]; + int[] order = new int[orderSize]; + combination(0, orderSize, order); // 헌팅시작 + + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); + } + bw.flush(); + bw.close(); + + } + + static void combination(int index, int size, int[] order) { + if (index == size) { + int time = 0; + hunterX = 1; + hunterY = 1; + for (int i = 0; i < order.length; i++) { + if (order[i] < 0) { //방문 좌표가 고객일 때 + for (int j = 1; j < customers.length; j++) { + if (j == Math.abs(order[i])) { + int x = Math.abs(hunterX - customers[j][1]); //x 거리 + int y = Math.abs(hunterY - customers[j][0]); //y 거리 + time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 + hunterX = customers[j][1]; //헌터 위치 갱신 + hunterY = customers[j][0]; + } + } + } else { + for (int j = 1; j < monsters.length; j++) { + if (j == order[i]) {//방문 좌표가 몬스터일 때 + int x = Math.abs(hunterX - monsters[j][1]); + int y = Math.abs(hunterY - monsters[j][0]); + time += x + y; + hunterX = monsters[j][1]; + hunterY = monsters[j][0]; + } + } + } + if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 + break; + } + } + minTime = Math.min(minTime, time); + return; + } + + for (int i = 0; i < list.size(); i++) { + if (index == 0) { //첫번째 방문 타겟 설정 + if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } else { + if (!checked[i]) { //중복 체크 + if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add + order[index] = list.get(i); + checked[i] = true; + combination(index + 1, size, order); + checked[i] = false; + } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } + } + } + } + + static int hunting(int target) { // BFS로 푸는 로직 + + int count = 0; + + Queue queue = new LinkedList(); + queue.add(new Point(hunterX, hunterY)); + + boolean[][] visited = new boolean[N + 1][N + 1]; + visited[hunterY][hunterX] = true; + + while (!queue.isEmpty()) { + int qSize = queue.size(); + for (int j = 0; j < qSize; j++) { + Point point = queue.poll(); + if (field[point.y][point.x] == target) { + hunterX = point.x; + hunterY = point.y; + return count; + } + for (int k = 0; k < dx.length; k++) { + int x = point.x + dx[k]; + int y = point.y + dy[k]; + + if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { + visited[y][x] = true; + queue.add(new Point(x, y)); + } + } + } + count++; + } + return count; + } +} diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.java" "b/08.28/\354\241\260\354\210\230\354\227\260/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.java" new file mode 100644 index 0000000..afbcc23 --- /dev/null +++ "b/08.28/\354\241\260\354\210\230\354\227\260/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.java" @@ -0,0 +1,289 @@ +import java.io.*; +import java.util.*; + +public class Solution { + + static int N; + static int[][] gates = new int[3][2]; // 게이트 value 낚시꾼 value + static int[] visited; // 낚시터 + static int[] dx = { 1, -1 }; // 방향벡터 + static int min = Integer.MAX_VALUE; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + N = Integer.parseInt(br.readLine()); + for (int i = 0; i < gates.length; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + gates[i][0] = Integer.parseInt(token.nextToken()); + gates[i][1] = Integer.parseInt(token.nextToken()); + } + + int[][] order = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 }, { 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 } }; // 3개의 게이트 + // 순서 + min = Integer.MAX_VALUE; + for (int i = 0; i < order.length; i++) { + visited = new int[N + 1]; + int first = order[i][0]; // 첫번째 게이트 + int second = order[i][1]; // 두번째 게이트 + int third = order[i][2]; // 세번째 게이트 + first(0, gates[first], gates[second], gates[third]); // 탐색 시작 + } + + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(min) + "\n"); + } + bw.flush(); + bw.close(); + + } + + static void copy(int[] temp, int[] original) { // 깊은복사 + + for (int i = 1; i <= N; i++) { + temp[i] = original[i]; + } + } + + static void first(int size, int[] gate1, int[] gate2, int[] gate3) { // 첫번째 게이트 탐색 + int sum = 0; + int distance = 0; + int gc = gate1[0]; + + if (visited[gc] == 0) { // 시작지점에 비어있으면 거리 +1 낚시터 공간-1 + visited[gc] = 1; + sum++; + size++; + } + + distance++; + + while (true) { + if (size == gate1[1]) { // 양쪽에 둘다 들어간 경우 + int[] temp = new int[N + 1]; + copy(temp, visited); + second(0, gate2, gate3, sum, temp); + break; + } else if (size == gate1[1] - 1) { // 해당 거리에 낚시꾼이 한명만 남은 경우 + int right = gc + distance; + int left = gc - distance; + Queue queue = new LinkedList(); + while (true) { + + for (int i = 0; i < 2; i++) { // 방향벡터를 통해 좌우에 들어갈 수 있는 위치에 add + int location = gc + dx[i] * distance; + if (location >= 1 && location <= N) { + if (visited[location] == 0) { + queue.add(location); + } + } + } + + if (queue.isEmpty()) { // 만약 둘 다 못 들어가면 거리 +1 + distance++; + } else { + break; + } + + } + + if (queue.size() == 1) { // 좌우중 한 자리만 비어 있는 경우 + int location = queue.poll(); + visited[location] = 1; + sum += distance + 1; + int[] temp = new int[N + 1]; + copy(temp, visited); + second(0, gate2, gate3, sum, temp); + } else { // 좌우 둘다 자리가 비어있어서 두가지 경우가 나타날 경우 + int location = queue.poll(); + sum += distance + 1; + visited[location] = 1; + int[] temp = new int[N + 1]; + copy(temp, visited); + second(0, gate2, gate3, sum, temp); // 2번째 자리 탐색 + visited[location] = 0; // 해당 자리에 1을 넣어주고 0으로 리셋시키고 2번째 자리 탐색 + location = queue.poll(); + visited[location] = 1; + temp = new int[N + 1]; + copy(temp, visited); + second(0, gate2, gate3, sum, temp); + } + break; + } + + for (int i = 0; i < 2; i++) { // 좌우에 들어갈 수 있는 위치에 낚시꾼 넣어주기 + int x = gc + dx[i] * distance; + if (x >= 1 && x <= N) { + if (visited[x] == 0) { + visited[x] = 1; + sum += distance + 1; + size++; + } + } + } + distance++; // 한번 탐색할 때마다 기준거리 +1 + + } + + } + + static void second(int size, int[] gate2, int[] gate3, int sum, int[] temp) { // 두번째 게이트 탐색 first()부분과 거의 동일 + + int distance = 0; + int gc = gate2[0]; + + if (temp[gc] == 0) { + temp[gc] = 2; + sum++; + size++; + } + + distance++; + + while (true) { + if (size == gate2[1]) { + int[] temp2 = new int[N + 1]; + copy(temp2, temp); + third(0, gate3, sum, temp2); + break; + } else if (size == gate2[1] - 1) { + int right = gc + distance; + int left = gc - distance; + Queue queue = new LinkedList(); + while (true) { + + for (int i = 0; i < 2; i++) { + int location = gc + dx[i] * distance; + if (location >= 1 && location <= N) { + if (temp[location] == 0) { + queue.add(location); + } + } + } + + if (queue.isEmpty()) { + distance++; + } else { + break; + } + + } + + if (queue.size() == 1) { + int location = queue.poll(); + temp[location] = 2; + sum += distance + 1; + int[] temp2 = new int[N + 1]; + copy(temp2, temp); + third(0, gate3, sum, temp2); + + } else { + int location = queue.poll(); + sum += distance + 1; + temp[location] = 2; + int[] temp2 = new int[N + 1]; + copy(temp2, temp); + third(0, gate3, sum, temp2); + temp[location] = 0; + location = queue.poll(); + temp[location] = 2; + temp2 = new int[N + 1]; + copy(temp2, temp); + third(0, gate3, sum, temp2); + + } + break; + } + + for (int i = 0; i < 2; i++) { + int x = gc + dx[i] * distance; + if (x >= 1 && x <= N) { + if (temp[x] == 0) { + temp[x] = 2; + sum += distance + 1; + size++; + } + } + } + + distance++; + + } + } + + static void third(int size, int[] gate3, int sum, int[] temp2) { // 세번째 게이트 탐색 first()부분과 거의 동일 + int distance = 0; + int gc = gate3[0]; + + if (temp2[gc] == 0) { + temp2[gc] = 3; + sum++; + size++; + } + + distance++; + + while (true) { + if (size == gate3[1]) { + min = Math.min(min, sum); // 탐색이 끝나면 min값 갱신시켜주기 + break; + } else if (size == gate3[1] - 1) { + int right = gc + distance; + int left = gc - distance; + Queue queue = new LinkedList(); + while (true) { + + for (int i = 0; i < 2; i++) { + int location = gc + dx[i] * distance; + if (location >= 1 && location <= N) { + if (temp2[location] == 0) { + queue.add(location); + } + } + } + + if (queue.isEmpty()) { + distance++; + } else { + break; + } + + } + + if (queue.size() == 1) { + int location = queue.poll(); + temp2[location] = 3; + sum += distance + 1; + min = Math.min(min, sum); + } else { + int location = queue.poll(); + sum += distance + 1; + temp2[location] = 3; + min = Math.min(min, sum); + temp2[location] = 0; + location = queue.poll(); + temp2[location] = 3; + min = Math.min(min, sum); + } + break; + } + + for (int i = 0; i < 2; i++) { + int x = gc + dx[i] * distance; + if (x >= 1 && x <= N) { + if (temp2[x] == 0) { + temp2[x] = 3; + sum += distance + 1; + size++; + } + } + } + + distance++; + + } + } +} \ No newline at end of file diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" new file mode 100644 index 0000000..4e256e5 --- /dev/null +++ "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" @@ -0,0 +1,158 @@ +import java.io.*; +import java.util.*; + +public class Solution2 { + + static int N; + static int[] card; // 카드 배열 + static boolean isSorted; // 정렬되어있는지 확인 변수 + static int count; // 셔플 횟수 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + N = Integer.parseInt(br.readLine()); + card = new int[N + 1]; // 카드 + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + card[i] = Integer.parseInt(token.nextToken()); + } + + isSorted = false; + count = 0; + + // 0번일 경우 정렬체크 + sortCheck(card); + reverseCheck(card); + + if (isSorted) { // 정렬되어있다면 바로 셔플 + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { // 아니라면 셔플 시작 + for (int i = 1; i <= 5; i++) { + int[] order = new int[i]; + combination(0, i, order); + if (isSorted) { // 정렬되어있다면 반복문 종료 + break; + } + } + if (isSorted) { + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { + bw.write("#" + String.valueOf(tc) + " -1\n"); + } + } + + } + bw.flush(); + bw.close(); + + } + + static void combination(int index, int size, int[] order) { + + if (isSorted) { // 정렬되어있다면 함수 종료 + return; + } + + if (index == size) { // 셔플 순서 정해지면 셔플하기 + shuffle(order); + if (isSorted) { + count = index; + } + return; + } + + for (int i = 1; i <= N - 1; i++) { + order[index] = i; + combination(index + 1, size, order); + } + } + + static void shuffle(int[] order) { + int temp[] = new int[N + 1]; // 임시배열 초기화 + copy(temp); + + for (int i = 0; i < order.length; i++) { + int start = N / 2; // 셔플 위치 + if (order[i] < start) { // 123 | 456 순서일 때 + for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 + start = start - j + 1; // 셔플 인덱스 + for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 + } + } else { // 456 | 123 순일때 + if (order[i] == N - 1) { // order[i]가 N-1일 때 + rCopy(temp); // 역순 배열 초기화 + } else { + rCopy(temp); + for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 + start = start - j + 1; + for (int k = 1; k <= j; k++) { + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; + } + } + } + } + + sortCheck(temp); // 오름차순 정렬인지 확인 + reverseCheck(temp); // 내림차순 정렬인지 확인 + + } + + static void copy(int[] temp) { //원본 복사 배열(깊은 복사) + for (int i = 1; i <= N; i++) { + temp[i] = card[i]; + } + } + + static void rCopy(int[] temp) { //123 456 -> 456 123 + for (int i = 1; i <= N / 2; i++) { + swap(i, (N / 2) + i, temp); + } + } + + static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 + int temp2 = temp[a]; + temp[a] = temp[b]; + temp[b] = temp2; + } + + static void sortCheck(int[] arr) { //오름차순 정렬 + boolean check = true; + for (int i = 1; i <= N; i++) { + if (arr[i] != i) { + check = false; + break; + } + } + + if (check) { + isSorted = true; + } + } + + static void reverseCheck(int[] arr) { //내림차순 정렬 + boolean check = true; + int rCount = N; + for (int i = 1; i <= N; i++) { + if (arr[i] != rCount) { + check = false; + break; + } + rCount--; + } + if (check) { + isSorted = true; + } + } +} From 347057b35f4a8d4c244466035823f57c02f39352 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 28 Aug 2022 13:45:59 +0900 Subject: [PATCH 234/822] =?UTF-8?q?=ED=97=8C=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main_15172_\355\227\214\355\204\260.java" | 58 +++---------------- 1 file changed, 8 insertions(+), 50 deletions(-) diff --git "a/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" "b/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" index 035cbe7..5b8617c 100644 --- "a/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" +++ "b/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" @@ -34,42 +34,6 @@ public Coordinates(int x, int y, int dist) { } } // End of Coordinates class - static class HunterCoordinates { - int x; - int y; - int totalDist; - - public HunterCoordinates(int x, int y, int totalDist) { - this.x = x; - this.y = y; - this.totalDist = totalDist; - } - - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public int getTotalDist() { - return totalDist; - } - - public void setTotalDist(int totalDist) { - this.totalDist = totalDist; - } - } // End of HunterCoordinates class - public static void main(String[] args) throws Exception { System.setIn(new FileInputStream("res/15172.txt")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -118,18 +82,13 @@ public static void main(String[] args) throws Exception { // 배열의 0번째는 무조건 몬스터가 들어와야 하고, 고객을 방문할 때는 해당 몬스터를 방문한 후에 고객을 방문할 수 있음 private static void DFS(int depth, int depthLimit) { // 방문 순서를 조합하는 백트래킹 if (depth == depthLimit) { - HunterCoordinates hunter = new HunterCoordinates(0, 0, 0); // 첫 번째 사냥꾼의 시작 위치는 항상 0, 0 거리도 0 + Coordinates hunter = new Coordinates(0, 0, 0); // 첫 번째 사냥꾼의 시작 위치는 항상 0, 0 거리도 0 int count = 0; for (int i = 0; i < totalCount; i++) { int num = orderArr[i]; - if (i == 0) { - hunter = BFS(hunter.getX(), hunter.getY(), num, hunter.getTotalDist()); - count += hunter.getTotalDist(); - } else { - hunter = BFS(hunter.getX(), hunter.getY(), num, hunter.getTotalDist()); - count += hunter.getTotalDist(); - } + hunter = BFS(hunter.x, hunter.y, num, hunter.dist); + count += hunter.dist; } copy(); // 배열 다시 원상 복귀 @@ -160,11 +119,10 @@ private static void DFS(int depth, int depthLimit) { // 방문 순서를 조합 isVisited[i] = false; } - } // End of DFS - private static HunterCoordinates BFS(int x, int y, int target, int totalDist) { - HunterCoordinates hunter = new HunterCoordinates(x, y, totalDist); + private static Coordinates BFS(int x, int y, int target, int totalDist) { + Coordinates hunter = new Coordinates(x, y, totalDist); if (tempMap[x][y] == target) { tempMap[x][y] = 0; @@ -188,9 +146,9 @@ private static HunterCoordinates BFS(int x, int y, int target, int totalDist) { isVisited[nowX][nowY] = true; if (tempMap[nowX][nowY] == target) { tempMap[nowX][nowY] = 0; // 방문한 타겟들은 0처리 - hunter.setTotalDist(dist + 1); - hunter.setX(nowX); - hunter.setY(nowY); + hunter.dist = dist + 1; + hunter.x = nowX; + hunter.y = nowY; return hunter; } From 6636ecf4c22a2de79d1fbbf960691b7bcc41ff7f Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 28 Aug 2022 13:47:24 +0900 Subject: [PATCH 235/822] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shuffle-O-Matic.java" | 244 ++++++++---------- .../\355\227\214\355\204\260.java" | 244 ++++++++++-------- 2 files changed, 244 insertions(+), 244 deletions(-) diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" index a5181bd..059737c 100644 --- "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" +++ "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" @@ -1,22 +1,12 @@ -import java.awt.Point; import java.io.*; import java.util.*; -public class Solution3 { +public class Solution { static int N; - static int[][] field; // 필드 - static boolean[] hunted; // 몬스터가 잡혔는지 체크 배열 - static boolean[] existed; // 몬스터가 존재하는지 체크 배열 - static int[][] customers; // 고객 좌표 - static int[][] monsters; // 몬스터 좌표 - static int[] dx = { 0, 0, -1, 1 }; // 좌표이동 - static int[] dy = { -1, 1, 0, 0 }; - static int hunterX; // 헌터의 x좌표 - static int hunterY; // 헌터의 y좌표 - static List list; // 몬스터 + 고객 리스트 - static boolean[] checked; // 순열 조합 체크 배열 - static int minTime; // 최소 시간 + static int[] card; // 카드 배열 + static boolean isSorted; // 정렬되어있는지 확인 변수 + static int count; // 셔플 횟수 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -26,47 +16,36 @@ public static void main(String[] args) throws Exception { for (int tc = 1; tc <= T; tc++) { N = Integer.parseInt(br.readLine()); - field = new int[N + 1][N + 1]; - monsters = new int[5][2]; - existed = new boolean[5]; - list = new ArrayList(); - customers = new int[5][2]; - int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 - + card = new int[N + 1]; // 카드 + StringTokenizer token = new StringTokenizer(br.readLine()); for (int i = 1; i <= N; i++) { - StringTokenizer token = new StringTokenizer(br.readLine()); - for (int j = 1; j <= N; j++) { - field[i][j] = Integer.parseInt(token.nextToken()); - - if (field[i][j] != 0) { - size = Math.max(size, Math.abs(field[i][j])); - if (field[i][j] < 0) { // 고객좌표 - customers[Math.abs(field[i][j])][0] = i; - customers[Math.abs(field[i][j])][1] = j; - list.add(field[i][j]); - - } else { // 몬스터 좌표 - monsters[field[i][j]][0] = i; - monsters[field[i][j]][1] = j; - existed[field[i][j]] = true; // 몬스터 존재 체크 - list.add(field[i][j]); - } - } + card[i] = Integer.parseInt(token.nextToken()); + } + isSorted = false; + count = 0; + + // 0번일 경우 정렬체크 + sortCheck(card); + reverseCheck(card); + + if (isSorted) { // 정렬되어있다면 바로 셔플 + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { // 아니라면 셔플 시작 + for (int i = 1; i <= 5; i++) { + int[] order = new int[i]; + combination(0, i, order); + if (isSorted) { // 정렬되어있다면 반복문 종료 + break; + } + } + if (isSorted) { + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { + bw.write("#" + String.valueOf(tc) + " -1\n"); } } - hunted = new boolean[5]; - - int orderSize = size * 2; // 순열 크기 - - minTime = Integer.MAX_VALUE; - - checked = new boolean[list.size()]; - int[] order = new int[orderSize]; - combination(0, orderSize, order); // 헌팅시작 - - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); } bw.flush(); bw.close(); @@ -74,105 +53,106 @@ public static void main(String[] args) throws Exception { } static void combination(int index, int size, int[] order) { - if (index == size) { - int time = 0; - hunterX = 1; - hunterY = 1; - for (int i = 0; i < order.length; i++) { - if (order[i] < 0) { //방문 좌표가 고객일 때 - for (int j = 1; j < customers.length; j++) { - if (j == Math.abs(order[i])) { - int x = Math.abs(hunterX - customers[j][1]); //x 거리 - int y = Math.abs(hunterY - customers[j][0]); //y 거리 - time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 - hunterX = customers[j][1]; //헌터 위치 갱신 - hunterY = customers[j][0]; - } - } - } else { - for (int j = 1; j < monsters.length; j++) { - if (j == order[i]) {//방문 좌표가 몬스터일 때 - int x = Math.abs(hunterX - monsters[j][1]); - int y = Math.abs(hunterY - monsters[j][0]); - time += x + y; - hunterX = monsters[j][1]; - hunterY = monsters[j][0]; - } - } - } - if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 - break; - } + + if (isSorted) { // 정렬되어있다면 함수 종료 + return; + } + + if (index == size) { // 셔플 순서 정해지면 셔플하기 + shuffle(order); + if (isSorted) { + count = index; } - minTime = Math.min(minTime, time); return; } - for (int i = 0; i < list.size(); i++) { - if (index == 0) { //첫번째 방문 타겟 설정 - if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 - order[index] = list.get(i); - checked[i] = true; - hunted[Math.abs(list.get(i))] = true; - existed[Math.abs(list.get(i))] = false; - combination(index + 1, size, order); - checked[i] = false; - hunted[Math.abs(list.get(i))] = false; - existed[Math.abs(list.get(i))] = true; + for (int i = 1; i <= N - 1; i++) { + order[index] = i; + combination(index + 1, size, order); + } + } + + static void shuffle(int[] order) { + int temp[] = new int[N + 1]; // 임시배열 초기화 + copy(temp); + + for (int i = 0; i < order.length; i++) { + int start = N / 2; // 셔플 위치 + if (order[i] < start) { // 123 | 456 순서일 때 + for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 + start = start - j + 1; // 셔플 인덱스 + for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 } - } else { - if (!checked[i]) { //중복 체크 - if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add - order[index] = list.get(i); - checked[i] = true; - combination(index + 1, size, order); - checked[i] = false; - } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add - order[index] = list.get(i); - checked[i] = true; - hunted[Math.abs(list.get(i))] = true; - existed[Math.abs(list.get(i))] = false; - combination(index + 1, size, order); - checked[i] = false; - hunted[Math.abs(list.get(i))] = false; - existed[Math.abs(list.get(i))] = true; + } else { // 456 | 123 순일때 + if (order[i] == N - 1) { // order[i]가 N-1일 때 + rCopy(temp); // 역순 배열 초기화 + } else { + rCopy(temp); + for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 + start = start - j + 1; + for (int k = 1; k <= j; k++) { + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; } } } } + + sortCheck(temp); // 오름차순 정렬인지 확인 + reverseCheck(temp); // 내림차순 정렬인지 확인 + } - static int hunting(int target) { // BFS로 푸는 로직 + static void copy(int[] temp) { //원본 복사 배열(깊은 복사) + for (int i = 1; i <= N; i++) { + temp[i] = card[i]; + } + } - int count = 0; + static void rCopy(int[] temp) { //123 456 -> 456 123 + for (int i = 1; i <= N / 2; i++) { + swap(i, (N / 2) + i, temp); + } + } - Queue queue = new LinkedList(); - queue.add(new Point(hunterX, hunterY)); + static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 + int temp2 = temp[a]; + temp[a] = temp[b]; + temp[b] = temp2; + } - boolean[][] visited = new boolean[N + 1][N + 1]; - visited[hunterY][hunterX] = true; + static void sortCheck(int[] arr) { //오름차순 정렬 + boolean check = true; + for (int i = 1; i <= N; i++) { + if (arr[i] != i) { + check = false; + break; + } + } - while (!queue.isEmpty()) { - int qSize = queue.size(); - for (int j = 0; j < qSize; j++) { - Point point = queue.poll(); - if (field[point.y][point.x] == target) { - hunterX = point.x; - hunterY = point.y; - return count; - } - for (int k = 0; k < dx.length; k++) { - int x = point.x + dx[k]; - int y = point.y + dy[k]; + if (check) { + isSorted = true; + } + } - if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { - visited[y][x] = true; - queue.add(new Point(x, y)); - } - } + static void reverseCheck(int[] arr) { //내림차순 정렬 + boolean check = true; + int rCount = N; + for (int i = 1; i <= N; i++) { + if (arr[i] != rCount) { + check = false; + break; } - count++; + rCount--; + } + if (check) { + isSorted = true; } - return count; } } diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" index 4e256e5..27c3150 100644 --- "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" +++ "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" @@ -1,12 +1,22 @@ +import java.awt.Point; import java.io.*; import java.util.*; -public class Solution2 { +public class Solution { static int N; - static int[] card; // 카드 배열 - static boolean isSorted; // 정렬되어있는지 확인 변수 - static int count; // 셔플 횟수 + static int[][] field; // 필드 + static boolean[] hunted; // 몬스터가 잡혔는지 체크 배열 + static boolean[] existed; // 몬스터가 존재하는지 체크 배열 + static int[][] customers; // 고객 좌표 + static int[][] monsters; // 몬스터 좌표 + static int[] dx = { 0, 0, -1, 1 }; // 좌표이동 + static int[] dy = { -1, 1, 0, 0 }; + static int hunterX; // 헌터의 x좌표 + static int hunterY; // 헌터의 y좌표 + static List list; // 몬스터 + 고객 리스트 + static boolean[] checked; // 순열 조합 체크 배열 + static int minTime; // 최소 시간 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -16,143 +26,153 @@ public static void main(String[] args) throws Exception { for (int tc = 1; tc <= T; tc++) { N = Integer.parseInt(br.readLine()); - card = new int[N + 1]; // 카드 - StringTokenizer token = new StringTokenizer(br.readLine()); - for (int i = 1; i <= N; i++) { - card[i] = Integer.parseInt(token.nextToken()); - } + field = new int[N + 1][N + 1]; + monsters = new int[5][2]; + existed = new boolean[5]; + list = new ArrayList(); + customers = new int[5][2]; + int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 - isSorted = false; - count = 0; - - // 0번일 경우 정렬체크 - sortCheck(card); - reverseCheck(card); - - if (isSorted) { // 정렬되어있다면 바로 셔플 - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); - } else { // 아니라면 셔플 시작 - for (int i = 1; i <= 5; i++) { - int[] order = new int[i]; - combination(0, i, order); - if (isSorted) { // 정렬되어있다면 반복문 종료 - break; + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + field[i][j] = Integer.parseInt(token.nextToken()); + + if (field[i][j] != 0) { + size = Math.max(size, Math.abs(field[i][j])); + if (field[i][j] < 0) { // 고객좌표 + customers[Math.abs(field[i][j])][0] = i; + customers[Math.abs(field[i][j])][1] = j; + list.add(field[i][j]); + + } else { // 몬스터 좌표 + monsters[field[i][j]][0] = i; + monsters[field[i][j]][1] = j; + existed[field[i][j]] = true; // 몬스터 존재 체크 + list.add(field[i][j]); + } } - } - if (isSorted) { - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); - } else { - bw.write("#" + String.valueOf(tc) + " -1\n"); + } } - } - bw.flush(); - bw.close(); + hunted = new boolean[5]; - } + int orderSize = size * 2; // 순열 크기 - static void combination(int index, int size, int[] order) { + minTime = Integer.MAX_VALUE; - if (isSorted) { // 정렬되어있다면 함수 종료 - return; - } + checked = new boolean[list.size()]; + int[] order = new int[orderSize]; + combination(0, orderSize, order); // 헌팅시작 - if (index == size) { // 셔플 순서 정해지면 셔플하기 - shuffle(order); - if (isSorted) { - count = index; - } - return; + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); } + bw.flush(); + bw.close(); - for (int i = 1; i <= N - 1; i++) { - order[index] = i; - combination(index + 1, size, order); - } } - static void shuffle(int[] order) { - int temp[] = new int[N + 1]; // 임시배열 초기화 - copy(temp); - - for (int i = 0; i < order.length; i++) { - int start = N / 2; // 셔플 위치 - if (order[i] < start) { // 123 | 456 순서일 때 - for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 - start = start - j + 1; // 셔플 인덱스 - for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 - swap(start, start + 1, temp); - start += 2; + static void combination(int index, int size, int[] order) { + if (index == size) { + int time = 0; + hunterX = 1; + hunterY = 1; + for (int i = 0; i < order.length; i++) { + if (order[i] < 0) { //방문 좌표가 고객일 때 + for (int j = 1; j < customers.length; j++) { + if (j == Math.abs(order[i])) { + int x = Math.abs(hunterX - customers[j][1]); //x 거리 + int y = Math.abs(hunterY - customers[j][0]); //y 거리 + time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 + hunterX = customers[j][1]; //헌터 위치 갱신 + hunterY = customers[j][0]; + } } - start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 - } - } else { // 456 | 123 순일때 - if (order[i] == N - 1) { // order[i]가 N-1일 때 - rCopy(temp); // 역순 배열 초기화 } else { - rCopy(temp); - for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 - start = start - j + 1; - for (int k = 1; k <= j; k++) { - swap(start, start + 1, temp); - start += 2; + for (int j = 1; j < monsters.length; j++) { + if (j == order[i]) {//방문 좌표가 몬스터일 때 + int x = Math.abs(hunterX - monsters[j][1]); + int y = Math.abs(hunterY - monsters[j][0]); + time += x + y; + hunterX = monsters[j][1]; + hunterY = monsters[j][0]; } - start = N / 2; } } + if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 + break; + } } + minTime = Math.min(minTime, time); + return; } - sortCheck(temp); // 오름차순 정렬인지 확인 - reverseCheck(temp); // 내림차순 정렬인지 확인 - - } - - static void copy(int[] temp) { //원본 복사 배열(깊은 복사) - for (int i = 1; i <= N; i++) { - temp[i] = card[i]; + for (int i = 0; i < list.size(); i++) { + if (index == 0) { //첫번째 방문 타겟 설정 + if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } else { + if (!checked[i]) { //중복 체크 + if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add + order[index] = list.get(i); + checked[i] = true; + combination(index + 1, size, order); + checked[i] = false; + } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } + } } } - static void rCopy(int[] temp) { //123 456 -> 456 123 - for (int i = 1; i <= N / 2; i++) { - swap(i, (N / 2) + i, temp); - } - } + static int hunting(int target) { // BFS로 푸는 로직 - static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 - int temp2 = temp[a]; - temp[a] = temp[b]; - temp[b] = temp2; - } + int count = 0; - static void sortCheck(int[] arr) { //오름차순 정렬 - boolean check = true; - for (int i = 1; i <= N; i++) { - if (arr[i] != i) { - check = false; - break; - } - } + Queue queue = new LinkedList(); + queue.add(new Point(hunterX, hunterY)); - if (check) { - isSorted = true; - } - } + boolean[][] visited = new boolean[N + 1][N + 1]; + visited[hunterY][hunterX] = true; - static void reverseCheck(int[] arr) { //내림차순 정렬 - boolean check = true; - int rCount = N; - for (int i = 1; i <= N; i++) { - if (arr[i] != rCount) { - check = false; - break; + while (!queue.isEmpty()) { + int qSize = queue.size(); + for (int j = 0; j < qSize; j++) { + Point point = queue.poll(); + if (field[point.y][point.x] == target) { + hunterX = point.x; + hunterY = point.y; + return count; + } + for (int k = 0; k < dx.length; k++) { + int x = point.x + dx[k]; + int y = point.y + dy[k]; + + if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { + visited[y][x] = true; + queue.add(new Point(x, y)); + } + } } - rCount--; - } - if (check) { - isSorted = true; + count++; } + return count; } } From b9a90c02aec8a2b233e30de64900eff04253bd43 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 28 Aug 2022 13:49:25 +0900 Subject: [PATCH 236/822] =?UTF-8?q?Revert=20"=EC=88=98=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 6636ecf4c22a2de79d1fbbf960691b7bcc41ff7f. --- .../Shuffle-O-Matic.java" | 244 ++++++++++-------- .../\355\227\214\355\204\260.java" | 244 ++++++++---------- 2 files changed, 244 insertions(+), 244 deletions(-) diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" index 059737c..a5181bd 100644 --- "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" +++ "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" @@ -1,12 +1,22 @@ +import java.awt.Point; import java.io.*; import java.util.*; -public class Solution { +public class Solution3 { static int N; - static int[] card; // 카드 배열 - static boolean isSorted; // 정렬되어있는지 확인 변수 - static int count; // 셔플 횟수 + static int[][] field; // 필드 + static boolean[] hunted; // 몬스터가 잡혔는지 체크 배열 + static boolean[] existed; // 몬스터가 존재하는지 체크 배열 + static int[][] customers; // 고객 좌표 + static int[][] monsters; // 몬스터 좌표 + static int[] dx = { 0, 0, -1, 1 }; // 좌표이동 + static int[] dy = { -1, 1, 0, 0 }; + static int hunterX; // 헌터의 x좌표 + static int hunterY; // 헌터의 y좌표 + static List list; // 몬스터 + 고객 리스트 + static boolean[] checked; // 순열 조합 체크 배열 + static int minTime; // 최소 시간 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -16,143 +26,153 @@ public static void main(String[] args) throws Exception { for (int tc = 1; tc <= T; tc++) { N = Integer.parseInt(br.readLine()); - card = new int[N + 1]; // 카드 - StringTokenizer token = new StringTokenizer(br.readLine()); - for (int i = 1; i <= N; i++) { - card[i] = Integer.parseInt(token.nextToken()); - } + field = new int[N + 1][N + 1]; + monsters = new int[5][2]; + existed = new boolean[5]; + list = new ArrayList(); + customers = new int[5][2]; + int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 - isSorted = false; - count = 0; - - // 0번일 경우 정렬체크 - sortCheck(card); - reverseCheck(card); - - if (isSorted) { // 정렬되어있다면 바로 셔플 - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); - } else { // 아니라면 셔플 시작 - for (int i = 1; i <= 5; i++) { - int[] order = new int[i]; - combination(0, i, order); - if (isSorted) { // 정렬되어있다면 반복문 종료 - break; + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + field[i][j] = Integer.parseInt(token.nextToken()); + + if (field[i][j] != 0) { + size = Math.max(size, Math.abs(field[i][j])); + if (field[i][j] < 0) { // 고객좌표 + customers[Math.abs(field[i][j])][0] = i; + customers[Math.abs(field[i][j])][1] = j; + list.add(field[i][j]); + + } else { // 몬스터 좌표 + monsters[field[i][j]][0] = i; + monsters[field[i][j]][1] = j; + existed[field[i][j]] = true; // 몬스터 존재 체크 + list.add(field[i][j]); + } } - } - if (isSorted) { - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); - } else { - bw.write("#" + String.valueOf(tc) + " -1\n"); + } } - } - bw.flush(); - bw.close(); + hunted = new boolean[5]; - } + int orderSize = size * 2; // 순열 크기 - static void combination(int index, int size, int[] order) { + minTime = Integer.MAX_VALUE; - if (isSorted) { // 정렬되어있다면 함수 종료 - return; - } + checked = new boolean[list.size()]; + int[] order = new int[orderSize]; + combination(0, orderSize, order); // 헌팅시작 - if (index == size) { // 셔플 순서 정해지면 셔플하기 - shuffle(order); - if (isSorted) { - count = index; - } - return; + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); } + bw.flush(); + bw.close(); - for (int i = 1; i <= N - 1; i++) { - order[index] = i; - combination(index + 1, size, order); - } } - static void shuffle(int[] order) { - int temp[] = new int[N + 1]; // 임시배열 초기화 - copy(temp); - - for (int i = 0; i < order.length; i++) { - int start = N / 2; // 셔플 위치 - if (order[i] < start) { // 123 | 456 순서일 때 - for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 - start = start - j + 1; // 셔플 인덱스 - for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 - swap(start, start + 1, temp); - start += 2; + static void combination(int index, int size, int[] order) { + if (index == size) { + int time = 0; + hunterX = 1; + hunterY = 1; + for (int i = 0; i < order.length; i++) { + if (order[i] < 0) { //방문 좌표가 고객일 때 + for (int j = 1; j < customers.length; j++) { + if (j == Math.abs(order[i])) { + int x = Math.abs(hunterX - customers[j][1]); //x 거리 + int y = Math.abs(hunterY - customers[j][0]); //y 거리 + time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 + hunterX = customers[j][1]; //헌터 위치 갱신 + hunterY = customers[j][0]; + } } - start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 - } - } else { // 456 | 123 순일때 - if (order[i] == N - 1) { // order[i]가 N-1일 때 - rCopy(temp); // 역순 배열 초기화 } else { - rCopy(temp); - for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 - start = start - j + 1; - for (int k = 1; k <= j; k++) { - swap(start, start + 1, temp); - start += 2; + for (int j = 1; j < monsters.length; j++) { + if (j == order[i]) {//방문 좌표가 몬스터일 때 + int x = Math.abs(hunterX - monsters[j][1]); + int y = Math.abs(hunterY - monsters[j][0]); + time += x + y; + hunterX = monsters[j][1]; + hunterY = monsters[j][0]; } - start = N / 2; } } + if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 + break; + } } + minTime = Math.min(minTime, time); + return; } - sortCheck(temp); // 오름차순 정렬인지 확인 - reverseCheck(temp); // 내림차순 정렬인지 확인 - - } - - static void copy(int[] temp) { //원본 복사 배열(깊은 복사) - for (int i = 1; i <= N; i++) { - temp[i] = card[i]; + for (int i = 0; i < list.size(); i++) { + if (index == 0) { //첫번째 방문 타겟 설정 + if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } else { + if (!checked[i]) { //중복 체크 + if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add + order[index] = list.get(i); + checked[i] = true; + combination(index + 1, size, order); + checked[i] = false; + } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } + } } } - static void rCopy(int[] temp) { //123 456 -> 456 123 - for (int i = 1; i <= N / 2; i++) { - swap(i, (N / 2) + i, temp); - } - } + static int hunting(int target) { // BFS로 푸는 로직 - static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 - int temp2 = temp[a]; - temp[a] = temp[b]; - temp[b] = temp2; - } + int count = 0; - static void sortCheck(int[] arr) { //오름차순 정렬 - boolean check = true; - for (int i = 1; i <= N; i++) { - if (arr[i] != i) { - check = false; - break; - } - } + Queue queue = new LinkedList(); + queue.add(new Point(hunterX, hunterY)); - if (check) { - isSorted = true; - } - } + boolean[][] visited = new boolean[N + 1][N + 1]; + visited[hunterY][hunterX] = true; - static void reverseCheck(int[] arr) { //내림차순 정렬 - boolean check = true; - int rCount = N; - for (int i = 1; i <= N; i++) { - if (arr[i] != rCount) { - check = false; - break; + while (!queue.isEmpty()) { + int qSize = queue.size(); + for (int j = 0; j < qSize; j++) { + Point point = queue.poll(); + if (field[point.y][point.x] == target) { + hunterX = point.x; + hunterY = point.y; + return count; + } + for (int k = 0; k < dx.length; k++) { + int x = point.x + dx[k]; + int y = point.y + dy[k]; + + if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { + visited[y][x] = true; + queue.add(new Point(x, y)); + } + } } - rCount--; - } - if (check) { - isSorted = true; + count++; } + return count; } } diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" index 27c3150..4e256e5 100644 --- "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" +++ "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" @@ -1,22 +1,12 @@ -import java.awt.Point; import java.io.*; import java.util.*; -public class Solution { +public class Solution2 { static int N; - static int[][] field; // 필드 - static boolean[] hunted; // 몬스터가 잡혔는지 체크 배열 - static boolean[] existed; // 몬스터가 존재하는지 체크 배열 - static int[][] customers; // 고객 좌표 - static int[][] monsters; // 몬스터 좌표 - static int[] dx = { 0, 0, -1, 1 }; // 좌표이동 - static int[] dy = { -1, 1, 0, 0 }; - static int hunterX; // 헌터의 x좌표 - static int hunterY; // 헌터의 y좌표 - static List list; // 몬스터 + 고객 리스트 - static boolean[] checked; // 순열 조합 체크 배열 - static int minTime; // 최소 시간 + static int[] card; // 카드 배열 + static boolean isSorted; // 정렬되어있는지 확인 변수 + static int count; // 셔플 횟수 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -26,47 +16,36 @@ public static void main(String[] args) throws Exception { for (int tc = 1; tc <= T; tc++) { N = Integer.parseInt(br.readLine()); - field = new int[N + 1][N + 1]; - monsters = new int[5][2]; - existed = new boolean[5]; - list = new ArrayList(); - customers = new int[5][2]; - int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 - + card = new int[N + 1]; // 카드 + StringTokenizer token = new StringTokenizer(br.readLine()); for (int i = 1; i <= N; i++) { - StringTokenizer token = new StringTokenizer(br.readLine()); - for (int j = 1; j <= N; j++) { - field[i][j] = Integer.parseInt(token.nextToken()); - - if (field[i][j] != 0) { - size = Math.max(size, Math.abs(field[i][j])); - if (field[i][j] < 0) { // 고객좌표 - customers[Math.abs(field[i][j])][0] = i; - customers[Math.abs(field[i][j])][1] = j; - list.add(field[i][j]); - - } else { // 몬스터 좌표 - monsters[field[i][j]][0] = i; - monsters[field[i][j]][1] = j; - existed[field[i][j]] = true; // 몬스터 존재 체크 - list.add(field[i][j]); - } - } + card[i] = Integer.parseInt(token.nextToken()); + } + isSorted = false; + count = 0; + + // 0번일 경우 정렬체크 + sortCheck(card); + reverseCheck(card); + + if (isSorted) { // 정렬되어있다면 바로 셔플 + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { // 아니라면 셔플 시작 + for (int i = 1; i <= 5; i++) { + int[] order = new int[i]; + combination(0, i, order); + if (isSorted) { // 정렬되어있다면 반복문 종료 + break; + } + } + if (isSorted) { + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { + bw.write("#" + String.valueOf(tc) + " -1\n"); } } - hunted = new boolean[5]; - - int orderSize = size * 2; // 순열 크기 - - minTime = Integer.MAX_VALUE; - - checked = new boolean[list.size()]; - int[] order = new int[orderSize]; - combination(0, orderSize, order); // 헌팅시작 - - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); } bw.flush(); bw.close(); @@ -74,105 +53,106 @@ public static void main(String[] args) throws Exception { } static void combination(int index, int size, int[] order) { - if (index == size) { - int time = 0; - hunterX = 1; - hunterY = 1; - for (int i = 0; i < order.length; i++) { - if (order[i] < 0) { //방문 좌표가 고객일 때 - for (int j = 1; j < customers.length; j++) { - if (j == Math.abs(order[i])) { - int x = Math.abs(hunterX - customers[j][1]); //x 거리 - int y = Math.abs(hunterY - customers[j][0]); //y 거리 - time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 - hunterX = customers[j][1]; //헌터 위치 갱신 - hunterY = customers[j][0]; - } - } - } else { - for (int j = 1; j < monsters.length; j++) { - if (j == order[i]) {//방문 좌표가 몬스터일 때 - int x = Math.abs(hunterX - monsters[j][1]); - int y = Math.abs(hunterY - monsters[j][0]); - time += x + y; - hunterX = monsters[j][1]; - hunterY = monsters[j][0]; - } - } - } - if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 - break; - } + + if (isSorted) { // 정렬되어있다면 함수 종료 + return; + } + + if (index == size) { // 셔플 순서 정해지면 셔플하기 + shuffle(order); + if (isSorted) { + count = index; } - minTime = Math.min(minTime, time); return; } - for (int i = 0; i < list.size(); i++) { - if (index == 0) { //첫번째 방문 타겟 설정 - if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 - order[index] = list.get(i); - checked[i] = true; - hunted[Math.abs(list.get(i))] = true; - existed[Math.abs(list.get(i))] = false; - combination(index + 1, size, order); - checked[i] = false; - hunted[Math.abs(list.get(i))] = false; - existed[Math.abs(list.get(i))] = true; + for (int i = 1; i <= N - 1; i++) { + order[index] = i; + combination(index + 1, size, order); + } + } + + static void shuffle(int[] order) { + int temp[] = new int[N + 1]; // 임시배열 초기화 + copy(temp); + + for (int i = 0; i < order.length; i++) { + int start = N / 2; // 셔플 위치 + if (order[i] < start) { // 123 | 456 순서일 때 + for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 + start = start - j + 1; // 셔플 인덱스 + for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 } - } else { - if (!checked[i]) { //중복 체크 - if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add - order[index] = list.get(i); - checked[i] = true; - combination(index + 1, size, order); - checked[i] = false; - } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add - order[index] = list.get(i); - checked[i] = true; - hunted[Math.abs(list.get(i))] = true; - existed[Math.abs(list.get(i))] = false; - combination(index + 1, size, order); - checked[i] = false; - hunted[Math.abs(list.get(i))] = false; - existed[Math.abs(list.get(i))] = true; + } else { // 456 | 123 순일때 + if (order[i] == N - 1) { // order[i]가 N-1일 때 + rCopy(temp); // 역순 배열 초기화 + } else { + rCopy(temp); + for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 + start = start - j + 1; + for (int k = 1; k <= j; k++) { + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; } } } } + + sortCheck(temp); // 오름차순 정렬인지 확인 + reverseCheck(temp); // 내림차순 정렬인지 확인 + } - static int hunting(int target) { // BFS로 푸는 로직 + static void copy(int[] temp) { //원본 복사 배열(깊은 복사) + for (int i = 1; i <= N; i++) { + temp[i] = card[i]; + } + } - int count = 0; + static void rCopy(int[] temp) { //123 456 -> 456 123 + for (int i = 1; i <= N / 2; i++) { + swap(i, (N / 2) + i, temp); + } + } - Queue queue = new LinkedList(); - queue.add(new Point(hunterX, hunterY)); + static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 + int temp2 = temp[a]; + temp[a] = temp[b]; + temp[b] = temp2; + } - boolean[][] visited = new boolean[N + 1][N + 1]; - visited[hunterY][hunterX] = true; + static void sortCheck(int[] arr) { //오름차순 정렬 + boolean check = true; + for (int i = 1; i <= N; i++) { + if (arr[i] != i) { + check = false; + break; + } + } - while (!queue.isEmpty()) { - int qSize = queue.size(); - for (int j = 0; j < qSize; j++) { - Point point = queue.poll(); - if (field[point.y][point.x] == target) { - hunterX = point.x; - hunterY = point.y; - return count; - } - for (int k = 0; k < dx.length; k++) { - int x = point.x + dx[k]; - int y = point.y + dy[k]; + if (check) { + isSorted = true; + } + } - if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { - visited[y][x] = true; - queue.add(new Point(x, y)); - } - } + static void reverseCheck(int[] arr) { //내림차순 정렬 + boolean check = true; + int rCount = N; + for (int i = 1; i <= N; i++) { + if (arr[i] != rCount) { + check = false; + break; } - count++; + rCount--; + } + if (check) { + isSorted = true; } - return count; } } From 6891e96c371f26b8ed95f0fa3af90aa325ade616 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 28 Aug 2022 13:51:32 +0900 Subject: [PATCH 237/822] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shuffle-O-Matic.java" | 244 ++++++++---------- .../\355\227\214\355\204\260.java" | 226 ++++++++-------- 2 files changed, 230 insertions(+), 240 deletions(-) diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" index a5181bd..059737c 100644 --- "a/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" +++ "b/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" @@ -1,22 +1,12 @@ -import java.awt.Point; import java.io.*; import java.util.*; -public class Solution3 { +public class Solution { static int N; - static int[][] field; // 필드 - static boolean[] hunted; // 몬스터가 잡혔는지 체크 배열 - static boolean[] existed; // 몬스터가 존재하는지 체크 배열 - static int[][] customers; // 고객 좌표 - static int[][] monsters; // 몬스터 좌표 - static int[] dx = { 0, 0, -1, 1 }; // 좌표이동 - static int[] dy = { -1, 1, 0, 0 }; - static int hunterX; // 헌터의 x좌표 - static int hunterY; // 헌터의 y좌표 - static List list; // 몬스터 + 고객 리스트 - static boolean[] checked; // 순열 조합 체크 배열 - static int minTime; // 최소 시간 + static int[] card; // 카드 배열 + static boolean isSorted; // 정렬되어있는지 확인 변수 + static int count; // 셔플 횟수 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -26,47 +16,36 @@ public static void main(String[] args) throws Exception { for (int tc = 1; tc <= T; tc++) { N = Integer.parseInt(br.readLine()); - field = new int[N + 1][N + 1]; - monsters = new int[5][2]; - existed = new boolean[5]; - list = new ArrayList(); - customers = new int[5][2]; - int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 - + card = new int[N + 1]; // 카드 + StringTokenizer token = new StringTokenizer(br.readLine()); for (int i = 1; i <= N; i++) { - StringTokenizer token = new StringTokenizer(br.readLine()); - for (int j = 1; j <= N; j++) { - field[i][j] = Integer.parseInt(token.nextToken()); - - if (field[i][j] != 0) { - size = Math.max(size, Math.abs(field[i][j])); - if (field[i][j] < 0) { // 고객좌표 - customers[Math.abs(field[i][j])][0] = i; - customers[Math.abs(field[i][j])][1] = j; - list.add(field[i][j]); - - } else { // 몬스터 좌표 - monsters[field[i][j]][0] = i; - monsters[field[i][j]][1] = j; - existed[field[i][j]] = true; // 몬스터 존재 체크 - list.add(field[i][j]); - } - } + card[i] = Integer.parseInt(token.nextToken()); + } + isSorted = false; + count = 0; + + // 0번일 경우 정렬체크 + sortCheck(card); + reverseCheck(card); + + if (isSorted) { // 정렬되어있다면 바로 셔플 + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { // 아니라면 셔플 시작 + for (int i = 1; i <= 5; i++) { + int[] order = new int[i]; + combination(0, i, order); + if (isSorted) { // 정렬되어있다면 반복문 종료 + break; + } + } + if (isSorted) { + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); + } else { + bw.write("#" + String.valueOf(tc) + " -1\n"); } } - hunted = new boolean[5]; - - int orderSize = size * 2; // 순열 크기 - - minTime = Integer.MAX_VALUE; - - checked = new boolean[list.size()]; - int[] order = new int[orderSize]; - combination(0, orderSize, order); // 헌팅시작 - - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); } bw.flush(); bw.close(); @@ -74,105 +53,106 @@ public static void main(String[] args) throws Exception { } static void combination(int index, int size, int[] order) { - if (index == size) { - int time = 0; - hunterX = 1; - hunterY = 1; - for (int i = 0; i < order.length; i++) { - if (order[i] < 0) { //방문 좌표가 고객일 때 - for (int j = 1; j < customers.length; j++) { - if (j == Math.abs(order[i])) { - int x = Math.abs(hunterX - customers[j][1]); //x 거리 - int y = Math.abs(hunterY - customers[j][0]); //y 거리 - time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 - hunterX = customers[j][1]; //헌터 위치 갱신 - hunterY = customers[j][0]; - } - } - } else { - for (int j = 1; j < monsters.length; j++) { - if (j == order[i]) {//방문 좌표가 몬스터일 때 - int x = Math.abs(hunterX - monsters[j][1]); - int y = Math.abs(hunterY - monsters[j][0]); - time += x + y; - hunterX = monsters[j][1]; - hunterY = monsters[j][0]; - } - } - } - if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 - break; - } + + if (isSorted) { // 정렬되어있다면 함수 종료 + return; + } + + if (index == size) { // 셔플 순서 정해지면 셔플하기 + shuffle(order); + if (isSorted) { + count = index; } - minTime = Math.min(minTime, time); return; } - for (int i = 0; i < list.size(); i++) { - if (index == 0) { //첫번째 방문 타겟 설정 - if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 - order[index] = list.get(i); - checked[i] = true; - hunted[Math.abs(list.get(i))] = true; - existed[Math.abs(list.get(i))] = false; - combination(index + 1, size, order); - checked[i] = false; - hunted[Math.abs(list.get(i))] = false; - existed[Math.abs(list.get(i))] = true; + for (int i = 1; i <= N - 1; i++) { + order[index] = i; + combination(index + 1, size, order); + } + } + + static void shuffle(int[] order) { + int temp[] = new int[N + 1]; // 임시배열 초기화 + copy(temp); + + for (int i = 0; i < order.length; i++) { + int start = N / 2; // 셔플 위치 + if (order[i] < start) { // 123 | 456 순서일 때 + for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 + start = start - j + 1; // 셔플 인덱스 + for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 } - } else { - if (!checked[i]) { //중복 체크 - if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add - order[index] = list.get(i); - checked[i] = true; - combination(index + 1, size, order); - checked[i] = false; - } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add - order[index] = list.get(i); - checked[i] = true; - hunted[Math.abs(list.get(i))] = true; - existed[Math.abs(list.get(i))] = false; - combination(index + 1, size, order); - checked[i] = false; - hunted[Math.abs(list.get(i))] = false; - existed[Math.abs(list.get(i))] = true; + } else { // 456 | 123 순일때 + if (order[i] == N - 1) { // order[i]가 N-1일 때 + rCopy(temp); // 역순 배열 초기화 + } else { + rCopy(temp); + for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 + start = start - j + 1; + for (int k = 1; k <= j; k++) { + swap(start, start + 1, temp); + start += 2; + } + start = N / 2; } } } } + + sortCheck(temp); // 오름차순 정렬인지 확인 + reverseCheck(temp); // 내림차순 정렬인지 확인 + } - static int hunting(int target) { // BFS로 푸는 로직 + static void copy(int[] temp) { //원본 복사 배열(깊은 복사) + for (int i = 1; i <= N; i++) { + temp[i] = card[i]; + } + } - int count = 0; + static void rCopy(int[] temp) { //123 456 -> 456 123 + for (int i = 1; i <= N / 2; i++) { + swap(i, (N / 2) + i, temp); + } + } - Queue queue = new LinkedList(); - queue.add(new Point(hunterX, hunterY)); + static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 + int temp2 = temp[a]; + temp[a] = temp[b]; + temp[b] = temp2; + } - boolean[][] visited = new boolean[N + 1][N + 1]; - visited[hunterY][hunterX] = true; + static void sortCheck(int[] arr) { //오름차순 정렬 + boolean check = true; + for (int i = 1; i <= N; i++) { + if (arr[i] != i) { + check = false; + break; + } + } - while (!queue.isEmpty()) { - int qSize = queue.size(); - for (int j = 0; j < qSize; j++) { - Point point = queue.poll(); - if (field[point.y][point.x] == target) { - hunterX = point.x; - hunterY = point.y; - return count; - } - for (int k = 0; k < dx.length; k++) { - int x = point.x + dx[k]; - int y = point.y + dy[k]; + if (check) { + isSorted = true; + } + } - if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { - visited[y][x] = true; - queue.add(new Point(x, y)); - } - } + static void reverseCheck(int[] arr) { //내림차순 정렬 + boolean check = true; + int rCount = N; + for (int i = 1; i <= N; i++) { + if (arr[i] != rCount) { + check = false; + break; } - count++; + rCount--; + } + if (check) { + isSorted = true; } - return count; } } diff --git "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" index 4e256e5..b30950b 100644 --- "a/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" +++ "b/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" @@ -16,143 +16,153 @@ public static void main(String[] args) throws Exception { for (int tc = 1; tc <= T; tc++) { N = Integer.parseInt(br.readLine()); - card = new int[N + 1]; // 카드 - StringTokenizer token = new StringTokenizer(br.readLine()); - for (int i = 1; i <= N; i++) { - card[i] = Integer.parseInt(token.nextToken()); - } + field = new int[N + 1][N + 1]; + monsters = new int[5][2]; + existed = new boolean[5]; + list = new ArrayList(); + customers = new int[5][2]; + int size = 0; // 최대 크기 ex 몬스터가 1,2 있으면 최대크기 2 * 2 = 4 - isSorted = false; - count = 0; - - // 0번일 경우 정렬체크 - sortCheck(card); - reverseCheck(card); - - if (isSorted) { // 정렬되어있다면 바로 셔플 - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); - } else { // 아니라면 셔플 시작 - for (int i = 1; i <= 5; i++) { - int[] order = new int[i]; - combination(0, i, order); - if (isSorted) { // 정렬되어있다면 반복문 종료 - break; + for (int i = 1; i <= N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + field[i][j] = Integer.parseInt(token.nextToken()); + + if (field[i][j] != 0) { + size = Math.max(size, Math.abs(field[i][j])); + if (field[i][j] < 0) { // 고객좌표 + customers[Math.abs(field[i][j])][0] = i; + customers[Math.abs(field[i][j])][1] = j; + list.add(field[i][j]); + + } else { // 몬스터 좌표 + monsters[field[i][j]][0] = i; + monsters[field[i][j]][1] = j; + existed[field[i][j]] = true; // 몬스터 존재 체크 + list.add(field[i][j]); + } } - } - if (isSorted) { - bw.write("#" + String.valueOf(tc) + " " + String.valueOf(count) + "\n"); - } else { - bw.write("#" + String.valueOf(tc) + " -1\n"); + } } - } - bw.flush(); - bw.close(); + hunted = new boolean[5]; - } + int orderSize = size * 2; // 순열 크기 - static void combination(int index, int size, int[] order) { + minTime = Integer.MAX_VALUE; - if (isSorted) { // 정렬되어있다면 함수 종료 - return; - } + checked = new boolean[list.size()]; + int[] order = new int[orderSize]; + combination(0, orderSize, order); // 헌팅시작 - if (index == size) { // 셔플 순서 정해지면 셔플하기 - shuffle(order); - if (isSorted) { - count = index; - } - return; + bw.write("#" + String.valueOf(tc) + " " + String.valueOf(minTime) + "\n"); } + bw.flush(); + bw.close(); - for (int i = 1; i <= N - 1; i++) { - order[index] = i; - combination(index + 1, size, order); - } } - static void shuffle(int[] order) { - int temp[] = new int[N + 1]; // 임시배열 초기화 - copy(temp); - - for (int i = 0; i < order.length; i++) { - int start = N / 2; // 셔플 위치 - if (order[i] < start) { // 123 | 456 순서일 때 - for (int j = 1; j <= order[i]; j++) { // order[i]만큼 반복 - start = start - j + 1; // 셔플 인덱스 - for (int k = 1; k <= j; k++) { // 셔플이 끝나면 다음 셔플할 때 시작점이 +2인 인덱스 셔플 - swap(start, start + 1, temp); - start += 2; + static void combination(int index, int size, int[] order) { + if (index == size) { + int time = 0; + hunterX = 1; + hunterY = 1; + for (int i = 0; i < order.length; i++) { + if (order[i] < 0) { //방문 좌표가 고객일 때 + for (int j = 1; j < customers.length; j++) { + if (j == Math.abs(order[i])) { + int x = Math.abs(hunterX - customers[j][1]); //x 거리 + int y = Math.abs(hunterY - customers[j][0]); //y 거리 + time += x + y; //시간은 현재 헌터 위치에서 목표 위치까지의 거리 + hunterX = customers[j][1]; //헌터 위치 갱신 + hunterY = customers[j][0]; + } } - start = N / 2; // order[i]번인 셔플이 끝나면 start 변수 초기화 - } - } else { // 456 | 123 순일때 - if (order[i] == N - 1) { // order[i]가 N-1일 때 - rCopy(temp); // 역순 배열 초기화 } else { - rCopy(temp); - for (int j = 1; j <= N - 1 - order[i]; j++) { // 역순으로 정렬한 후에 위에 반복문 로직과 같음 - start = start - j + 1; - for (int k = 1; k <= j; k++) { - swap(start, start + 1, temp); - start += 2; + for (int j = 1; j < monsters.length; j++) { + if (j == order[i]) {//방문 좌표가 몬스터일 때 + int x = Math.abs(hunterX - monsters[j][1]); + int y = Math.abs(hunterY - monsters[j][0]); + time += x + y; + hunterX = monsters[j][1]; + hunterY = monsters[j][0]; } - start = N / 2; } } + if (time > minTime) { //소요시간이 최소시간보다 길 경우 중간에 빠져나오기 + break; + } } + minTime = Math.min(minTime, time); + return; } - sortCheck(temp); // 오름차순 정렬인지 확인 - reverseCheck(temp); // 내림차순 정렬인지 확인 - - } - - static void copy(int[] temp) { //원본 복사 배열(깊은 복사) - for (int i = 1; i <= N; i++) { - temp[i] = card[i]; + for (int i = 0; i < list.size(); i++) { + if (index == 0) { //첫번째 방문 타겟 설정 + if (list.get(i) > 0 || hunted[Math.abs(list.get(i))]) { //몬스터이거나 해당 번호의 몬스터를 잡은 고객의 위치 + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } else { + if (!checked[i]) { //중복 체크 + if (list.get(i) < 0 && hunted[Math.abs(list.get(i))]) { //해당 번호를 잡은 고객의 위치이면 add + order[index] = list.get(i); + checked[i] = true; + combination(index + 1, size, order); + checked[i] = false; + } else if (list.get(i) > 0 && existed[list.get(i)]) { //잡히지 않은 몬스터이면 add + order[index] = list.get(i); + checked[i] = true; + hunted[Math.abs(list.get(i))] = true; + existed[Math.abs(list.get(i))] = false; + combination(index + 1, size, order); + checked[i] = false; + hunted[Math.abs(list.get(i))] = false; + existed[Math.abs(list.get(i))] = true; + } + } + } } } - static void rCopy(int[] temp) { //123 456 -> 456 123 - for (int i = 1; i <= N / 2; i++) { - swap(i, (N / 2) + i, temp); - } - } + static int hunting(int target) { // BFS로 푸는 로직 - static void swap(int a, int b, int[] temp) { //배열 인덱스 교환 - int temp2 = temp[a]; - temp[a] = temp[b]; - temp[b] = temp2; - } + int count = 0; - static void sortCheck(int[] arr) { //오름차순 정렬 - boolean check = true; - for (int i = 1; i <= N; i++) { - if (arr[i] != i) { - check = false; - break; - } - } + Queue queue = new LinkedList(); + queue.add(new Point(hunterX, hunterY)); - if (check) { - isSorted = true; - } - } + boolean[][] visited = new boolean[N + 1][N + 1]; + visited[hunterY][hunterX] = true; - static void reverseCheck(int[] arr) { //내림차순 정렬 - boolean check = true; - int rCount = N; - for (int i = 1; i <= N; i++) { - if (arr[i] != rCount) { - check = false; - break; + while (!queue.isEmpty()) { + int qSize = queue.size(); + for (int j = 0; j < qSize; j++) { + Point point = queue.poll(); + if (field[point.y][point.x] == target) { + hunterX = point.x; + hunterY = point.y; + return count; + } + for (int k = 0; k < dx.length; k++) { + int x = point.x + dx[k]; + int y = point.y + dy[k]; + + if (x >= 1 && x <= N && y >= 1 && y <= N && !visited[y][x]) { + visited[y][x] = true; + queue.add(new Point(x, y)); + } + } } - rCount--; - } - if (check) { - isSorted = true; + count++; } + return count; } } From 7d7dba69aded8a52e9d8d44f17c315119cda97f7 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:41:17 +0900 Subject: [PATCH 238/822] =?UTF-8?q?=ED=97=8C=ED=84=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\227\214\355\204\260" | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 "08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" diff --git "a/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" new file mode 100644 index 0000000..defed61 --- /dev/null +++ "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" @@ -0,0 +1,106 @@ +import java.util.*; +import java.io.*; + +public class 헌터_A형모의테스트 { + static int[][] map; + static ArrayList arr; // map입력 받다가 몬스터, 집 나오면 넣어줌 + static int[] per; // 몬스터, 집 순열 돌림(단, 몬스터 고객 집 전에 몬스터가 나와야함) + static int[][] perinfo; // 순열 돌린 몬스터, 고객 좌표 + static boolean[] pvis; // 순열 돌릴 때 사용 + static int ans, N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int t = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= t; tc++) { + N = Integer.parseInt(br.readLine()); + arr = new ArrayList<>(); + map = new int[N][N]; + ans = Integer.MAX_VALUE; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if (map[i][j] != 0) { + arr.add(map[i][j]); + } + } + } + + per = new int[arr.size()]; + perinfo = new int[arr.size()][2]; + pvis = new boolean[arr.size()]; + + permutation(0, arr.size(), arr.size()); + for (int i = 0; i < per.length; i++) + System.out.print(per[i] + " "); + System.out.println(); + System.out.printf("#%d %d\n", tc, ans); + } + } + + // arr갖고 방문할 순열 만들어줌, 조건 고려하지 않고 일단 그냥 다 만듦 + static void permutation(int index, int n, int m) { + if (index == m) { + check(); + return; + } + for (int i = 0; i < n; i++) { + if (pvis[i] == false) { + per[index] = arr.get(i); + pvis[i] = true; + permutation(index + 1, n, m); + pvis[i] = false; + } + } + } + + //만든 순열이 조건에 부합하는지 확인, 부합하면 다음 단계로 넘어감 + static void check() { + Loop1: for (int i = 0; i < per.length; i++) { + int check = 0; + if(per[0] < 0) break Loop1; //처음부터 집 방문이면 함수 종료(다음 단계 못감) + if (per[i] < 0) { //per[i]가 음수일 때(집일때) + for (int j = 0; j < i; j++) { + if (per[j] == Math.abs(per[i])) { //앞에서 뽑을 순열 중에 고객의 몬스터가 있는지 확인 + check = 1; + } + } + if (check == 0) //없으면 함수 종료(다음 단계로 못감) + break Loop1; + } + if (i == per.length - 1) + permutationinfo(); + } + } + + // 순열 돌린 몬스터, 집의 좌표 구함 + static void permutationinfo() { + for (int k = 0; k < per.length; k++) { + Loop1: for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (per[k] == map[i][j]) { + perinfo[k][0] = i; + perinfo[k][1] = j; + break Loop1; // 좌표 찾았으면 더 찾지말고 바로 다음 per의 좌표 찾아줌 + } + } + } + } + callength(); + } + + // + static void callength() { + int len = 0; + len = perinfo[0][0] + perinfo[0][1]; + for (int i = 0; i < per.length - 1; i++) { + len += Math.abs(perinfo[i][0] - perinfo[i + 1][0]) + Math.abs(perinfo[i][1] - perinfo[i + 1][1]); + } + ans = Math.min(ans, len); + } + +} From f5b9b209f83ff6bebfb150db322143df7337e9a6 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:53:21 +0900 Subject: [PATCH 239/822] =?UTF-8?q?Delete=20=ED=97=8C=ED=84=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\227\214\355\204\260" | 106 ------------------ 1 file changed, 106 deletions(-) delete mode 100644 "08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" diff --git "a/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" deleted file mode 100644 index defed61..0000000 --- "a/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260" +++ /dev/null @@ -1,106 +0,0 @@ -import java.util.*; -import java.io.*; - -public class 헌터_A형모의테스트 { - static int[][] map; - static ArrayList arr; // map입력 받다가 몬스터, 집 나오면 넣어줌 - static int[] per; // 몬스터, 집 순열 돌림(단, 몬스터 고객 집 전에 몬스터가 나와야함) - static int[][] perinfo; // 순열 돌린 몬스터, 고객 좌표 - static boolean[] pvis; // 순열 돌릴 때 사용 - static int ans, N; - - public static void main(String[] args) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st; - - int t = Integer.parseInt(br.readLine()); - for (int tc = 1; tc <= t; tc++) { - N = Integer.parseInt(br.readLine()); - arr = new ArrayList<>(); - map = new int[N][N]; - ans = Integer.MAX_VALUE; - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - if (map[i][j] != 0) { - arr.add(map[i][j]); - } - } - } - - per = new int[arr.size()]; - perinfo = new int[arr.size()][2]; - pvis = new boolean[arr.size()]; - - permutation(0, arr.size(), arr.size()); - for (int i = 0; i < per.length; i++) - System.out.print(per[i] + " "); - System.out.println(); - System.out.printf("#%d %d\n", tc, ans); - } - } - - // arr갖고 방문할 순열 만들어줌, 조건 고려하지 않고 일단 그냥 다 만듦 - static void permutation(int index, int n, int m) { - if (index == m) { - check(); - return; - } - for (int i = 0; i < n; i++) { - if (pvis[i] == false) { - per[index] = arr.get(i); - pvis[i] = true; - permutation(index + 1, n, m); - pvis[i] = false; - } - } - } - - //만든 순열이 조건에 부합하는지 확인, 부합하면 다음 단계로 넘어감 - static void check() { - Loop1: for (int i = 0; i < per.length; i++) { - int check = 0; - if(per[0] < 0) break Loop1; //처음부터 집 방문이면 함수 종료(다음 단계 못감) - if (per[i] < 0) { //per[i]가 음수일 때(집일때) - for (int j = 0; j < i; j++) { - if (per[j] == Math.abs(per[i])) { //앞에서 뽑을 순열 중에 고객의 몬스터가 있는지 확인 - check = 1; - } - } - if (check == 0) //없으면 함수 종료(다음 단계로 못감) - break Loop1; - } - if (i == per.length - 1) - permutationinfo(); - } - } - - // 순열 돌린 몬스터, 집의 좌표 구함 - static void permutationinfo() { - for (int k = 0; k < per.length; k++) { - Loop1: for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - if (per[k] == map[i][j]) { - perinfo[k][0] = i; - perinfo[k][1] = j; - break Loop1; // 좌표 찾았으면 더 찾지말고 바로 다음 per의 좌표 찾아줌 - } - } - } - } - callength(); - } - - // - static void callength() { - int len = 0; - len = perinfo[0][0] + perinfo[0][1]; - for (int i = 0; i < per.length - 1; i++) { - len += Math.abs(perinfo[i][0] - perinfo[i + 1][0]) + Math.abs(perinfo[i][1] - perinfo[i + 1][1]); - } - ans = Math.min(ans, len); - } - -} From 4e5e5f0b82df1eb2e25eee1d7b908c591f177a03 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:53:42 +0900 Subject: [PATCH 240/822] =?UTF-8?q?Create=20=EC=A0=95=ED=98=B8=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "08.28/\354\240\225\355\230\270\354\241\260" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "08.28/\354\240\225\355\230\270\354\241\260" diff --git "a/08.28/\354\240\225\355\230\270\354\241\260" "b/08.28/\354\240\225\355\230\270\354\241\260" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/08.28/\354\240\225\355\230\270\354\241\260" @@ -0,0 +1 @@ + From 7acca2a3df10e8302b50405b5c4eeda1adbf777a Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:53:53 +0900 Subject: [PATCH 241/822] =?UTF-8?q?Delete=20=EC=A0=95=ED=98=B8=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "08.28/\354\240\225\355\230\270\354\241\260" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "08.28/\354\240\225\355\230\270\354\241\260" diff --git "a/08.28/\354\240\225\355\230\270\354\241\260" "b/08.28/\354\240\225\355\230\270\354\241\260" deleted file mode 100644 index 8b13789..0000000 --- "a/08.28/\354\240\225\355\230\270\354\241\260" +++ /dev/null @@ -1 +0,0 @@ - From c948ff2d2e63ea17859ad1cf5b6a3f39fdf4f235 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:54:46 +0900 Subject: [PATCH 242/822] =?UTF-8?q?Create=20=ED=97=8C=ED=84=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\227\214\355\204\260.java" | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 "08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" diff --git "a/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" new file mode 100644 index 0000000..1ba3e3d --- /dev/null +++ "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" @@ -0,0 +1,107 @@ +package swea; + +import java.util.*; +import java.io.*; + +public class 헌터_A형모의테스트 { + static int[][] map; + static ArrayList arr; // map입력 받다가 몬스터, 집 나오면 넣어줌 + static int[] per; // 몬스터, 집 순열 돌림(단, 몬스터 고객 집 전에 몬스터가 나와야함) + static int[][] perinfo; // 순열 돌린 몬스터, 고객 좌표 + static boolean[] pvis; // 순열 돌릴 때 사용 + static int ans, N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int t = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= t; tc++) { + N = Integer.parseInt(br.readLine()); + arr = new ArrayList<>(); + map = new int[N][N]; + ans = Integer.MAX_VALUE; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if (map[i][j] != 0) { + arr.add(map[i][j]); + } + } + } + + per = new int[arr.size()]; + perinfo = new int[arr.size()][2]; + pvis = new boolean[arr.size()]; + + permutation(0, arr.size(), arr.size()); + for (int i = 0; i < per.length; i++) + System.out.print(per[i] + " "); + System.out.println(); + System.out.printf("#%d %d\n", tc, ans); + } + } + + // arr갖고 방문할 순열 만들어줌, 조건 고려하지 않고 일단 그냥 다 만듦 + static void permutation(int index, int n, int m) { + if (index == m) { + check(); + return; + } + for (int i = 0; i < n; i++) { + if (pvis[i] == false) { + per[index] = arr.get(i); + pvis[i] = true; + permutation(index + 1, n, m); + pvis[i] = false; + } + } + } + + //만든 순열이 조건에 부합하는지 확인, 부합하면 다음 단계로 넘어감 + static void check() { + Loop1: for (int i = 0; i < per.length; i++) { + int check = 0; + if(per[0] < 0) break Loop1; //처음부터 집 방문이면 함수 종료(다음 단계 못감) + if (per[i] < 0) { //per[i]가 음수일 때(집일때) + for (int j = 0; j < i; j++) { + if (per[j] == Math.abs(per[i])) { //앞에서 뽑을 순열 중에 고객의 몬스터가 있는지 확인 + check = 1; + } + } + if (check == 0) //없으면 함수 종료(다음 단계로 못감) + break Loop1; + } + if (i == per.length - 1) + permutationinfo(); + } + } + + // 순열 돌린 몬스터, 집의 좌표 구함 + static void permutationinfo() { + for (int k = 0; k < per.length; k++) { + Loop1: for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (per[k] == map[i][j]) { + perinfo[k][0] = i; + perinfo[k][1] = j; + break Loop1; // 좌표 찾았으면 더 찾지말고 바로 다음 per의 좌표 찾아줌 + } + } + } + } + callength(); + } + + static void callength() { + int len = 0; + len = perinfo[0][0] + perinfo[0][1]; + for (int i = 0; i < per.length - 1; i++) { + len += Math.abs(perinfo[i][0] - perinfo[i + 1][0]) + Math.abs(perinfo[i][1] - perinfo[i + 1][1]); + } + ans = Math.min(ans, len); + } + +} From 00ab5cfc2a9c6b87eab0865b962be33acb46af4e Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sun, 28 Aug 2022 15:08:12 +0900 Subject: [PATCH 243/822] =?UTF-8?q?Update=20=ED=97=8C=ED=84=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\227\214\355\204\260.java" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" index 1ba3e3d..873bb06 100644 --- "a/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" +++ "b/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" @@ -67,7 +67,7 @@ static void check() { if(per[0] < 0) break Loop1; //처음부터 집 방문이면 함수 종료(다음 단계 못감) if (per[i] < 0) { //per[i]가 음수일 때(집일때) for (int j = 0; j < i; j++) { - if (per[j] == Math.abs(per[i])) { //앞에서 뽑을 순열 중에 고객의 몬스터가 있는지 확인 + if (per[j] == Math.abs(per[i])) { //앞에서 뽑 순열 중에 고객의 몬스터가 있는지 확인 check = 1; } } From 64c7d92b6876a0079da0af9252d965a1aac46f8e Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 28 Aug 2022 19:32:49 +0900 Subject: [PATCH 244/822] complete --- .../Main_15172_\355\227\214\355\204\260.java" | 11 ----------- 1 file changed, 11 deletions(-) diff --git "a/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" "b/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" index 5b8617c..b3e4b97 100644 --- "a/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" +++ "b/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" @@ -91,7 +91,6 @@ private static void DFS(int depth, int depthLimit) { // 방문 순서를 조합 count += hunter.dist; } - copy(); // 배열 다시 원상 복귀 result = Math.min(result, count); return; } @@ -125,7 +124,6 @@ private static Coordinates BFS(int x, int y, int target, int totalDist) { Coordinates hunter = new Coordinates(x, y, totalDist); if (tempMap[x][y] == target) { - tempMap[x][y] = 0; return hunter; } @@ -145,7 +143,6 @@ private static Coordinates BFS(int x, int y, int target, int totalDist) { if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY]) { isVisited[nowX][nowY] = true; if (tempMap[nowX][nowY] == target) { - tempMap[nowX][nowY] = 0; // 방문한 타겟들은 0처리 hunter.dist = dist + 1; hunter.x = nowX; hunter.y = nowY; @@ -171,12 +168,4 @@ private static void init() { // 변수 초기화 메소드 allList = new ArrayList<>(); result = Integer.MAX_VALUE / 4; // 오버플로우 방지 } // End of init - - private static void copy() { - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - tempMap[i][j] = map[i][j]; - } - } - } // End of copy } // End of Main class \ No newline at end of file From 88900486d4d2cbe160b4b76fb67d2ff299dd9227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 1 Sep 2022 18:55:21 +0900 Subject: [PATCH 245/822] =?UTF-8?q?Create=201=EB=B2=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1\353\262\210.cpp" | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 "0901_sw/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" diff --git "a/0901_sw/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" "b/0901_sw/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" new file mode 100644 index 0000000..47b3bca --- /dev/null +++ "b/0901_sw/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +using namespace std; + +int N; +vector> house; + +int dfs(vector &visited, int x, int y) { + int minCount = INT_MAX; + for (int i = -15; i <= 15; i++) { + for (int k = -15; k <= 15; k++) { + if (i == x && k == y) continue; + bool flag = true; + vector distance(visited.begin(), visited.end()); + for (int j = 0; j < N; j++) { + int dif = abs(i - house[j][0]) + abs(k - house[j][1]); + if (dif == 0) { //집이 있을 때 + flag = false; + break; + } + if (dif <= house[j][2]) { + distance[j] = min(distance[j], dif); + } + } + if (flag) { + bool isAll = true; + int count = 0; + for (int j = 0; j < N; j++) { + if (distance[j] == INT_MAX) { + isAll = false; + break; + } + count += distance[j]; + } + if (isAll) { + minCount = min(minCount, count); + } + } + } + } + return minCount; +} + +int main() { + int T; cin >> T; + for (int t = 1; t <= T; t++) { + cin >> N; + house.clear(); + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < 3; k++) { + int n; cin >> n; + tmp.push_back(n); + } + house.push_back(tmp); + } + int minCount = INT_MAX; + int minCount2 = INT_MAX; + int minIndex = 3; + for (int i = -15; i <= 15; i++) { + for (int k = -15; k <= 15; k++) { + bool flag = true; + int count = 0; //방문 한 개수 + vector distance(N, INT_MAX); + for (int j = 0; j < N; j++) { + int dif = abs(i - house[j][0]) + abs(k - house[j][1]); + if (dif == 0) { //집이 있을 때 + flag = false; + break; + } + if (dif <= house[j][2]) { + distance[j] = dif; + count += 1; + } + } + if (flag) { + if (count == N) { + int sum = 0; + for (int j = 0; j < N; j++) { + sum += distance[j]; + } + minCount = min(minCount, sum); + minIndex = 1; + } + else if (count > 0 && minIndex > 1) { + int nowCount = dfs(distance, i, k); + if (nowCount < minCount2) { + minIndex = 2; + minCount2 = nowCount; + } + } + } + } + } + if (minIndex == 3) minCount = -1; + if (minIndex == 2) minCount = minCount2; + cout << "#" << t << " " << minCount << endl; + } + return 0; +} From 028a57cfc1ae1956f13345e15175f8eb7d74bcf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 1 Sep 2022 18:55:44 +0900 Subject: [PATCH 246/822] =?UTF-8?q?Create=202=EB=B2=88.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2\353\262\210.cpp" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "0901_sw/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" diff --git "a/0901_sw/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" "b/0901_sw/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" new file mode 100644 index 0000000..eb4d19a --- /dev/null +++ "b/0901_sw/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" @@ -0,0 +1,88 @@ +#include +#include +#include +#include +using namespace std; + +int N; +vector> board; +vector> core; +int maxIndex, minCount; +int dx[] = { 0,1,0,-1 }; +int dy[] = { 1,0,-1,0 }; + +void getCore(vector> &v, int index, int count, int coreCount) { + if (coreCount > maxIndex) { + maxIndex = coreCount; + minCount = count; + } + if (coreCount == maxIndex && minCount > count) { + minCount = count; + } + if (index == core.size()) return; + bool isNone = true; + for (int i = 0; i < 4; i++) { + int len = 0; + int x = core[index].first; + int y = core[index].second; + vector> copy; + for (int i = 0; i < N; i++) { + copy.push_back(v[i]); + } + bool cross = false; + while (true) { + x += dx[i]; + y += dy[i]; + if (0 <= x && x < N && 0 <= y && y < N) { + if (copy[x][y] > 0) { + cross = true; + break; + } + copy[x][y] = 1; + len++; + } + else { + break; + } + } + if (cross) continue; + isNone = false; + getCore(copy, index + 1, count + len,coreCount+1); + if (len == 0) break; + } + if (isNone) { + vector> copy; + for (int i = 0; i < N; i++) { + copy.push_back(v[i]); + } + getCore(copy, index + 1, count, coreCount); + } +} + +void init() { + board.clear(); core.clear(); + maxIndex = 0; minCount = INT_MAX; +} + +int main() +{ + int T; cin >> T; + for (int t = 1; t <= T; t++) { + init(); + cin >> N; + for (int i = 0; i < N; i++) { + vector tmp; + for (int k = 0; k < N; k++) { + int n; cin >> n; + tmp.push_back(n); + if (n == 1) { + core.push_back({ i,k }); + } + } + board.push_back(tmp); + } + getCore(board, 0, 0,0); + cout << "#" << t << " " << minCount << endl; + } + return 0; +} From 5a2deadf9aca164aa6b2c3dae072f8b4df3f9d17 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 1 Sep 2022 20:09:09 +0900 Subject: [PATCH 247/822] solve --- .../1\353\262\210.java" | 119 ++++++++++++++++++ ...0\354\274\200\354\235\264\354\212\244.txt" | 33 +++++ 2 files changed, 152 insertions(+) create mode 100644 "0901_sw/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" create mode 100644 "0901_sw/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" diff --git "a/0901_sw/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" "b/0901_sw/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" new file mode 100644 index 0000000..c72fc90 --- /dev/null +++ "b/0901_sw/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" @@ -0,0 +1,119 @@ +import java.io.*; +import java.util.*; + +public class Solution { + + static int N; + static boolean[][] map; //마을 + static int[][] house; //집 x좌표 y좌표 거리 이차원 배열 + static boolean isSupply; //보급가능 여부 + static int min; //최솟값 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= T; tc++) { + N = Integer.parseInt(br.readLine().trim()); //공백 제거 테스트케이스에 공백이 있었음. + house = new int[N][3]; + isSupply = false; + min = Integer.MAX_VALUE; + + for (int i = 0; i < N; i++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + house[i][0] = Integer.parseInt(token.nextToken()); + house[i][1] = Integer.parseInt(token.nextToken()); + house[i][2] = Integer.parseInt(token.nextToken()); + } + + one(); + + if (!isSupply) { //한개로 해결하지 못하였을 때 + two(); + + } + + if (!isSupply) { //두개로 해결하지 못하였을 때 + min = -1; + } + + bw.write("#"+String.valueOf(tc)+" "+String.valueOf(min)+"\n"); + } + bw.flush(); + bw.close(); + + } + + static void one() { //충전소를 하나 탐색 + + for (int i = -15; i <= 15 ; i++) { // -15부터 15까지 + for (int j = -15; j <= 15; j++) { + boolean isConnected = true; //연결되어있는지 체킹하는 변수 + int sum = 0; + for (int k = 0; k < house.length; k++) { // + int distance = Math.abs(j - house[k][1]) + Math.abs(i - house[k][0]); //거리 계산 + if (distance > house[k][2]) { //영역 밖이면 연결 되어있지 않음 + isConnected = false; + break; + }else { + if (distance != 0) { //거리가 0인경우는 제외 왜냐하면 전기차의 좌표이므로 0이 아닌 경우에는 거리+ + + sum += distance; + }else { + isConnected = false; + break; + } + } + } + if (isConnected) { //연결 되어있는 경우라면 min값을 최소값으로 갱신하고 isSupply를 true로 만들어서 one()에서 탐색 종료 + isSupply = true; + min = Math.min(min,sum); + } + } + } + + } + + static void two() { //2개의 충전소를 탐색 + + for (int i = -15; i <= 15 ; i++) { //똑같이 -15부터 15까지 + for (int j = -15; j <= 15; j++) { + for (int a = -15; a <= 15; a++) { + for (int b = -15; b <= 15; b++) { + if (a == i && b == j ) { //두 개의 충전소의 좌표가 같으면 안됨 + break; + } + else { + + boolean isConnected = true; + int sum = 0; + int count = 0; + for (int k = 0; k < house.length; k++) { + + int distance1 = Math.abs(j - house[k][1]) + Math.abs(i - house[k][0]); //첫번째 충전소 거리차이 + int distance2 = Math.abs(b - house[k][1]) + Math.abs(a - house[k][0]); //두번째 충전소 거리차이 + + if (distance1 > house[k][2] && distance2 > house[k][2]) { //두 충전소의 거리가 허용범위볻 클 경우에는 제외 + isConnected = false; + break; + + }else { //둘중 거리가 허용 범위안에 들어올 때 + if (distance1 != 0 && distance2 != 0) { //거리가 0인 경우는 제외 왜냐하면 충전소의 좌표가 전기차의 좌표와 동일 아니라면 거리++ 충전소++ + sum += Math.min(distance1,distance2); + count++; + } + } + } + + if (isConnected && count == house.length) { //충전소가 연결되어있는 상태이고 개수가 2개일때 min값을 갱신시키고 isSupply값을 true로 반환 + isSupply = true; + min = Math.min(min,sum); + } + } + } + } + } + } + } +} \ No newline at end of file diff --git "a/0901_sw/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" "b/0901_sw/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" new file mode 100644 index 0000000..f0f69b4 --- /dev/null +++ "b/0901_sw/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" @@ -0,0 +1,33 @@ +5 +2 +-2 0 1 +1 3 2 +2 +-1 -1 1 +1 0 2 +10 +3 5 4 +2 6 8 +7 4 10 +6 6 11 +3 3 3 +5 2 8 +0 5 10 +4 7 9 +6 2 5 +1 1 10 +5 +-1 -2 1 +4 -2 1 +7 9 2 +10 10 3 +0 3 1 +8 +1 1 8 +-3 1 8 +-4 0 4 +3 3 6 +-1 1 6 +-4 4 7 +-3 5 4 +-1 -2 4 From 833bef1b86ebb878a1867dc6bdda136f050c20a3 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Fri, 2 Sep 2022 09:18:57 +0900 Subject: [PATCH 248/822] Create readme.md --- 0906/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 0906/readme.md diff --git a/0906/readme.md b/0906/readme.md new file mode 100644 index 0000000..5b6b07a --- /dev/null +++ b/0906/readme.md @@ -0,0 +1,3 @@ +# 09/06(화) +- 탈주범 검거 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpLlKAQ4DFAUq +- 디저트 카페 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5VwAr6APYDFAWu From 076da3feb83ba7eeeef5ffbee83d7101df3321b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sat, 3 Sep 2022 14:35:32 +0900 Subject: [PATCH 249/822] =?UTF-8?q?Create=20=ED=83=88=EC=A3=BC=EB=B2=94?= =?UTF-8?q?=EA=B2=80=EA=B1=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\262\224\352\262\200\352\261\260.java" | 363 ++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 "0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" diff --git "a/0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" "b/0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" new file mode 100644 index 0000000..6a335c3 --- /dev/null +++ "b/0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" @@ -0,0 +1,363 @@ +import java.io.*; +import java.util.*; + +class P { + int x; + int y; + + P(int x, int y) { + this.x = x; + this.y = y; + } +} + +public class Swea_1953_탈주범검거 { + + // N : 세로크기, M : 가로크기, R : 맨홀뚜껑세로, C : 맨홀뚜껑가로, L : 주어진 시간 + static int N, M, R, C, L, map[][], ans = 0; + static boolean visit[][]; + static int dx[] = { -1, 1, 0, 0 }; // 상 하 좌 우 + static int dy[] = { 0, 0, -1, 1 }; + static int dist[][]; + + public static void main(String[] args) throws NumberFormatException, IOException { +// System.setIn(new FileInputStream("res/input.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + + dist = new int[N][M]; + map = new int[N][M]; + visit = new boolean[N][M]; + ans = 0; + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + dist[i][j] = Integer.MAX_VALUE; + } + } + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + + bfs(R, C); // 시작점을 넣어 bfs를 돌린다. + + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (dist[i][j] <= L) { + ans++; + } + } + } + + System.out.println("#" + tc + " " + ans); + + } + + } + + private static void bfs(int x, int y) { // 시작점 값을 잡고 + + Queue

q = new LinkedList<>(); + + + q.add(new P(x, y));// 시작점을 넣고 + visit[x][y] = true; // 방문체크한다. + dist[x][y] = 1; // 값은 1로 시작한다. + + while (!q.isEmpty()) { + P p = q.poll(); + int nx = 0, ny = 0; + + if (map[p.x][p.y] == 1) {// 1 : 상하좌우 + for (int i = 0; i < 4; i++) { + if (i == 0) { // 상 처리 + nx = p.x + dx[i]; // 다음 친구의 x 값 + ny = p.y + dy[i]; // 다음 친구의 y 값 + + for (int j = 0; j < 4; j++) { // 다음 친구의 상하좌우 + if (rangeCheck(nx, ny) && map[nx][ny] != 0 && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 5 || map[nx][ny] == 6) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + else if (i == 1) { // 하 방향 처리 + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 4 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + else if (i == 2) { // 좌 방향 처리 + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { // + - ㄴ ┌ + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 4 || map[nx][ny] == 5) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + else if (i == 3) { // 우 방향 + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { // + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 6 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + + } + } else if (map[p.x][p.y] == 2) {// 2 : 상하 | + + for (int i = 0; i < 4; i++) { + if (i == 0) { // | 의 위와 연결될 수 있는 친구 +, |, ┐ ,┌ + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 5 || map[nx][ny] == 6) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + + if (i == 1) { // | 의 아래(1)와 연결될 수 있는 친구 + │ ┘ └ + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny)&& !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 4 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + } + + } else if (map[p.x][p.y] == 3) {// 3 : __좌우 __23 + + for (int i = 0; i < 4; i++) { + + if (i == 2) { + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 4 || map[nx][ny] == 5) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + if (i == 3) { + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 6 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + } + + } else if (map[p.x][p.y] == 4) {// 4 : 상23우 ㄴ + + for (int i = 0; i < 4; i++) { + + if (i == 0) { + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 5 || map[nx][ny] == 6) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + if (i == 3) { + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 6 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + } + + } else if (map[p.x][p.y] == 5) { // 5 : 0하2우 r + for (int i = 0; i < 4; i++) { + + if (i == 1) { // 하 + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 4 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + if (i == 3) { // 우 + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 6 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + } + + } else if (map[p.x][p.y] == 6) { // 6 : 하좌 + + for (int i = 0; i < 4; i++) { // 상 하 좌 우 구분 해주는 친구 + + if (i == 1) { // 하 일때 + + // 해당하는 값들 다 큐에 넣어주는 친구 + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 4 || map[nx][ny] == 7) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + + } + if (i == 2) { + + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 4 || map[nx][ny] == 5) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + } + + } else if (map[p.x][p.y] == 7) {// 7 : 상좌 + for (int i = 0; i < 4; i++) { + + if (i == 0) { + nx = p.x + dx[i]; + ny = p.y + dy[i]; + + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 2 || map[nx][ny] == 5 || map[nx][ny] == 6) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + if (i == 2) { + nx = p.x + dx[i]; + ny = p.y + dy[i]; + for (int j = 0; j < 4; j++) { + if (rangeCheck(nx, ny) && !visit[nx][ny]) { + if (map[nx][ny] == 1 || map[nx][ny] == 3 || map[nx][ny] == 4 || map[nx][ny] == 5) { + dist[nx][ny] = Math.min(dist[p.x][p.y] + 1, dist[nx][ny]); + q.add(new P(nx, ny)); + visit[nx][ny] = true; + } + } + } + } + } + + } + + } + + } + + private static boolean rangeCheck(int x, int y) { + return (0 <= x && x < N && 0 <= y && y < M); + } + +} From 1a8b0604e37476f82548aeba5bdef8dfad691373 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 3 Sep 2022 18:32:43 +0900 Subject: [PATCH 250/822] solve --- {0906 => 09.05}/readme.md | 0 ...353\262\224 \352\262\200\352\261\260.java" | 295 ++++++++++++++++++ ...\353\262\224\352\262\200\352\261\260.java" | 0 3 files changed, 295 insertions(+) rename {0906 => 09.05}/readme.md (100%) create mode 100644 "09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" rename "0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" => "09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" (100%) diff --git a/0906/readme.md b/09.05/readme.md similarity index 100% rename from 0906/readme.md rename to 09.05/readme.md diff --git "a/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" "b/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" new file mode 100644 index 0000000..e1f5b21 --- /dev/null +++ "b/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" @@ -0,0 +1,295 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Solution { + + static int N; // 세로 크기 + static int M; // 가로 크기 + static int L; // 탈출 후 소요된 시간 + static int[][] map; // 터널 지도 + static boolean[][] visited; // 방문 체크 + static int count = 0; // 도달할 수 있는 지점 + static List thief; // 도둑의 위치 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + int R = Integer.parseInt(token.nextToken()); // 맨홀 뚜껑이 위치한 세로 위치 + int C = Integer.parseInt(token.nextToken()); // 맨홀 뚜껑이 위치한 가로 위치 + L = Integer.parseInt(token.nextToken()); + + map = new int[N][M]; + visited = new boolean[N][M]; + count = 0; + thief = new LinkedList(); + + for (int i = 0; i < N; i++) { + token = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(token.nextToken()); + } + } + + escape(R, C); + + bw.write("#"+String.valueOf(tc)+" "+String.valueOf(count)+"\n"); + } + bw.flush(); + bw.close(); + } + + static void escape(int R, int C) { // 탈출 bfs + Queue queue = new LinkedList(); + queue.add(new Point(C, R)); + visited[R][C] = true; + count++; + thief.add(new Point(C, R)); + + for (int loop = 1; loop < L; loop++) { + int qSize = queue.size(); + for (int i = 0; i < qSize; i++) { // 동시에 진행 + Point point = queue.poll(); + + int direction = map[point.y][point.x]; // 방향 + + switch (direction) { // 방향값에 따른 좌표 이동 + case 1: + int[] x1 = { 0, 0, -1, 1 }; + int[] y1 = { -1, 1, 0, 0 }; + for (int j = 0; j < x1.length; j++) { + int x = point.x + x1[j]; + int y = point.y + y1[j]; + // x 좌표는 0 ~ M-1 y좌표는 0 ~ N -1 , 방문한 적이 없으며 파이프가 있는 곳 + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { //다음 파이크가 연결될 수 있는지 체크 + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + case 2: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + case 3: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 2: + int[] y2 = { -1, 1 }; + for (int j = 0; j < y2.length; j++) { + int x = point.x; + int y = point.y + y2[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 3: + int[] x3 = { -1, 1 }; + + for (int j = 0; j < x3.length; j++) { + int x = point.x + x3[j]; + int y = point.y; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 4: + int[] x4 = { 0, 1 }; + int[] y4 = { -1, 0 }; + + for (int j = 0; j < y4.length; j++) { + int x = point.x + x4[j]; + int y = point.y + y4[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + + } + } + break; + case 5: + int[] x5 = { 0, 1 }; + int[] y5 = { 1, 0 }; + for (int j = 0; j < y5.length; j++) { + int x = point.x + x5[j]; + int y = point.y + y5[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 6: + int[] x6 = { 0, -1 }; + int[] y6 = { 1, 0 }; + for (int j = 0; j < y6.length; j++) { + int x = point.x + x6[j]; + int y = point.y + y6[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 7: + int[] x7 = { 0, -1 }; + int[] y7 = { -1, 0 }; + for (int j = 0; j < y7.length; j++) { + int x = point.x + x7[j]; + int y = point.y + y7[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + } + } + } + } +} diff --git "a/0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" "b/09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" similarity index 100% rename from "0906/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" rename to "09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" From 335612034e056c47187a75b8e433b2598778e995 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 3 Sep 2022 18:36:37 +0900 Subject: [PATCH 251/822] tw --- ...353\262\224 \352\262\200\352\261\260.java" | 295 ------------------ 1 file changed, 295 deletions(-) delete mode 100644 "09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" diff --git "a/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" "b/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" deleted file mode 100644 index e1f5b21..0000000 --- "a/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" +++ /dev/null @@ -1,295 +0,0 @@ -import java.awt.Point; -import java.io.*; -import java.util.*; - -public class Solution { - - static int N; // 세로 크기 - static int M; // 가로 크기 - static int L; // 탈출 후 소요된 시간 - static int[][] map; // 터널 지도 - static boolean[][] visited; // 방문 체크 - static int count = 0; // 도달할 수 있는 지점 - static List thief; // 도둑의 위치 - - public static void main(String[] args) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - - int T = Integer.parseInt(br.readLine()); - - for (int tc = 1; tc <= T; tc++) { - StringTokenizer token = new StringTokenizer(br.readLine()); - N = Integer.parseInt(token.nextToken()); - M = Integer.parseInt(token.nextToken()); - int R = Integer.parseInt(token.nextToken()); // 맨홀 뚜껑이 위치한 세로 위치 - int C = Integer.parseInt(token.nextToken()); // 맨홀 뚜껑이 위치한 가로 위치 - L = Integer.parseInt(token.nextToken()); - - map = new int[N][M]; - visited = new boolean[N][M]; - count = 0; - thief = new LinkedList(); - - for (int i = 0; i < N; i++) { - token = new StringTokenizer(br.readLine()); - for (int j = 0; j < M; j++) { - map[i][j] = Integer.parseInt(token.nextToken()); - } - } - - escape(R, C); - - bw.write("#"+String.valueOf(tc)+" "+String.valueOf(count)+"\n"); - } - bw.flush(); - bw.close(); - } - - static void escape(int R, int C) { // 탈출 bfs - Queue queue = new LinkedList(); - queue.add(new Point(C, R)); - visited[R][C] = true; - count++; - thief.add(new Point(C, R)); - - for (int loop = 1; loop < L; loop++) { - int qSize = queue.size(); - for (int i = 0; i < qSize; i++) { // 동시에 진행 - Point point = queue.poll(); - - int direction = map[point.y][point.x]; // 방향 - - switch (direction) { // 방향값에 따른 좌표 이동 - case 1: - int[] x1 = { 0, 0, -1, 1 }; - int[] y1 = { -1, 1, 0, 0 }; - for (int j = 0; j < x1.length; j++) { - int x = point.x + x1[j]; - int y = point.y + y1[j]; - // x 좌표는 0 ~ M-1 y좌표는 0 ~ N -1 , 방문한 적이 없으며 파이프가 있는 곳 - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { //다음 파이크가 연결될 수 있는지 체크 - case 0: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - case 2: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - case 3: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - } - } - break; - case 2: - int[] y2 = { -1, 1 }; - for (int j = 0; j < y2.length; j++) { - int x = point.x; - int y = point.y + y2[j]; - - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { - case 0: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - } - } - break; - case 3: - int[] x3 = { -1, 1 }; - - for (int j = 0; j < x3.length; j++) { - int x = point.x + x3[j]; - int y = point.y; - - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { - case 0: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - } - } - break; - case 4: - int[] x4 = { 0, 1 }; - int[] y4 = { -1, 0 }; - - for (int j = 0; j < y4.length; j++) { - int x = point.x + x4[j]; - int y = point.y + y4[j]; - - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { - case 0: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - - } - } - break; - case 5: - int[] x5 = { 0, 1 }; - int[] y5 = { 1, 0 }; - for (int j = 0; j < y5.length; j++) { - int x = point.x + x5[j]; - int y = point.y + y5[j]; - - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { - case 0: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - } - } - break; - case 6: - int[] x6 = { 0, -1 }; - int[] y6 = { 1, 0 }; - for (int j = 0; j < y6.length; j++) { - int x = point.x + x6[j]; - int y = point.y + y6[j]; - - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { - case 0: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - } - } - break; - case 7: - int[] x7 = { 0, -1 }; - int[] y7 = { -1, 0 }; - for (int j = 0; j < y7.length; j++) { - int x = point.x + x7[j]; - int y = point.y + y7[j]; - - if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { - switch (j) { - case 0: - if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - - case 1: - if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { - visited[y][x] = true; - queue.add(new Point(x, y)); - thief.add(new Point(x, y)); - count++; - } - break; - } - } - } - break; - } - } - } - } -} From e38ad45a215a7952037a1aa483aab04be17c6814 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 3 Sep 2022 18:37:05 +0900 Subject: [PATCH 252/822] solve --- ...353\262\224 \352\262\200\352\261\260.java" | 295 ++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 "09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" diff --git "a/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" "b/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" new file mode 100644 index 0000000..e1f5b21 --- /dev/null +++ "b/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" @@ -0,0 +1,295 @@ +import java.awt.Point; +import java.io.*; +import java.util.*; + +public class Solution { + + static int N; // 세로 크기 + static int M; // 가로 크기 + static int L; // 탈출 후 소요된 시간 + static int[][] map; // 터널 지도 + static boolean[][] visited; // 방문 체크 + static int count = 0; // 도달할 수 있는 지점 + static List thief; // 도둑의 위치 + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + StringTokenizer token = new StringTokenizer(br.readLine()); + N = Integer.parseInt(token.nextToken()); + M = Integer.parseInt(token.nextToken()); + int R = Integer.parseInt(token.nextToken()); // 맨홀 뚜껑이 위치한 세로 위치 + int C = Integer.parseInt(token.nextToken()); // 맨홀 뚜껑이 위치한 가로 위치 + L = Integer.parseInt(token.nextToken()); + + map = new int[N][M]; + visited = new boolean[N][M]; + count = 0; + thief = new LinkedList(); + + for (int i = 0; i < N; i++) { + token = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(token.nextToken()); + } + } + + escape(R, C); + + bw.write("#"+String.valueOf(tc)+" "+String.valueOf(count)+"\n"); + } + bw.flush(); + bw.close(); + } + + static void escape(int R, int C) { // 탈출 bfs + Queue queue = new LinkedList(); + queue.add(new Point(C, R)); + visited[R][C] = true; + count++; + thief.add(new Point(C, R)); + + for (int loop = 1; loop < L; loop++) { + int qSize = queue.size(); + for (int i = 0; i < qSize; i++) { // 동시에 진행 + Point point = queue.poll(); + + int direction = map[point.y][point.x]; // 방향 + + switch (direction) { // 방향값에 따른 좌표 이동 + case 1: + int[] x1 = { 0, 0, -1, 1 }; + int[] y1 = { -1, 1, 0, 0 }; + for (int j = 0; j < x1.length; j++) { + int x = point.x + x1[j]; + int y = point.y + y1[j]; + // x 좌표는 0 ~ M-1 y좌표는 0 ~ N -1 , 방문한 적이 없으며 파이프가 있는 곳 + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { //다음 파이크가 연결될 수 있는지 체크 + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + case 2: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + case 3: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 2: + int[] y2 = { -1, 1 }; + for (int j = 0; j < y2.length; j++) { + int x = point.x; + int y = point.y + y2[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 3: + int[] x3 = { -1, 1 }; + + for (int j = 0; j < x3.length; j++) { + int x = point.x + x3[j]; + int y = point.y; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 4: + int[] x4 = { 0, 1 }; + int[] y4 = { -1, 0 }; + + for (int j = 0; j < y4.length; j++) { + int x = point.x + x4[j]; + int y = point.y + y4[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + + } + } + break; + case 5: + int[] x5 = { 0, 1 }; + int[] y5 = { 1, 0 }; + for (int j = 0; j < y5.length; j++) { + int x = point.x + x5[j]; + int y = point.y + y5[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 6 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 6: + int[] x6 = { 0, -1 }; + int[] y6 = { 1, 0 }; + for (int j = 0; j < y6.length; j++) { + int x = point.x + x6[j]; + int y = point.y + y6[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 4 || map[y][x] == 7) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + case 7: + int[] x7 = { 0, -1 }; + int[] y7 = { -1, 0 }; + for (int j = 0; j < y7.length; j++) { + int x = point.x + x7[j]; + int y = point.y + y7[j]; + + if (x >= 0 && x < M && y >= 0 && y < N && !visited[y][x] && map[y][x] != 0) { + switch (j) { + case 0: + if (map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5 || map[y][x] == 6) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + + case 1: + if (map[y][x] == 1 || map[y][x] == 3 || map[y][x] == 4 || map[y][x] == 5) { + visited[y][x] = true; + queue.add(new Point(x, y)); + thief.add(new Point(x, y)); + count++; + } + break; + } + } + } + break; + } + } + } + } +} From fa44bc6216982a58fe7e3b8cab64cdc853bb42e5 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 4 Sep 2022 03:18:38 +0900 Subject: [PATCH 253/822] complete --- ...353\262\224_\352\262\200\352\261\260.java" | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 "09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" diff --git "a/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" "b/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" new file mode 100644 index 0000000..3d59ccf --- /dev/null +++ "b/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" @@ -0,0 +1,151 @@ +import java.util.*; +import java.io.*; + + +public class Main_1953_탈주범_검거 { + static int N, M, R, C, L; + static int[][] map; + static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 + static int[] dirY = {0, 0, -1, 1}; + static int result; + + static class Coordiantes { + int x; + int y; + int time; + + public Coordiantes(int x, int y, int time) { + this.x = x; + this.y = y; + this.time = time; + } + } // End of Coordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1953.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + + result = 0; + map = new int[N][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + BFS(R, C); + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void BFS(int x, int y) { + Queue que = new LinkedList<>(); + int[][] isVisited2 = new int[N][M]; + + isVisited2[x][y] = 1; + que.offer(new Coordiantes(x, y, 1)); + int nowX; + int nowY; + int time; + int pipe; + + while (!que.isEmpty()) { + Coordiantes cor = que.poll(); + pipe = map[cor.x][cor.y]; + int loopStart = 0; + int loopLimit = 4; + int loopIncrease = 1; + + if (pipe == 2) { + // 상 하 + loopLimit = 2; + } else if (pipe == 3) { + // 좌 우 + loopStart = 2; + } else if (pipe == 4) { + // 상, 우 + loopIncrease = 3; + } else if (pipe == 5) { + // 하, 우 + loopStart = 1; + loopIncrease = 2; + } else if (pipe == 6) { + // 하, 좌 + loopStart = 1; + loopLimit = 3; + } else if (pipe == 7) { + // 상,좌 + loopLimit = 3; + loopIncrease = 2; + } + + for (int i = loopStart; i < loopLimit; i = i + loopIncrease) { + nowX = cor.x + dirX[i]; + nowY = cor.y + dirY[i]; + time = cor.time + 1; + + // 상 하 좌 우 방향 + + if (rangeCheck(nowX, nowY) && isVisited2[nowX][nowY] == 0) { + if ((i == 0 || i == 1) && map[nowX][nowY] == 3) { + // 상 하 방향인데, 3번 파이프는 불가능 + continue; + } else if ((i == 2 || i == 3) && map[nowX][nowY] == 2) { + // 좌 우 방향에서 , 2번 파이프는 불가능 + continue; + } else if (i == 0 && (map[nowX][nowY] == 4 || map[nowX][nowY] == 7)) { + continue; + } else if (i == 1 && (map[nowX][nowY] == 5 || map[nowX][nowY] == 6)) { + continue; + } else if (i == 2 && (map[nowX][nowY] == 6 || map[nowX][nowY] == 7)) { + continue; + } else if (i == 3 && (map[nowX][nowY] == 4 || map[nowX][nowY] == 5)) { + continue; + } + + if (map[nowX][nowY] != 0) { + if (L == time) { + isVisited2[nowX][nowY] = time; + continue; + } + + isVisited2[nowX][nowY] = time; + que.offer(new Coordiantes(nowX, nowY, time)); + } + } + + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (isVisited2[i][j] > 0 && isVisited2[i][j] <= L) { + result++; + } + } + } + + } // End of BFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of rangeCheck +} // End of Main class \ No newline at end of file From b2c992f441fe7ff44d2a5fbf820694e2aae3491d Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Mon, 5 Sep 2022 00:32:52 +0900 Subject: [PATCH 254/822] =?UTF-8?q?Create=20[=EB=AA=A8=EC=9D=98SW=EC=97=AD?= =?UTF-8?q?=EB=9F=89=ED=85=8C=EC=8A=A4=ED=8A=B8]=ED=83=88=EC=A3=BC?= =?UTF-8?q?=EB=B2=94=EA=B2=80=EA=B1=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\262\224\352\262\200\352\261\260.py" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" diff --git "a/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" "b/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" new file mode 100644 index 0000000..c3fa5e8 --- /dev/null +++ "b/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" @@ -0,0 +1,46 @@ +# import sys; sys.stdin = open("input.txt") +from collections import deque + +move = [(0, -1), (0, 1), (-1, 0), (1, 0)] +moves = [[0, 0], [(0, -1), (0, 1), (-1, 0), (1, 0)], [(0, -1), (0, 1)], + [(-1, 0), (1, 0)], [(0, -1), (1, 0)], [(0, 1), (1, 0)], + [(0, 1), (-1, 0)], [(0, -1),(-1, 0)]] + +def count_visited_area(_arr) -> int: + count = 0 + for y in range(n): + for x in range(m): + if _arr[y][x] : count+=1 + return count + +def is_available(_delta, _next_pipe) -> bool : + if _delta == move[0] and _next_pipe in [1, 2, 5, 6]: return True + if _delta == move[1] and _next_pipe in [1, 2, 4, 7]: return True + if _delta == move[2] and _next_pipe in [1, 3, 4, 5]: return True + if _delta == move[3] and _next_pipe in [1, 3, 6, 7]: return True + return False + +def bfs(_start_x, _start_y, _time) -> int: + visited = [[0]*m for _ in range(n)] + queue = deque() + queue.append((c, r)); visited[r][c] = 1 + while queue: + present = queue.popleft() + present_pipe_type = arr[present[1]][present[0]] + for delta in moves[present_pipe_type]: + next_x, next_y = present[0]+delta[0], present[1]+delta[1] + if visited[present[1]][present[0]] == _time: continue + if 0<=next_x Date: Mon, 5 Sep 2022 15:49:35 +0900 Subject: [PATCH 255/822] solve --- ...00\355\212\270\354\271\264\355\216\230.py" | 54 +++++++++++++++++++ ...45\353\262\224\352\262\200\352\261\260.py" | 50 +++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 "09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" create mode 100644 "09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" diff --git "a/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" "b/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" new file mode 100644 index 0000000..958cef1 --- /dev/null +++ "b/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" @@ -0,0 +1,54 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +T = int(input()) + +dy = [-1, 1, 1, -1] +dx = [1, 1, -1, -1] + + +def makeDiamond(y, x, dir, path, dessert): + global diamonds, desserts + nY = y + dy[dir] + nX = x + dx[dir] + # 탈출 조건 + if dir == 3 and path[0] == (nY, nX): + if len(diamonds) < len(path): + diamonds = path[:] + desserts = dessert[:] + # 직진 + if 0 <= nY < n and 0 <= nX < n: + if matrix[nY][nX] not in dessert: + makeDiamond(nY, nX, dir, path + [(nY, nX)], dessert + [matrix[nY][nX]]) + + # 방향 전환 + if dir < 3: + nY = y + dy[dir + 1] + nX = x + dx[dir + 1] + if 0 <= nY < n and 0 <= nX < n: + # 탈출 조건 + if dir == 2 and path[0] == (nY, nX): + if len(diamonds) < len(path): + diamonds = path[:] + desserts = dessert[:] + else: + if matrix[nY][nX] not in dessert: + makeDiamond(nY, nX, dir + 1, path + [(nY, nX)], dessert + [matrix[nY][nX]]) + + +for test_case in range(1, T+1): + n = int(input()) + matrix = [list(map(int, input().split())) for _ in range(n)] + diamonds = [] + desserts = [] + for y in range(n): + for x in range(n): + makeDiamond(y, x, 0, [(y, x)], [matrix[y][x]]) + + if not desserts: + print("#{} -1".format(test_case)) + else: + print("#{} {}".format(test_case, len(desserts))) + + diff --git "a/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" "b/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" new file mode 100644 index 0000000..c08214f --- /dev/null +++ "b/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" @@ -0,0 +1,50 @@ +import sys +from collections import deque +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +T = int(input()) + +pipeList = [[], [0, 1, 2, 3], [0, 1], [2, 3], [0, 3], [1, 3], [1, 2], [0, 2]] +typeList = [1, 0, 3, 2] + +dy = [-1, 1, 0, 0] +dx = [0, 0, -1, 1] + +def bfs(depth, y, x): + q = deque() + q.append((depth, y, x)) + while q: + nowDepth, nowY, nowX = q.popleft() + if nowDepth == l-1: + continue + pipe = matrix[nowY][nowX] + for dir in pipeList[pipe]: + nY = nowY + dy[dir] + nX = nowX + dx[dir] + if nY < 0 or nX < 0 or nY >= n or nX >= m: + continue + if matrix[nY][nX] == 0: + continue + if visited[nY][nX] > 0: + continue + nextPipe = matrix[nY][nX] + if typeList[dir] in pipeList[nextPipe]: + visited[nY][nX] = nowDepth + 1 + q.append((nowDepth + 1, nY, nX)) + +for test_case in range(1, T+1): + n, m, r, c, l = map(int, input().split()) + matrix = [list(map(int, input().split())) for _ in range(n)] + visited = [[0] * m for _ in range(n)] + result = 0 + visited[r][c] = 1 + bfs(0, r, c) + + for y in range(n): + for x in range(m): + if visited[y][x]: + result += 1 + + print("#{} {}".format(test_case, result)) + + From c1f9469de1e96a62cfd6abf7f59003aee263953c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Mon, 5 Sep 2022 20:38:13 +0900 Subject: [PATCH 256/822] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bc746a3..fd6e360 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,4 @@ - 스터디마다 작성하신 코드를 제출하는 곳입니다. - 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 +- https://docs.google.com/spreadsheets/d/1s-QDZtheT136zsQCac_3vdVNnNUHj7P-gIowrXlDKU4/edit#gid=0 From 5b5618f2674fa782ecff0053df5fd48c5114a4c7 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Mon, 5 Sep 2022 22:15:29 +0900 Subject: [PATCH 257/822] Update README.md . --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index fd6e360..5449470 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # StudyCodes -Study
-- [👉일정 관리용 노션👈]( https://wealthy-perfume-4c7.notion.site/SSAFY-Moblie-8th-Study-3eee2886ef5d49b6bdb6b04fbb9da97f)
+Study
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From 20f4ec2086ec2acdd58a9285860700098a438245 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Tue, 6 Sep 2022 11:23:10 +0900 Subject: [PATCH 258/822] complete --- ...355\212\270_\354\271\264\355\216\230.java" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" diff --git "a/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" "b/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" new file mode 100644 index 0000000..19091e3 --- /dev/null +++ "b/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" @@ -0,0 +1,92 @@ +import java.util.*; +import java.io.*; + +// 디저트를 가장 많이 먹을 수 있는 경우의 디저트 종류 수를 출력 +// 디저트를 먹을 수 없는 경우 -1을 출력 +// 탐색하는 방향에서 직사각형의 특징을 생각해야 됨 -> 직사각형의 특징. 마주보는 변의 길이가 같음 +public class Main_2105_디저트_카페 { + static int N; + static int[][] map; + static int[] dirX = {-1, 1, 1, -1}; // 대각선 방향으로 시계방향. (상우 -> 하우 -> 하좌 -> 상좌) + static int[] dirY = {1, 1, -1, -1}; + static boolean[][] isVisited; // map의 경로상 방문여부를 체크하는 배열 + static boolean[] isVisitedDesert; // 방문한 디저트가 겹치는지 여부를 파악하기 위한 배열 + static int maxResult; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2105.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); // 변수 초기화 + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + // 완전탐색 & 백트래킹 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (i == 0 && (j == 0 || j == N - 1)) continue; + else if (i == N - 1 && (j == 0 || j == N - 1)) continue; + + isVisited[i][j] = true; + isVisitedDesert[map[i][j]] = true; + DFS(i, j, i, j, 1, 0); + isVisitedDesert[map[i][j]] = false; + isVisited[i][j] = false; + } + } + + sb.append(maxResult).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int startX, int startY, int x, int y, int counting, int index) { + for (int i = index; i < 4; i++) { + int nowX = x + dirX[i]; + int nowY = y + dirY[i]; + + // 시작한 곳으로 돌아오면 중지, 재귀 탈출 조건 + // counting이 3이상이고, counting이 짝수. + if (startX == nowX && startY == nowY && counting >= 4) { + maxResult = Math.max(maxResult, counting); + return; + } + + // 만약 i의 값으로 계속 이동할 수 있으면 계속해서 이동. + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && !isVisitedDesert[map[nowX][nowY]]) { + + isVisited[nowX][nowY] = true; + isVisitedDesert[map[nowX][nowY]] = true; + DFS(startX, startY, nowX, nowY, counting + 1, i); + isVisitedDesert[map[nowX][nowY]] = false; + isVisited[nowX][nowY] = false; + } + } + + } // End of DFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { // 변수를 초기화 하는 메소드 + map = new int[N][N]; + isVisited = new boolean[N][N]; + isVisitedDesert = new boolean[101]; + maxResult = -1; + } // End of init +} // End of Main class From dce664ac552d232a8157af4a898ce1ee9f830e7f Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Tue, 6 Sep 2022 11:25:47 +0900 Subject: [PATCH 259/822] complete --- ...4\354\240\200\355\212\270_\354\271\264\355\216\230.java" | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git "a/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" "b/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" index 19091e3..da4829b 100644 --- "a/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" +++ "b/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" @@ -59,8 +59,8 @@ private static void DFS(int startX, int startY, int x, int y, int counting, int int nowX = x + dirX[i]; int nowY = y + dirY[i]; - // 시작한 곳으로 돌아오면 중지, 재귀 탈출 조건 - // counting이 3이상이고, counting이 짝수. + // 재귀 탈출 조건 + // counting이 4이상이고, 시작한 곳으로 돌아오면 중지, if (startX == nowX && startY == nowY && counting >= 4) { maxResult = Math.max(maxResult, counting); return; @@ -71,6 +71,8 @@ private static void DFS(int startX, int startY, int x, int y, int counting, int isVisited[nowX][nowY] = true; isVisitedDesert[map[nowX][nowY]] = true; + + // 만약 i의 값으로 계속 이동할 수 있으면 계속해서 이동. DFS(startX, startY, nowX, nowY, counting + 1, i); isVisitedDesert[map[nowX][nowY]] = false; isVisited[nowX][nowY] = false; From c4da5b19cbdad4cf6f64bf6343a8296f1e2d3f87 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 7 Sep 2022 12:35:18 +0900 Subject: [PATCH 260/822] =?UTF-8?q?Create=20=EB=B3=B4=ED=98=B8=ED=95=84?= =?UTF-8?q?=EB=A6=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\230\270\355\225\204\353\246\204.java" | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 "0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" diff --git "a/0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" "b/0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" new file mode 100644 index 0000000..d6bf3b3 --- /dev/null +++ "b/0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" @@ -0,0 +1,99 @@ +import java.util.*; +import java.io.*; + +public class 보호필름_2112_모의SW테스트 { + + static int[][] film, copy; + static int D, W, k, ans, injectioncnt; + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int t = Integer.parseInt(br.readLine()); + for(int tc=1; tc<=t; tc++) { + st = new StringTokenizer(br.readLine()); + D = Integer.parseInt(st.nextToken()); + W = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + + film = new int[D][W]; + copy = new int[D][W]; + ans = Integer.MAX_VALUE; + for(int i=0; i Date: Wed, 7 Sep 2022 15:39:56 +0900 Subject: [PATCH 261/822] solve --- ...\355\230\270\355\225\204\353\246\204.java" | 0 .../README.md" | 8 +++ ...0\353\212\224 \355\212\270\353\237\255.kt" | 65 +++++++++++++++++++ 3 files changed, 73 insertions(+) rename "0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" => "09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" (100%) create mode 100644 "09.12/\354\241\260\354\210\230\354\227\260/README.md" create mode 100644 "09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" diff --git "a/0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" "b/09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" similarity index 100% rename from "0912/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" rename to "09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" new file mode 100644 index 0000000..5449470 --- /dev/null +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -0,0 +1,8 @@ +# StudyCodes +Study
+ +## Introduction
+- 스터디마다 작성하신 코드를 제출하는 곳입니다. +- 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! +- 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 +- https://docs.google.com/spreadsheets/d/1s-QDZtheT136zsQCac_3vdVNnNUHj7P-gIowrXlDKU4/edit#gid=0 diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" "b/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" new file mode 100644 index 0000000..7870e67 --- /dev/null +++ "b/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" @@ -0,0 +1,65 @@ +package com.ssafy.algorithm + + +import java.util.* +import kotlin.collections.ArrayList + +fun main() { + val sl = Solution() + val bridge_length = 100 + val weight = 100 + val truck_weights = intArrayOf(10,10,10,10,10,10,10,10,10,10) + println(sl.solution(bridge_length, weight, truck_weights)) + +} + +class Solution { + lateinit var cross: BooleanArray //현재 트럭이 다리에 있는지 체크 배열 + fun solution(bridge_length: Int, weight: Int, truck_weights: IntArray): Int { + var answer = 0 + val wait: Queue = LinkedList() + val bridge: Queue = LinkedList() + + for (i in truck_weights){ //대기 트럭 + wait.offer(i) + } + + var possible = 0 + var time = 0 //시간 + + cross = BooleanArray(truck_weights.size) + val trucks = IntArray(truck_weights.size) + var index = 0 + while (true) { + time++ + if (wait.isEmpty() && bridge.isEmpty()) break //대기 트럭이랑 다리에 트럭 큐가 비어있으면 종료 + + if (wait.isNotEmpty()){ //대기트럭이 있을 때 + if (possible + wait.peek() <= weight) { //현재 다리위에 있는 트럭 + 트럭의 무게가 다리가 버틸 수 있는 무게라면 트럭추가 + val truckWeight = wait.poll() + possible += truckWeight + bridge.offer(truckWeight) + cross[index] = true + index++ + } + } + + + + for (i in cross.indices){ + if (cross[i]){ //다리위에 있는 트럭의 인덱스 + trucks[i]++ + if (trucks[i] >= bridge_length && cross[i]){ //다리를 지난경우 + cross[i] = false + possible -= bridge.poll() //다리가 버틸 수 있는 무게 증가 + } + } + + + } + } + + return time + } +} + From 401f27998c9722c287adde10b3a6c0df36cfeba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:42:53 +0900 Subject: [PATCH 262/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 5449470..85a0620 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,5 +1,5 @@ -# StudyCodes -Study
+ +Study
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From 9b704c9380cbf6eeb046eccabbb043499e629bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:44:01 +0900 Subject: [PATCH 263/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 85a0620..8944f72 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,5 +1,5 @@ -Study
+Study
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From cf42d64a44338dd18e986481d32e371a446883c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:44:14 +0900 Subject: [PATCH 264/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 8944f72..19089f1 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,5 +1,5 @@ -Study
+Study
## Introduction
- 스터디마다 작성하신 코드를 제출하는 곳입니다. From 62f4e1dfd0d33ea377a53dca00df85ee84f6f142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:44:57 +0900 Subject: [PATCH 265/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 19089f1..646ac42 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,8 +1,8 @@ Study
-## Introduction
-- 스터디마다 작성하신 코드를 제출하는 곳입니다. +## 프로그래머스 Level 1,2
+- 다리를 지나는 트럭 - 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 - https://docs.google.com/spreadsheets/d/1s-QDZtheT136zsQCac_3vdVNnNUHj7P-gIowrXlDKU4/edit#gid=0 From bb31f2ce12c3d8bb5321e3010e96e23464caf0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:45:55 +0900 Subject: [PATCH 266/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 646ac42..a6f44de 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -2,7 +2,7 @@ Study
## 프로그래머스 Level 1,2
-- 다리를 지나는 트럭 +- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 - 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 - https://docs.google.com/spreadsheets/d/1s-QDZtheT136zsQCac_3vdVNnNUHj7P-gIowrXlDKU4/edit#gid=0 From 9855adc83e3176a26316a050f4be30380fd41df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:48:30 +0900 Subject: [PATCH 267/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index a6f44de..cb32e12 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,5 +1,5 @@ -Study
+Study
## 프로그래머스 Level 1,2
- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 From 2c186f204d7bc700fa618820d266253c99c89014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:49:40 +0900 Subject: [PATCH 268/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index cb32e12..226c9cb 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -3,6 +3,6 @@ ## 프로그래머스 Level 1,2
- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 -- 스터디 문제가 정해지면 가장 빨리 제출하시는 분이 폴더를 생성해주세요! +- 성격 유형 검사하기(2022 KAKAO TECH INTERNSHIP) : https://school.programmers.co.kr/learn/courses/30/lessons/118666 - 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 - https://docs.google.com/spreadsheets/d/1s-QDZtheT136zsQCac_3vdVNnNUHj7P-gIowrXlDKU4/edit#gid=0 From 9434a8ce6917d198525d11a1a7461cba92f9fe61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:51:20 +0900 Subject: [PATCH 269/822] solve --- ...00\354\202\254\355\225\230\352\270\260.kt" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" "b/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" new file mode 100644 index 0000000..0bb4c4a --- /dev/null +++ "b/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" @@ -0,0 +1,95 @@ +import java.lang.StringBuilder +import kotlin.collections.ArrayList + +fun main() { + val sl = Solution() + val survey = arrayOf("TR", "RT", "TR") + val choices = intArrayOf(7, 1, 3) + + println(sl.solution(survey, choices)) +} + +class Solution { + lateinit var paper: ArrayList> + fun solution(survey: Array, choices: IntArray): String { + val sb = StringBuilder() + + val arr = arrayOf('R', 'T', 'C', 'F', 'J', 'M', 'A', 'N') + paper = ArrayList() + + for (i in 0..7) { //초기 세팅 + paper.add(Pair(arr[i], 0)) + } + + for (i in survey.indices) { //성격 유형 점수 갱신 + getScore(survey[i], choices[i]) + } + + for (i in paper.indices step 2){ //성격 유형 만들기 + val score = paper[i].second + val score2 = paper[i+1].second + + if (score >= score2) sb.append(paper[i].first) + else sb.append(paper[i+1].first) + } + + var answer = sb.toString() + + return answer + } + + fun getScore(personality: String, score: Int) { + when (score) { + 1 -> + for (i in paper.indices) { + if (personality[0] == paper[i].first) { + paper.set(i, Pair(paper[i].first, paper[i].second + 3)) + } + } + 2 -> + for (i in paper.indices) { + if (personality[0] == paper[i].first) { + paper.set(i, Pair(paper[i].first, paper[i].second + 2)) + } + } + 3 -> + for (i in paper.indices) { + if (personality[0] == paper[i].first) { + paper.set(i, Pair(paper[i].first, paper[i].second + 1)) + } + } + 5 -> + for (i in paper.indices) { + if (personality[1] == paper[i].first) { + paper.set(i, Pair(paper[i].first, paper[i].second + 1)) + } + } + 6 -> + for (i in paper.indices) { + if (personality[1] == paper[i].first) { + paper.set(i, Pair(paper[i].first, paper[i].second + 2)) + } + } + 7 -> + for (i in paper.indices) { + if (personality[1] == paper[i].first) { + paper.set(i, Pair(paper[i].first, paper[i].second + 3)) + } + } + } + + } +} + + + + + + + + + + + + + From 3f5723154e5ae2981e91ee42ac5d3f37476dfa82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:55:02 +0900 Subject: [PATCH 270/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 226c9cb..832b981 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,5 +1,5 @@ -Study
+Study
## 프로그래머스 Level 1,2
- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 From 378a18d9ed9048307a2327c26c0a8c2a3f354cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Thu, 8 Sep 2022 15:59:04 +0900 Subject: [PATCH 271/822] Update README.md --- "09.12/\354\241\260\354\210\230\354\227\260/README.md" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" index 832b981..9c686d7 100644 --- "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.12/\354\241\260\354\210\230\354\227\260/README.md" @@ -4,5 +4,4 @@ ## 프로그래머스 Level 1,2
- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 - 성격 유형 검사하기(2022 KAKAO TECH INTERNSHIP) : https://school.programmers.co.kr/learn/courses/30/lessons/118666 -- 폴더 경로 : 날짜(MM.DD)/사용자이름/문제 -- https://docs.google.com/spreadsheets/d/1s-QDZtheT136zsQCac_3vdVNnNUHj7P-gIowrXlDKU4/edit#gid=0 +- 위장 : https://school.programmers.co.kr/learn/courses/30/lessons/42578 From ffaf1e8aa42775ff8185f5e91f1abec2348a9a8a Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 8 Sep 2022 15:57:56 +0900 Subject: [PATCH 272/822] solve --- .../\354\234\204\354\236\245.kt" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" "b/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" new file mode 100644 index 0000000..49ebaba --- /dev/null +++ "b/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" @@ -0,0 +1,67 @@ +package com.ssafy.algorithm + + +import java.util.* +import kotlin.collections.ArrayList +import kotlin.collections.HashSet + +fun main() { + val sl = Solution() +// val clothes = arrayOf( +// arrayOf("yellow_hat", "headgear"), arrayOf("blue_sunglasses", "eyewear"), +// arrayOf("green_turban", "headgear") +// ) + val clothes = arrayOf( + arrayOf("crow_mask", "face"), arrayOf("blue_sunglasses", "face"), + arrayOf("smoky_makeup", "face") + ) + println(sl.solution(clothes)) + +} + +class Solution { + lateinit var clothesType : HashSet //옷 종류 담는 set + lateinit var checked : BooleanArray //옷 종류 중복 체크 + lateinit var clothList: ArrayList> //옷 리스트 + var answer = 0 + fun solution(clothes: Array>): Int { + answer = 0 + clothesType = HashSet() + for (i in clothes){ //옷 종류 담기 + clothesType.add(i[1]) + } + clothList = ArrayList() + checked = BooleanArray(clothesType.size) + for (i in clothes){ // 옷 리스트에 정보 담기 + clothList.add(Pair(i[0],clothesType.indexOf(i[1]))) + } + + if(clothesType.size == 30){ //1번 정답 시간초과 남 조합으로 못품 + answer = 1073741823; + }else{ + for (i in 1 .. clothesType.size){ + val clothArr = Array(i){""} + permulation(0,i,0, clothArr) + } + } + return answer + } + + fun permulation(index : Int, size : Int, start : Int, clothArr : Array){ //옷 조합 + if (index == size){ + answer++ + return + } + + for (i in start until clothList.size){ + if (!checked[clothList[i].second]){ + clothArr[index] = clothList[i].first + checked[clothList[i].second] = true + permulation(index+1,size,i+1,clothArr) + checked[clothList[i].second] = false + } + } + + } +} + From f3d22e2776792a5d4d68611966b594590d9d9456 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Fri, 9 Sep 2022 11:09:03 +0900 Subject: [PATCH 273/822] complete --- ...355\230\270_\355\225\204\353\246\204.java" | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 "09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" new file mode 100644 index 0000000..78348c1 --- /dev/null +++ "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" @@ -0,0 +1,129 @@ +import java.util.*; +import java.io.*; + +// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V1SYKAaUDFAWu + + +// 성능검사를 통과할 수 있는 약품의 최소 투입 횟수이다. 약품을 투입하지 않고도 성능검사를 통과하는 경우에는 0을 출력한다. +// for (int[] arr : tempArr) System.out.println(Arrays.toString(arr)); +public class Main_2112_보호_필름 { + static int D, W, K, result; + static int[][] arr; + static int[] isVisited; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2112.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + D = Integer.parseInt(st.nextToken()); + W = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + init(); + + for (int i = 0; i < D; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < W; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + DFS(0, 0); + sb.append(result).append('\n'); + + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int depth, int index) { + + // 약품이 투여되지 않았을 때와 한번이라도 투여됬을 때도 searching시작 하기위해 최소 조건을 줌 + if (depth <= K) { + // 가지치기 조건. + // 지금까지 최소 약품투여횟수와 현재 투여된 약품투여횟수(depth)가 같으면 더 이상 searching할 필요가 없음 + if(depth >= result) { + return; + } + + if (searching()) { + int count = 0; + for (int num : isVisited) { + if (num != 0) { + count++; + } + } + + result = Math.min(result, count); + } + + if (depth == K) { + return; + } + } + + for (int i = index; i < D; i++) { + if (isVisited[i] == 2) continue; + isVisited[i] = 1; // isVisited가 1이면 1로 채우고, 2이면 0으로 채움. + DFS(depth + 1, i + 1); + isVisited[i] = 2; + DFS(depth + 1, i + 1); + isVisited[i] = 0; + } + + } // End of DFS + + private static boolean searching() { + for (int i = 0; i < W; i++) { + boolean check = false; + int zeroCount = 0; + int oneCount = 0; + + for (int j = 0; j < D; j++) { + + if (isVisited[j] == 0) { + if (arr[j][i] == 0) { + zeroCount++; + oneCount = 0; + } else if (arr[j][i] == 1) { + oneCount++; + zeroCount = 0; + } + } else if (isVisited[j] == 1) { + oneCount++; + zeroCount = 0; + } else if (isVisited[j] == 2) { + zeroCount++; + oneCount = 0; + } + + + // 둘 중 하나라도 K를 찍으면 중지. + if (zeroCount == K || oneCount == K) { + check = true; + break; + } + } + + if (!check) { + return false; + } + } + + return true; + } // End of searching + + private static void init() { + arr = new int[D][W]; + isVisited = new int[D]; + result = K+1; + } // End of init +} // End of Main class From 9265a85c654d41d5cf56d7fffabbed4329b85a22 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Fri, 9 Sep 2022 13:47:17 +0900 Subject: [PATCH 274/822] complete --- ...\352\277\200\354\261\204\354\267\250.java" | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 "09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" new file mode 100644 index 0000000..d8e4659 --- /dev/null +++ "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" @@ -0,0 +1,143 @@ +import java.util.*; +import java.io.*; + +public class Main_2115_벌꿀채취 { + static int N, M, C, result; + + static int[][] arr; + static boolean[][] isVisited; + static int[] beekeeper1; + static int[] beekeeper2; + static int beekeeper1Max; + static Deque deque; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2115.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 벌통의 크기 + M = Integer.parseInt(st.nextToken()); // 벌통의 개수 + C = Integer.parseInt(st.nextToken()); // 채취할 수 있는 꿀의 최대양 + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + // 가로로 연속되도록 M개의 벌통을 선택 + // 2명의 일꾼 + // 2명의 일꾼이 채취할 수 있는 최대양은 C이다. + + // 선택된 M개의 벌통에서 값을 조합 + // 조합된 수가 C를 넘지 않도록하기. + // 부분 조합 만들기 <- 완전탐색 + + for (int i = 0; i < N; i++) { + for (int j = 0; j <= N - M; j++) { + + // 첫번째 양봉업자 조합 만들기. + int index = 0; + for (int k = j; k < j + M; k++) { + beekeeper1[index] = arr[i][k]; + isVisited[i][k] = true; + index++; + } + + + // beekeeper1의 조합으로 최댓값을 찾기. + DFS(0, 1, 0); + + // 두번째 양봉 업자 조합 만들기. + madeBekeeper2(i); + } + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void madeBekeeper2(int iIndex) { // 양봉업자1이 만든 벌통을 제외하고 양봉업자 2의 벌통을 만드는 메소드 + for (int i = iIndex; i < N; i++) { + for (int j = 0; j <= N - M; j++) { + + // 첫번째 양봉업자가 만든 조합은 지나침. + if (isVisited[i][j]) { + continue; + } + + // 두번째 양봉업자 조합 만들기. + int index = 0; + for (int k = j; k < j + M; k++) { + beekeeper2[index] = arr[i][k]; + index++; + } + + // 만들어진 벌꿀 통에 대해서 다시 조합을 계산해서 최댓값을 만들기. + DFS(0, 2, 0); + } + } + + } // End of madeBeekeeper2 + + private static void DFS(int depth, int beekeeperNum, int index) { + + if (depth <= M) { + int sum = 0; + int total = 0; + + for (int num : deque) { + sum += num; + total += Math.pow(num, 2); + } + + if (sum <= C) { + if (beekeeperNum == 1) { + beekeeper1Max = Math.max(beekeeper1Max, total); + } else { + result = Math.max(beekeeper1Max + total, result); + } + } + + if (depth == M) { + return; + } + } + + for (int i = index; i < M; i++) { + if (beekeeperNum == 1) { // 양봉업자 1일떄, 최댓값 + deque.offerLast(beekeeper1[i]); + DFS(depth + 1, beekeeperNum, i + 1); + deque.pollLast(); + } else { // 양봉업자 2 최댓값 + deque.offerLast(beekeeper2[i]); + DFS(depth + 1, beekeeperNum, i + 1); + deque.pollLast(); + } + + } + } // End of DFS + + private static void init() { + result = Integer.MIN_VALUE; + arr = new int[N][N]; + isVisited = new boolean[N][N]; + beekeeper1 = new int[M]; + beekeeper2 = new int[M]; + deque = new LinkedList<>(); + beekeeper1Max = Integer.MIN_VALUE; + } // End of init +} // End of Main class \ No newline at end of file From 3beecfc8d4333c49a33cc9fe82af7636fc4643e8 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 10 Sep 2022 03:01:58 +0900 Subject: [PATCH 275/822] complete --- ...353\254\274_\352\262\251\353\246\254.java" | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 "09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" new file mode 100644 index 0000000..d9e2a38 --- /dev/null +++ "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" @@ -0,0 +1,159 @@ +import java.util.*; +import java.io.*; + +public class Main_2382_미생물_격리 { + static int N, M, K, result; + static LinkedList list; + + static class Microorganism implements Comparable { + int count; // 미생물 숫자 + int direction; // 이동 방향 + int x; + int y; + + public Microorganism(int x, int y, int count, int direction) { + this.x = x; + this.y = y; + this.count = count; + this.direction = direction; + } + + @Override + public int compareTo(Microorganism o) { + if (this.x == o.x) { + if (this.y == o.y) { + return o.count - this.count; + } + + return this.y - o.y; + } + + return this.x - o.x; + } + } // End of microorganism class + + // 미생물 이동방향 1 : 상 , 2 : 하, 3 : 좌 , 4 : 우 + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2382.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 가로 세로 크기 + M = Integer.parseInt(st.nextToken()); // 미생물이 격리되는 시간. + K = Integer.parseInt(st.nextToken()); // 미생물 군집의 숫자 + init(); + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + int count = Integer.parseInt(st.nextToken()); + int direction = Integer.parseInt(st.nextToken()); + list.add(new Microorganism(x, y, count, direction)); + } + Collections.sort(list); + + while (M-- > 0) { + int size = list.size(); + for (int i = 0; i < size; i++) { + Microorganism micro = list.get(i); + int x = micro.x; + int y = micro.y; + int count = micro.count; + int direction = micro.direction; + + if (direction == 1) { // 상 + x--; + if (x == 0) { + count = count / 2; + direction = 2; + } + } else if (direction == 2) { // 하 + x++; + if (x == N - 1) { + count = count / 2; + direction = 1; + } + } else if (direction == 3) { // 좌 + y--; + if (y == 0) { + count = count / 2; + direction = 4; + } + } else if (direction == 4) { // 우 + y++; + if (y == N - 1) { + count = count / 2; + direction = 3; + } + } + + list.set(i, new Microorganism(x, y, count, direction)); + } + + // 리스트 정렬, x를 기준으로 정렬, x가 같으면, y값, y도 같으면 count를 기준으로 내림차순 정렬 + Collections.sort(list); + + // 한바퀴를 돌고 난 후 겹치는 값이 있는지 확인. + // x와 y를 기준으로 정렬 후 그래도 값이 같으면 count를 기준으로 정렬. + + List list2 = new LinkedList<>(); + int preX = -1; + int preY = -1; + for (int i = 0; i < list.size(); i++) { + Microorganism micro = list.get(i); + int x = micro.x; + int y = micro.y; + int count = micro.count; + int direction = micro.direction; + if (preX == x && preY == y) continue; + + for (int j = i + 1; j < list.size(); j++) { + Microorganism micro2 = list.get(j); + int x2 = micro2.x; + int y2 = micro2.y; + double count2 = micro2.count; + + if (x != x2) { + break; + } + + if (y == y2) { + count += count2; + } + } + + preX = x; + preY = y; + list2.add(new Microorganism(x, y, count, direction)); + } + + list.clear(); + list.addAll(list2); + } + + // 최종 결과 + for (Microorganism micro : list) { + result += micro.count; + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + + private static void init() { + result = 0; + list = new LinkedList<>(); + } // End of init +} // End of Main class \ No newline at end of file From 83cb4e7757563787824f74f126149b7eb7d602b4 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 10 Sep 2022 04:05:07 +0900 Subject: [PATCH 276/822] complete --- ...\352\277\200\354\261\204\354\267\250.java" | 44 +++++++------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" index d8e4659..9bf41b7 100644 --- "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" +++ "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" @@ -6,8 +6,7 @@ public class Main_2115_벌꿀채취 { static int[][] arr; static boolean[][] isVisited; - static int[] beekeeper1; - static int[] beekeeper2; + static int[] beekeeper; static int beekeeper1Max; static Deque deque; @@ -35,31 +34,25 @@ public static void main(String[] args) throws Exception { } } - // 가로로 연속되도록 M개의 벌통을 선택 - // 2명의 일꾼 - // 2명의 일꾼이 채취할 수 있는 최대양은 C이다. - // 선택된 M개의 벌통에서 값을 조합 // 조합된 수가 C를 넘지 않도록하기. // 부분 조합 만들기 <- 완전탐색 - for (int i = 0; i < N; i++) { for (int j = 0; j <= N - M; j++) { // 첫번째 양봉업자 조합 만들기. int index = 0; for (int k = j; k < j + M; k++) { - beekeeper1[index] = arr[i][k]; + beekeeper[index] = arr[i][k]; isVisited[i][k] = true; index++; } - // beekeeper1의 조합으로 최댓값을 찾기. DFS(0, 1, 0); // 두번째 양봉 업자 조합 만들기. - madeBekeeper2(i); + madeBekeeper(i); } } @@ -70,11 +63,10 @@ public static void main(String[] args) throws Exception { bw.close(); } // End of main - private static void madeBekeeper2(int iIndex) { // 양봉업자1이 만든 벌통을 제외하고 양봉업자 2의 벌통을 만드는 메소드 + private static void madeBekeeper(int iIndex) { // 양봉업자1이 만든 벌통을 제외하고 양봉업자 2의 벌통을 만드는 메소드 for (int i = iIndex; i < N; i++) { for (int j = 0; j <= N - M; j++) { - - // 첫번째 양봉업자가 만든 조합은 지나침. + // 첫번째 양봉업자가 만든 조합은 지나치도록 isVisited를 사용 if (isVisited[i][j]) { continue; } @@ -82,7 +74,7 @@ private static void madeBekeeper2(int iIndex) { // 양봉업자1이 만든 벌 // 두번째 양봉업자 조합 만들기. int index = 0; for (int k = j; k < j + M; k++) { - beekeeper2[index] = arr[i][k]; + beekeeper[index] = arr[i][k]; index++; } @@ -91,7 +83,7 @@ private static void madeBekeeper2(int iIndex) { // 양봉업자1이 만든 벌 } } - } // End of madeBeekeeper2 + } // End of madeBekeeper private static void DFS(int depth, int beekeeperNum, int index) { @@ -104,10 +96,11 @@ private static void DFS(int depth, int beekeeperNum, int index) { total += Math.pow(num, 2); } + // 합이 C를 넘으면 안됨. if (sum <= C) { - if (beekeeperNum == 1) { + if (beekeeperNum == 1) { // 양봉 업자1로 만든 조합에서 최고값을 찾기. beekeeper1Max = Math.max(beekeeper1Max, total); - } else { + } else { // 양봉업자 1이 만든 최고값과 양봉업자2가 만든조합의 합과 최고값 비교. result = Math.max(beekeeper1Max + total, result); } } @@ -117,17 +110,11 @@ private static void DFS(int depth, int beekeeperNum, int index) { } } + // 덱을 사용해서 조합을 만듬. for (int i = index; i < M; i++) { - if (beekeeperNum == 1) { // 양봉업자 1일떄, 최댓값 - deque.offerLast(beekeeper1[i]); - DFS(depth + 1, beekeeperNum, i + 1); - deque.pollLast(); - } else { // 양봉업자 2 최댓값 - deque.offerLast(beekeeper2[i]); - DFS(depth + 1, beekeeperNum, i + 1); - deque.pollLast(); - } - + deque.offerLast(beekeeper[i]); + DFS(depth + 1, beekeeperNum, i + 1); + deque.pollLast(); } } // End of DFS @@ -135,8 +122,7 @@ private static void init() { result = Integer.MIN_VALUE; arr = new int[N][N]; isVisited = new boolean[N][N]; - beekeeper1 = new int[M]; - beekeeper2 = new int[M]; + beekeeper = new int[M]; deque = new LinkedList<>(); beekeeper1Max = Integer.MIN_VALUE; } // End of init From 7010e1615e2054015b2bb6d7e42ad4cb80307e57 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 10 Sep 2022 12:52:21 +0900 Subject: [PATCH 277/822] complete --- ...\354\204\234\353\271\204\354\212\244.java" | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 "09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" new file mode 100644 index 0000000..bc144ba --- /dev/null +++ "b/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" @@ -0,0 +1,117 @@ +import java.util.*; +import java.io.*; + +public class Main_2117_홈_방범_서비스 { + static int N, M, maxBenefit, result; + static int[][] arr; + static int[] dirX = {0, 0, -1, 1}; + static int[] dirY = {-1, 1, 0, 0}; + + static class Coordinates { + int x; + int y; + int dist; + + public Coordinates(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } // End of Coordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2117.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); // 집 하나당 지불하는 비용. + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int k = 1; k <= N+1; k++) { // 방범 면적의 크기 증가. + int protectArea = preventionAreaCalc(k); // 방범 면적 계산 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + BFS(i, j, k, protectArea); + } + } + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + // 어차피 K값은 BFS탐색 전에 고정됨. K는 한번만 계산하면 그 값을 활용할 수 있음 + private static void BFS(int x, int y, int distLimit, int protectArea) { + boolean[][] isVisited = new boolean[N][N]; + isVisited[x][y] = true; + int homeCount = 0; + if (arr[x][y] == 1) { + homeCount++; + } + + Queue que = new LinkedList<>(); + que.offer(new Coordinates(x, y, 1)); + + while (!que.isEmpty()) { + Coordinates cor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = cor.x + dirX[i]; + int nowY = cor.y + dirY[i]; + int dist = cor.dist; + + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && dist < distLimit) { + isVisited[nowX][nowY] = true; + que.offer(new Coordinates(nowX, nowY, dist + 1)); + + if (arr[nowX][nowY] == 1) { + homeCount++; + } + } + } + } + + if (benefitCalc(protectArea, homeCount) >= 0 && maxBenefit <= benefitCalc(protectArea, homeCount)) { + result = Math.max(result, homeCount); + } + + } // End of BFS + + + private static int benefitCalc(int area, int homeCount) { // 이익을 계산하는 메소드 + // 방범 면적 - 집의 개수 * M + return (homeCount * M) - area; + } // End of calc + + private static int preventionAreaCalc(int K) { + return K * K + (K - 1) * (K - 1); + } // End of preventionAreaCalc + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + result = Integer.MIN_VALUE; + maxBenefit = Integer.MIN_VALUE; + arr = new int[N][N]; + } // End of init +} // End of Main class \ No newline at end of file From 545e16fdb6f46f7cf25e92bffd56baa6114099fa Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 10 Sep 2022 18:31:13 +0900 Subject: [PATCH 278/822] kihun --- ...64\355\230\270\355\225\204\353\246\204.py" | 64 ++++++++++++++++ ...14\352\277\200\354\261\204\354\267\250.py" | 76 +++++++++++++++++++ ...24\354\204\234\353\271\204\354\212\244.py" | 34 +++++++++ ...35\353\254\274\352\262\251\353\246\254.py" | 67 ++++++++++++++++ 4 files changed, 241 insertions(+) create mode 100644 "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" create mode 100644 "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" create mode 100644 "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" create mode 100644 "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" new file mode 100644 index 0000000..653780f --- /dev/null +++ "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" @@ -0,0 +1,64 @@ +import sys + +sys.stdin = open("09.12/protect_film.txt", "r", encoding="UTF-8") + +T = int(input()) + + +def checkAll(arr): + check = [0 for _ in range(w)] + for x in range(w): + queue = [] + for y in range(d): + if not queue: + queue.append(arr[y][x]) + else: + if queue[-1] == arr[y][x]: + queue.append(arr[y][x]) + else: + if len(queue) >= k: + check[x] = 1 + queue = [arr[y][x]] + if queue: + if len(queue) >= k: + check[x] = 1 + if check[x] < 1: + return -1 + return sum(check) + + +def dfs(depth, dfsArr, changed): + global result + if changed > result: + return + if depth == d: + if checkAll(dfsArr) == w: + if result > changed: + result = changed + return + + keepOrigin = dfsArr[depth][:] + # depth행에 + # 약품 안 넣기 + dfs(depth + 1, dfsArr, changed) + + # A 약품 넣기 (0), 원상복구 + for x in range(w): + dfsArr[depth][x] = 0 + dfs(depth + 1, dfsArr, changed + 1) + dfsArr[depth] = keepOrigin[:] + + # B 약품 넣기 (1), 원상복구 + for x in range(w): + dfsArr[depth][x] = 1 + dfs(depth + 1, dfsArr, changed + 1) + dfsArr[depth] = keepOrigin[:] + + +for test_case in range(1, T+1): + d, w, k = map(int, input().split()) + matrix = [list(map(int, input().split())) for _ in range(d)] + result = 999999999 + dfs(0, matrix, 0) + + print("#{} {}".format(test_case, result)) diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" new file mode 100644 index 0000000..857a277 --- /dev/null +++ "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" @@ -0,0 +1,76 @@ +import sys + +sys.stdin = open("벌꿀채취.txt", "r", encoding="UTF-8") + +T = int(input()) + +def check(arr): + arr.sort() + result = 0 + if sum(arr) > c: + while sum(arr) < c: + arr.pop(0) + for number in arr: + result += number * number + +def calculate(arr): + global resultA, resultB + a = arr[:len(arr)//2] + b = arr[len(arr)//2:] + a.sort() + b.sort() + resultA, resultB = 0, 0 + calDFS(0, a, [], 1) + calDFS(0, b, [], 2) + return resultA + resultB + +def calDFS(depth, arr, pickList, flag): + global resultA, resultB + if depth == len(arr): + if sum(pickList) <= c: + temp = 0 + for pick in pickList: + temp += pick * pick + if flag == 1: + if resultA < temp: + resultA = temp + else: + if resultB < temp: + resultB = temp + return + calDFS(depth + 1, arr, pickList, flag) + calDFS(depth + 1, arr, pickList + [arr[depth]], flag) + + + +def pick(depth, pickList): + global result + if depth == 2: + honey = calculate(pickList) + if result < honey: + result = honey + return + keepPick = pickList[:] + for y in range(n): + for x in range(n-m+1): + if [y, x] not in banList and not visited[y][x]: + for dx in range(m): + visited[y][x + dx] = True + pickList.append(matrix[y][x + dx]) + if depth == 0: + banList.append([y, x]) + pick(depth + 1, pickList) + for dx in range(m): + visited[y][x + dx] = False + pickList = keepPick[:] + +for test_case in range(1, T+1): + n, m, c = map(int, input().split()) + matrix = [list(map(int,input().split())) for _ in range(n)] + visited = [[False] * n for _ in range(n)] + banList = [] + resultA = -999999999 + resultB = -999999999 + result = -999999999 + pick(0, []) + print("#{} {}".format(test_case, result)) diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" new file mode 100644 index 0000000..689ee5e --- /dev/null +++ "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" @@ -0,0 +1,34 @@ +import sys + +sys.stdin = open("09.12/홈방범서비스.txt", "r", encoding="UTF-8") + +T = int(input()) + +costList = [0] + [(k * k) + (k - 1) * (k - 1) for k in range(1, 22)] + +for test_case in range(1, T+1): + n, m = map(int, input().split()) + maxValue = 0 + matrix = [] + homeList = [] + for y in range(n): + temp = list(map(int, input().split())) + matrix.append(temp) + for x in range(n): + if temp[x] == 1: + homeList.append((y, x)) + # k를 늘려가면서 확인, + # n이 홀수일 때 마름모 속 사각형이 n x n 을 커버 + # n이 짝수일 때는 n x n이 안 들어감...n은 20까지이므로 k=21까지 탐색이 안전 + for k in range(1, n+2): + for y in range(n): + for x in range(n): + count = 0 + for home in homeList: + # 거리로 마름모 속에 있는지 확인 + if abs(home[0] - y) + abs(home[1] - x) < k: + count += 1 + if count * m >= costList[k]: + maxValue = max(maxValue, count) + + print("#{} {}".format(test_case, maxValue)) diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" new file mode 100644 index 0000000..c3d5b5e --- /dev/null +++ "b/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" @@ -0,0 +1,67 @@ +import sys + +sys.stdin = open("09.12/미생물격리.txt", "r", encoding="UTF-8") + +T = int(input()) + +delta = [[0, 0], [-1, 0], [1, 0], [0, -1], [0, 1]] + +for test_case in range(1, T+1): + n, m, k = map(int, input().split()) + virus = [] + for _ in range(k): + y, x, number, dir = map(int, input().split()) + virus.append([y, x, number, dir]) + t = 0 + while t < m: + cleanData = [[[0, 0, 0] for _ in range(n)] for _ in range(n)] + for i in range(k): + # 합쳐진 값은 패스 + if virus[i][0] == -1: + continue + y, x, number, dir = virus[i] + # 다음 좌표로 이동 + nY = y + delta[dir][0] + nX = x + delta[dir][1] + # 가장자리일 때 처리 + if nY == 0 or nX == 0 or nY == n-1 or nX == n-1: + if dir == 1: + dir = 2 + elif dir == 2: + dir = 1 + elif dir == 3: + dir = 4 + elif dir == 4: + dir = 3 + number = number // 2 + # 가야할 곳에 뭔가 있다 + if cleanData[nY][nX] != [0, 0, 0]: + # cleanData에 있던게 더 크면 값을 virus 배열에 전해주고 내 것을 삭제 + if cleanData[nY][nX][0] > number: + index = cleanData[nY][nX][2] + virus[index][2] += number + nY, nX, number, dir = -1, -1, -1, -1 + # 내 것이 더 크면 같은 데이터 찾아서 삭제, 인덱스 덮어쓰기 + # cleanData에는 내 값을 비교용으로 남겨두고 + # number에서 미생물 수 합치기 + else: + deleteIndex = cleanData[nY][nX][2] + oldNumber = virus[deleteIndex][2] + virus[deleteIndex] = [-1, -1, -1, -1] + cleanData[nY][nX][0] = number + cleanData[nY][nX][1] = dir + cleanData[nY][nX][2] = i + number += oldNumber + else: + cleanData[nY][nX] = [number, dir, i] + # virus 배열 최신화 + virus[i] = [nY, nX, number, dir] + t += 1 + + # 결과값 출력 + result = 0 + for i in range(k): + if virus[i][2] > 0: + result += virus[i][2] + + print("#{} {}".format(test_case, result)) From 5f30b3048c709aff92e7e9faa9b4c221fe87daa3 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 12 Sep 2022 00:35:07 +0900 Subject: [PATCH 279/822] =?UTF-8?q?Create=20=EB=B2=8C=EA=BF=80=EC=B1=84?= =?UTF-8?q?=EC=B7=A8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\277\200\354\261\204\354\267\250.java" | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 "09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" new file mode 100644 index 0000000..0cff972 --- /dev/null +++ "b/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" @@ -0,0 +1,118 @@ +import java.util.*; +import java.io.*; +public class 벌꿀채취_2115 { + + static int N, M, C; + static int[][] arr; + static int[] aworker, bworker; + static boolean[][] vis; + static boolean[] avis; + static boolean[] bvis; + static int amax, bmax, ans; + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int t = Integer.parseInt(br.readLine()); + for(int tc=1; tc<=t; tc++) { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + + arr = new int[N][N]; + aworker = new int[M]; + bworker = new int[M]; + ans = Integer.MIN_VALUE; + + for(int i=0; i Date: Mon, 12 Sep 2022 15:57:14 +0900 Subject: [PATCH 280/822] . --- ...4\352\277\200 \354\261\204\354\267\250.py" | 40 +++++++++++++++++ ...5 \354\204\234\353\271\204\354\212\244.py" | 45 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 "09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" create mode 100644 "09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" diff --git "a/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" "b/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" new file mode 100644 index 0000000..11eea32 --- /dev/null +++ "b/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" @@ -0,0 +1,40 @@ +import sys; sys.stdin = open("input.txt") + +profit = 0 +def calc_max_profit(_row_index, _col_index, _col_last_index, _limit, _sum, _result) : + global profit + if _sum > _limit : return + if _col_index == _col_last_index : + profit = max(profit, _result) + return + value = arr[_row_index][_col_index] + calc_max_profit(_row_index, _col_index + 1, _col_last_index, _limit, _sum+value, _result+value**2) + calc_max_profit(_row_index, _col_index + 1, _col_last_index, _limit, _sum, _result) + +def solution_diffRow(_limit) -> int: + global profit + max_profit = 0 + for first_row_index in range(n-1): + for first_col_index in range(n): + if first_col_index + m >= n: break + calc_max_profit(first_row_index, first_col_index, first_col_index+m, _limit, 0, 0) + profit1 = profit; profit=0 + for second_row_index in range(first_col_index + 1, n): + for second_col_index in range(n): + if second_col_index + m >= n: break + calc_max_profit(second_row_index, second_col_index, second_col_index+m, _limit, 0, 0) + profit2 = profit; profit=0 + max_profit = max(max_profit, profit1+profit2) + return max_profit + +def solution(_limit) -> int: + profit_diff = solution_diffRow(_limit) + profit_same = 0 + return max(profit_diff, profit_same) + +T = int(input()) +for t in range(1,T+1): + n, m, c = map(int, input().split()) + arr = [list(map(int, input().split())) for _ in range(n)] + answer = solution(c) + print(f"#{t} {answer}") \ No newline at end of file diff --git "a/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" "b/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" new file mode 100644 index 0000000..0cbd35c --- /dev/null +++ "b/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" @@ -0,0 +1,45 @@ +import sys; sys.stdin = open("input.txt") +from collections import deque +move = [(1,0), (0,1), (-1,0), (0,-1)] + +def bfs(_depth, _center, _cost) -> int: + queue = deque(); visited = [[0]*n for _ in range(n)] + queue.append(_center); visited[_center[1]][_center[0]] = 1 + count = 0 + while queue: + present = queue.popleft() + if arr_home[present[1]][present[0]] : count +=1 + for dx, dy in move: + next_x, next_y = present[0]+dx, present[1]+dy + if 0<=next_x_depth:continue + queue.append((next_x, next_y)) + visited[next_y][next_x] = visited[present[1]][present[0]] + 1 + return count if m*count-_cost>=0 else -1 + +def solution(): + global answer + k = 1 + while True: + cost = k*k + (k-1)*(k-1) + if cost > count_home*m: break + for y in range(n): + for x in range(n): + center = (x, y) + count = bfs(k, center, cost) + if count>=0: answer = max(answer, count) + k+=1 + return + +T = int(input()) +for t in range(1,T+1): + n, m = map(int, input().split()) + arr_home = [] ; count_home = 0 + for row_index in range(n): + row = list(map(int, input().split())) + for col in row: + if col : count_home+=1 + arr_home.append(row) + answer = 0 + solution() + print(f"#{t} {answer}") \ No newline at end of file From 4206162e30fb32b1a882e13cbb5da3943f240f45 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 13 Sep 2022 22:05:39 +0900 Subject: [PATCH 281/822] =?UTF-8?q?Create=20=ED=99=88=EB=B0=A9=EB=B2=94?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\204\234\353\271\204\354\212\244.java" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" "b/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" new file mode 100644 index 0000000..d4fc919 --- /dev/null +++ "b/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" @@ -0,0 +1,80 @@ +import java.util.*; +import java.io.*; + +public class 홈방범서비스_2117 { + static int[][] map; + static int ans; + static int N, M; + + static int[] di = {0,0,1,-1}; + static int[] dj = {1,-1,0,0}; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int TC = sc.nextInt(); + for(int tc=1; tc<=TC; tc++) { + N = sc.nextInt(); + M = sc.nextInt(); + + map = new int[N][N]; + + for(int i=0; i q = new LinkedList<>(); + boolean[][] visit = new boolean[N][N]; + + q.add(new Point(r, c)); + visit[r][c] = true; + + int K = 1; + int house = 0; + while(!q.isEmpty()) { + int size = q.size(); + for(int s=0; s=0 && rr=0 && cc Date: Tue, 13 Sep 2022 22:06:02 +0900 Subject: [PATCH 282/822] =?UTF-8?q?Create=20=EB=AF=B8=EC=83=9D=EB=AC=BC?= =?UTF-8?q?=EA=B2=A9=EB=A6=AC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\254\274\352\262\251\353\246\254.java" | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 "09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" "b/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" new file mode 100644 index 0000000..ded96c4 --- /dev/null +++ "b/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" @@ -0,0 +1,103 @@ +import java.util.*; +import java.io.*; +public class 미생물격리_2_2382 { + static class Microbe { + int x, y; + int power; + int dir; + + public Microbe(int x, int y, int power, int dir) { + this.x = x; + this.y = y; + this.power = power; + this.dir = dir; + } + } + + static int N, M, K; + static int[][] map; + static List microbes = new LinkedList<>(); + // (상: 1, 하: 2, 좌: 3, 우: 4) + static int[][] dir = { { 0, 0 }, { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(br.readLine()); + + for (int test_case = 1; test_case <= T; test_case++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + microbes.clear(); + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + microbes.add(new Microbe(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()))); + } + + for (int day = 0; day < M; day++) { + int lIdx = 0; + List lists = new ArrayList<>(); + map = new int[N][N]; + for (int i = 0; i < N; i++) { + Arrays.fill(map[i], -1); + } + + //군집 순으로 list를 내림차순 정렬 + microbes.sort(new Comparator() { + public int compare(Microbe m1, Microbe m2) { + return m2.power - m1.power; + } + }); + + for (int mIdx = 0; mIdx < microbes.size(); mIdx++) { + Microbe m = microbes.get(mIdx); + int curDir = m.dir; + int nextX = m.x + dir[m.dir][0]; + int nextY = m.y + dir[m.dir][1]; + + m.x = nextX; + m.y = nextY; + + if (isEdge(nextX, nextY)) { // power절반, 방향 반대 + m.power/=2; + m.dir = getReversedDir(curDir); + } + + if (map[nextX][nextY] == -1) { + lists.add(m); + map[nextX][nextY] = lIdx++; + } else { + lists.get(map[nextX][nextY]).power += m.power; + } + } + + microbes.clear(); + microbes.addAll(lists); + } + + System.out.println("#" + test_case + " "+microbes.stream().mapToInt(m -> m.power).sum()); + } + } + + // (상: 1, 하: 2, 좌: 3, 우: 4) + private static int getReversedDir(int curDir) { + if (curDir%2 == 0) + return curDir - 1; + else + return curDir + 1; + } + + private static boolean isEdge(int nextX, int nextY) { + if (nextX == 0 || nextX == N - 1 || nextY == 0 || nextY == N - 1) + return true; + else + return false; + } + +} + From 23ba317e6b1301a1af8f3f26cc38aaee720f9044 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Wed, 14 Sep 2022 15:23:54 +0900 Subject: [PATCH 283/822] Create swea2117.java --- .../swea2117.java" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" diff --git "a/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" "b/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" new file mode 100644 index 0000000..68d86f4 --- /dev/null +++ "b/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" @@ -0,0 +1,94 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Scanner; + +public class swea2117 { + public static class position{ + int x,y; + position(int x, int y){ + this.x=x; + this.y=y; + } + } + static int N,M,ans; + static int[][] arr; + static boolean[][]visited; + static int[] dx= {-1,1,0,0}; + static int[] dy= {0,0,-1,1}; + static Queue q; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + int T=scan.nextInt(); + for(int o=1;o<=T;o++) { + ans=0; + N=scan.nextInt(); + M=scan.nextInt(); + arr=new int[N][N]; + q=new LinkedList<>(); + visited=new boolean[N][N]; + for(int i=0;ians) { + ans=k; + } + } + + while(!q.isEmpty()) { + int size=q.size(); + k++; + for(int i=0;i=0&&nx=0&&nyans) { + ans=house; + } + } + } + + } + +} From 355ad7316e05cace07ee7653160087315a34a9db Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Wed, 14 Sep 2022 15:54:34 +0900 Subject: [PATCH 284/822] =?UTF-8?q?Create=20=EB=B2=8C=EA=BF=80=EC=B1=84?= =?UTF-8?q?=EC=B7=A8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\277\200\354\261\204\354\267\250.java" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" diff --git "a/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" new file mode 100644 index 0000000..06662c1 --- /dev/null +++ "b/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" @@ -0,0 +1,92 @@ +import java.util.Scanner; + +public class Solution { + static int [][] arr; + static boolean []visited; + static int ans,N,M,C; + static int max1,max2; + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + int T=scan.nextInt(); + for(int o=1;o<=T;o++) { + N=scan.nextInt(); + M=scan.nextInt(); + C=scan.nextInt(); + + ans=0; + max1=Integer.MIN_VALUE; + max2=Integer.MIN_VALUE; + arr=new int[N][N]; + visited=new boolean[M]; + ans=0; + for(int i=0;i Date: Wed, 14 Sep 2022 15:55:11 +0900 Subject: [PATCH 285/822] =?UTF-8?q?Create=20=EB=B3=B4=ED=98=B8=ED=95=84?= =?UTF-8?q?=EB=A6=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\230\270\355\225\204\353\246\204.java" | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 "09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" diff --git "a/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" "b/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" new file mode 100644 index 0000000..93eaa76 --- /dev/null +++ "b/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" @@ -0,0 +1,113 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Scanner; + +public class Solution { + static int [][] arr; + static int D,W,K; + static boolean visited[]; + static int min; + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + int T=scan.nextInt(); + for(int o=1;o<=T;o++) { + D=scan.nextInt(); + W=scan.nextInt(); + K=scan.nextInt(); //합격기준 두께 + arr=new int[D][W]; + min=Integer.MAX_VALUE; + visited=new boolean[D]; + for(int i=0;i약품주입 a or b->search + medi(0,0,i,0); + if(minab[pre]) { + ab[pre]=tmp_cnt; //저장된 값보다 크면 저장해주기 + } + pre=arr[j][i]; + tmp_cnt=1; + } + + if(j==D-1) { //마지막이면 + if(tmp_cnt>ab[pre]) { + ab[pre]=tmp_cnt; //저장된 값보다 크면 저장해주기 + } + pre=arr[j][i]; + tmp_cnt=1; + } + } + if(ab[0] list=new ArrayList(); + //약품주입 a + for(int j=0;j list2=new ArrayList(); + for(int j=0;j Date: Wed, 14 Sep 2022 16:07:55 +0900 Subject: [PATCH 286/822] =?UTF-8?q?Create=20=EB=91=90=20=ED=81=90=20?= =?UTF-8?q?=ED=95=A9=20=EA=B0=99=EA=B2=8C=20=EB=A7=8C=EB=93=A4=EA=B8=B0.cp?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \353\247\214\353\223\244\352\270\260.cpp" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" new file mode 100644 index 0000000..4c91013 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" @@ -0,0 +1,44 @@ +#include +#include +#include + +using namespace std; + +int solution(vector queue1, vector queue2) { + int answer = 0; + long long sum1 = 0, sum2 = 0, half = 0; + int count = queue1.size() + queue2.size(); + queue q1, q2; + for (int i = 0; i < queue1.size(); i++) { //q에 넣기 + 총합 구하기 + sum1 += queue1[i]; + q1.push(queue1[i]); + } + for (int i = 0; i < queue2.size(); i++) { //q에 넣기 + 총합 구하기 + sum2 += queue2[i]; + q2.push(queue2[i]); + } + half = sum1 + sum2; + if (half % 2) return -1; //홀수이면 -1 + half /= 2; + while (answer < count * 10) { //임의의 수 + if (sum1 == half) return answer; //탈출조건 + while (sum1 > half && !q1.empty()) { //한쪽이 크면 pop + int n = q1.front(); q1.pop(); + if (n > half) return -1; + q2.push(n); + sum1 -= n; + sum2 += n; + answer++; + } + while (sum2 > half && !q2.empty()) { + int n = q2.front(); q2.pop(); + if (n > half) return -1; + q1.push(n); + sum2 -= n; + sum1 += n; + answer++; + } + } + if (sum1 != half) return -1; //모두 돌아도 충족하지 않으면 -1 + return answer; +} From eefa189e1e4c883aa0690df89f6d44dabaac85bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 14 Sep 2022 16:08:13 +0900 Subject: [PATCH 287/822] =?UTF-8?q?Create=20=EC=98=88=EC=83=81=20=EB=8C=80?= =?UTF-8?q?=EC=A7=84=ED=91=9C.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...01 \353\214\200\354\247\204\355\221\234.cpp" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" new file mode 100644 index 0000000..9ebf00a --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int solution(int n, int a, int b) +{ + int answer = 0; + int A = a, B = b; + while (A != B) { + answer++; + A = (A % 2) ? A + 1 : A; //짝수화 + B = (B % 2) ? B + 1 : B; //짝수화 + A /= 2; + B /= 2; + } + return answer; +} From 5f924bd3054f594539ca55e516493b18096214d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 14 Sep 2022 16:09:32 +0900 Subject: [PATCH 288/822] Create readme.md --- .../readme.md" | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" new file mode 100644 index 0000000..8f81e4c --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" @@ -0,0 +1,7 @@ +# 09.15(목) 프로그래머스 스터디 + +문제 1) 예상 대진표 +https://school.programmers.co.kr/learn/courses/30/lessons/12985 + +문제 2) 두 큐 합 같게 만들기 +https://school.programmers.co.kr/learn/courses/30/lessons/118667 From ee86ca1fba11d5e589bb7a7725b8dbe26b7ba3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 14 Sep 2022 16:10:33 +0900 Subject: [PATCH 289/822] Update readme.md --- .../readme.md" | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" index 8f81e4c..6a351a5 100644 --- "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" @@ -1,4 +1,5 @@ -# 09.15(목) 프로그래머스 스터디 +# 09.15(목) 프로그래머스 스터디 ( Level - 2) + 문제 1) 예상 대진표 https://school.programmers.co.kr/learn/courses/30/lessons/12985 From 045d9fc53882c6e13718cb7c5a2c48e83f954302 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Wed, 14 Sep 2022 16:45:38 +0900 Subject: [PATCH 290/822] complete --- ...\354\202\254\354\213\234\352\260\204.java" | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 "09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" diff --git "a/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" new file mode 100644 index 0000000..735da3c --- /dev/null +++ "b/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" @@ -0,0 +1,188 @@ +import java.io.*; +import java.util.*; + +public class Main_2383_점심_식사시간 { + static int N, result; + static int[][] arr; + static int[] ans; + static List personList; + static Stair[] stairArr; + static int finalTime; // 가장 늦게 도착한 사람의 시간. + + static class Person { + int num; + int x; + int y; + int minMin; + + public Person(int num, int x, int y, int minMin) { + this.num = num; + this.x = x; + this.y = y; + this.minMin = minMin; + } + } // End of Person class + + static class Stair { + int x; + int y; + int time; + List waitingList; + + public Stair(int x, int y, int time, List waitingList) { + this.x = x; + this.y = y; + this.time = time; + this.waitingList = waitingList; + } + } // End of Stair class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2383.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); + + int stairIndex = 0; + int manCount = 0; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + if (arr[i][j] == 1) { + personList.add(new Person(manCount, i, j, Integer.MAX_VALUE)); + manCount++; + } else if (arr[i][j] > 1) { + stairArr[stairIndex] = new Stair(i, j, arr[i][j], new LinkedList<>()); + stairIndex++; + } + } + } + + ans = new int[manCount]; + DFS(0, manCount); + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int depth, int depthLimit) { + + if (depth == depthLimit) { + int finalTime1 = Integer.MIN_VALUE; + int finalTime2 = Integer.MIN_VALUE; + + for (Stair s : stairArr) { + s.waitingList = new ArrayList<>(); + } + + for (int i = 0; i < depthLimit; i++) { + int stairIndex = ans[i] - 1; + int manNum = i; // 사람 번호 + int distTime = minCalc(personList.get(manNum).x, stairArr[stairIndex].x, personList.get(manNum).y, stairArr[stairIndex].y); + + stairArr[stairIndex].waitingList.add(distTime); + // index에 해당하는 계단으로 이동, + } + + + // 가장 마지막에 빠져나온 사람을 기준으로 result 값을 최솟값으로 갱신 + for (int i = 0; i < 2; i++) { + Stair s = stairArr[i]; + int stairTime = s.time; + + // 대기열이 비었으면 진행 X + if (s.waitingList.isEmpty()) continue; + + Collections.sort(s.waitingList); + + // 대기열이 3이하까지는 상관없음 + if (s.waitingList.size() <= 3) { + finalTime1 = Math.max(finalTime1, (s.waitingList.get(s.waitingList.size() - 1) + stairTime)); + } else { + Deque deque = new LinkedList<>(); + int time = 0; + + for (int j = 0; j < 3; j++) { + deque.offerLast(s.waitingList.remove(0) + s.time); + } + + for (; ; ) { + + while (!deque.isEmpty() && deque.peekFirst() == time) { + deque.pollFirst(); + } + + + if (deque.size() < 3) { + int dif = 3 - deque.size(); + int removeCount = 0; + + for (int j = 0; j < dif; j++) { + if (s.waitingList.isEmpty()) { + break; + } + + if (time < s.waitingList.get(0)) { + break; + } else if (time + s.time == s.waitingList.get(0)) { + deque.offerLast(s.waitingList.get(0) + s.time); + removeCount++; + } else if (time + s.time > s.waitingList.get(0)) { + deque.offerLast(time + s.time); + removeCount++; + } + + s.waitingList.remove(0); + } + } + + if (deque.size() <= 3 && s.waitingList.isEmpty()) { + time = deque.pollLast(); + break; + } + + if (time == 100) break; + time++; + } + + finalTime2 = Math.max(finalTime2, time); + } // End of else of if + } // End of for(i); + + // 모든 값이 계산되고 나면 종료 + finalTime = Math.max(finalTime1, finalTime2); + result = Math.min(finalTime, result); + return; + } + + for (int i = 1; i <= 2; i++) { + ans[depth] = i; + DFS(depth + 1, depthLimit); + } + } // End of DFS + + private static int minCalc(int pr, int sr, int pc, int sc) { + int time = Math.abs(pr - sr) + Math.abs(pc - sc); + return time + 1; // 계단을 내려가는 시간이 기준이므로 + 1을 해줌. + } // End of minCalc + + private static void init() { + result = Integer.MAX_VALUE; + arr = new int[N][N]; + stairArr = new Stair[2]; + personList = new ArrayList<>(); + finalTime = Integer.MIN_VALUE; + } // End of init +} // End of Main class \ No newline at end of file From 3f4460280d63ffa0af7fda1fab935bd3bb9eb0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 14 Sep 2022 17:35:59 +0900 Subject: [PATCH 291/822] =?UTF-8?q?readme=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\241\260\354\210\230\354\227\260/README.md" | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" new file mode 100644 index 0000000..9c686d7 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" @@ -0,0 +1,7 @@ + +Study
+ +## 프로그래머스 Level 1,2
+- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 +- 성격 유형 검사하기(2022 KAKAO TECH INTERNSHIP) : https://school.programmers.co.kr/learn/courses/30/lessons/118666 +- 위장 : https://school.programmers.co.kr/learn/courses/30/lessons/42578 From 6e447b603847380c4b8a5ea09c0cc3810fc289c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 14 Sep 2022 17:38:16 +0900 Subject: [PATCH 292/822] Update README.md --- .../\354\241\260\354\210\230\354\227\260/README.md" | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" index 9c686d7..c82f2b9 100644 --- "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" @@ -1,7 +1,11 @@ Study
-## 프로그래머스 Level 1,2
-- 다리를 지나는 트럭 : https://school.programmers.co.kr/learn/courses/30/lessons/42583 -- 성격 유형 검사하기(2022 KAKAO TECH INTERNSHIP) : https://school.programmers.co.kr/learn/courses/30/lessons/118666 -- 위장 : https://school.programmers.co.kr/learn/courses/30/lessons/42578 +## 프로그래머스 Level 2
+- 이진 변환 반복하기 : https://school.programmers.co.kr/learn/courses/30/lessons/70129 +- JadenCase 문자열 만들기 : https://school.programmers.co.kr/learn/courses/30/lessons/118666 +- 멀리 뛰기 : https://school.programmers.co.kr/learn/courses/30/lessons/12914 +- 예상 대진표 : https://school.programmers.co.kr/learn/courses/30/lessons/12985 +- 행렬의 곱셈 : https://school.programmers.co.kr/learn/courses/30/lessons/12949 +- 두 큐 합 같게 만들기(2022 KAKAO TECH INTERNSHIP +) : https://school.programmers.co.kr/learn/courses/30/lessons/118667 From 21bb0fce51e5a18e8cb79bada326f161fe94a205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= <48742378+su6378@users.noreply.github.com> Date: Wed, 14 Sep 2022 17:38:55 +0900 Subject: [PATCH 293/822] solve --- ...4 \353\247\214\353\223\244\352\270\260.kt" | 18 +++++ ...4 \353\247\214\353\223\244\352\270\260.kt" | 70 +++++++++++++++++++ ...0\353\246\254 \353\233\260\352\270\260.kt" | 30 ++++++++ ...1 \353\214\200\354\247\204\355\221\234.kt" | 33 +++++++++ ...30\353\263\265\355\225\230\352\270\260.kt" | 49 +++++++++++++ ...4\354\235\230 \352\263\261\354\205\210.kt" | 28 ++++++++ 6 files changed, 228 insertions(+) create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" create mode 100644 "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" new file mode 100644 index 0000000..325d475 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" @@ -0,0 +1,18 @@ +package com.ssafy.algorithm + +fun main() { + val sl = Solution() + val S = "for the last week" + println(sl.solution(S)) + +} + +class Solution { + fun solution(s: String): String { + //문자열을 소문자로 바꾼 후 공백을 기준으로 나눠서 해당 문자들을 capitalize()함수를 통해 첫번째 문자만 바꾼 후 joinString()함수로 문자열 변환 + return s.lowercase().split(" ").map { it.capitalize() }.joinToString(" ") + } +} + + + diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" new file mode 100644 index 0000000..e4e70d8 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" @@ -0,0 +1,70 @@ +package com.ssafy.algorithm + +import java.util.* + +fun main() { + val sl = Solution() + val queue1 = intArrayOf(1,1,1,1,1,1,1,1,1,10) + val queue2 = intArrayOf(1,1,1,1,1,1,1,1,1,1) + println(sl.solution(queue1, queue2)) +} + +class Solution { + var sum1: Long = 0 + var sum2: Long = 0 + + fun solution(queue1: IntArray, queue2: IntArray): Int { + var answer: Int = -2 + var sum: Long = 0 + + //큐의 합 구하기 + for (i in queue1) sum1 += i + for (i in queue2) sum2 += i + sum = (sum1 + sum2) / 2 + + if (queue1.maxOrNull()!! > sum || queue2.maxOrNull()!! > sum) answer = -1 //인덱스가 각큐의 합보다 클 경우 -1 리턴 + else answer = shift(queue1, queue2, sum) + return answer + } + + fun shift(queue1: IntArray, queue2: IntArray, sum: Long): Int { + + var count = 0 + val shift1: Queue = LinkedList() + val shift2: Queue = LinkedList() + + for (value in queue1) { //큐에 값 채우기 + shift1.offer(value.toLong()) + } + + for (value in queue2) { + shift2.offer(value.toLong()) + } + var time = 0 + while (time <= 300000) { //shift가 똑같이 반복하면 탈출 loop + + if (sum1 == sum2) break //합이 같으면 종료 + + if (sum1 < sum) { //shift1 큐의 합이 전체 큐의 합 / 2보다 작으면 shift1에 value 추가 + val qPoll = shift2.poll() + shift1.offer(qPoll) + sum1 += qPoll //shift1 sum1 값 증가 + sum2 -= qPoll //shift2 sum2 값 감소 + count++ + } else { + val qPoll = shift1.poll() + shift2.offer(qPoll) + sum2 += qPoll + sum1 -= qPoll + count++ + } + time++ + } + if (time > 300000){ + count = -1 + } + return count + } +} + + diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" new file mode 100644 index 0000000..858e45e --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" @@ -0,0 +1,30 @@ +package com.ssafy.algorithm + + + +fun main() { + val sl = Solution() + val n = 3 + println(sl.solution(n)) + +} + +class Solution { + var arr = LongArray(2001) //2000까지 초기화 + fun solution(n: Int): Long { + dp(arr) + return arr[n] + } + + fun dp(arr : LongArray){ //dp로 인덱스 값 넣어주기 + arr[1] = 1 + arr[2] = 2 + + for (i in 3 until arr.size){ + arr[i] = (arr[i-1] + arr[i-2]) % 1234567 //인덱스가 커지면 값이 커지므로 미리 1234567로 나머지 연산을 실행 + } + } +} + + + diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" new file mode 100644 index 0000000..8978661 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" @@ -0,0 +1,33 @@ +package com.ssafy.algorithm + +fun main() { + val sl = Solution() + val n = 8 + val a = 4 + val b = 5 + println(sl.solution(n,a,b)) + +} + +class Solution { + fun solution(n: Int, a: Int, b: Int): Int { + var answer = 1 + var A = a + var B = b + while (true){ + if (Math.abs(A - B) == 1) { //둘의 위치가 1 차이가 날 때 + if (A > B) { //A가 더 클 경우 A의 위치가 2로 나눴을 때 나머지가 0 이면 종료 + if (A % 2 == 0) break + }else{ //B가 더 클 경우 A의 위치가 2로 나눴을 때 나머지가 0 이면 종료 + if (B % 2 == 0) break + } + } + answer++ + A = A / 2 + A % 2 //A의 다음 위치 + B = B / 2 + B % 2 //B의 다음 위치 + } + return answer + } +} + + diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" new file mode 100644 index 0000000..1a8e9c5 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" @@ -0,0 +1,49 @@ +package com.ssafy.algorithm + +import java.util.* +import kotlin.collections.ArrayList +import kotlin.collections.HashSet + +fun main() { + val sl = Solution() + val S = "1111111" + println(Arrays.toString(sl.solution(S))) + +} + +class Solution { + fun solution(s: String): IntArray { + var str = s + var changeCount = 0 //변환 횟수 + var removeCount = 0 //제거 횟수 + + while (true) { + if (str == "1") break + + for (binary in str) { + if (binary == '0') removeCount++ + } + + str = str.replace("0", "") + + changeCount++ + + str = changeBinary(str) + + } + + var answer = IntArray(2) + answer[0] = changeCount + answer[1] = removeCount + + return answer + } + + fun changeBinary(str: String): String { //문자열의 길이를 이진수로 변환 + val strLength = str.length + return Integer.toBinaryString(strLength) + } +} + + + diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" new file mode 100644 index 0000000..2170575 --- /dev/null +++ "b/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" @@ -0,0 +1,28 @@ +package com.ssafy.algorithm + +fun main() { + val sl = Solution() + val arr1 = arrayOf(intArrayOf(1,4), intArrayOf(3,2), intArrayOf(4,1)) + val arr2 = arrayOf(intArrayOf(3,3), intArrayOf(3,3)) + println(sl.solution(arr1,arr2)) + +} + +class Solution { + fun solution(arr1: Array, arr2: Array): Array { + var answer = arrayOf() + answer = Array(arr1.size){IntArray(arr2[0].size)} + + for (i in answer.indices){ + for (j in answer[i].indices){ + for (k in arr2.indices) { // 3*2 2*2 일 때 행렬곱이 될려면 가운데 두 개의 수가 같아야 하므로 그 수만큼 반복 + answer[i][j] += arr1[i][k] * arr2[k][j] + } + } + } + + return answer + } +} + + From 484a59a7a2ae4bdb2545aaf7afd1340535bb1731 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 14 Sep 2022 23:08:37 +0900 Subject: [PATCH 294/822] kihun --- ...35\354\202\254\354\213\234\352\260\204.py" | 86 +++++++++++++++++++ ...11\354\240\225\353\271\204\354\206\214.py" | 70 +++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 "09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" create mode 100644 "09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" diff --git "a/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" "b/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" new file mode 100644 index 0000000..0e6ec2f --- /dev/null +++ "b/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" @@ -0,0 +1,86 @@ +import sys +sys.stdin = open("09.15/점심식사시간.txt", "r", encoding="UTF-8") + +T = int(input()) + + +def selection(depth, pick, m): + global stairSelect + if depth == m: + stairSelect.append(pick) + return + + selection(depth + 1, pick + [0], m) + selection(depth + 1, pick + [1], m) + +# stair: 계단에 들어갈 사람들. time: 내려가는데 걸리는 시간 + + +def downStairs(stair, time): + t = 1 + down = [] + while stair or down: + delete = [] + # 내려가는 사람들을 처리해야 계단에 사람을 올릴 수 있다 + if down: + for i in range(len(down)): + down[i][1] += 1 + if down[i][1] == time: + delete.append(i) + + for _ in range(len(delete)): + down.pop(0) + + delete = [] + if stair: + for i in range(len(stair)): + if stair[i][0] <= t: + if len(down) < 3: + down.append(stair[i]) + delete.append(i) + for _ in range(len(delete)): + stair.pop(0) + t += 1 + return t + + +for test_case in range(1, T+1): + n = int(input()) + manList = [] + stairList = [] + stairSelect = [] + stair0, stair1 = [], [] + times = [] + minTime = 999999999 + for y in range(n): + temp = list(map(int, input().split())) + for x in range(n): + if temp[x] == 1: + manList.append([y, x]) + elif temp[x] > 1: + stairList.append([y, x]) + times.append(temp[x]) + + selection(0, [], len(manList)) + + for select in stairSelect: + for i in range(len(manList)): + if select[i] == 0: + temp = abs(manList[i][0] - stairList[0][0]) + \ + abs(manList[i][1] - stairList[0][1]) + stair0.append([temp, 0]) + else: + temp = abs(manList[i][0] - stairList[1][0]) + \ + abs(manList[i][1] - stairList[1][1]) + stair1.append([temp, 0]) + # 거리가 짧은 것이 먼저 오도록 정렬 + stair0.sort() + stair1.sort() + + # 두 계단 중 큰 값이 이번 조합의 시간 + time = max(downStairs(stair0, times[0]), downStairs(stair1, times[1])) + + # 최소 시간을 갱신 + minTime = min(time, minTime) + + print("#{} {}".format(test_case, minTime)) diff --git "a/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" "b/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" new file mode 100644 index 0000000..08abbe3 --- /dev/null +++ "b/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" @@ -0,0 +1,70 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +T = int(input()) + +for test_case in range(1, T+1): + n, m, k, a, b = map(int, input().split()) + aList = list(map(int, input().split())) + bList = list(map(int, input().split())) + tList = [0] + list(map(int, input().split())) + + nList = [[0,0] for _ in range(n)] + mList = [[0,0] for _ in range(m)] + + waiting = [] + complete = [] + result = 0 + # 사용했던 desk를 저장하는 배열 + usedDesk = [[0,0] for _ in range(k+1)] + tIdx = 1 + time = 0 + while True: + for i in range(n): + # 빈자리가 아니면 1초 추가 + if nList[i][0] != 0: + nList[i][1] += 1 + # 시간을 다 채웠다면 waiting으로 + if nList[i][1] == aList[i]: + waiting.append(nList[i][0]) + nList[i] = [0, 0] + # tIdx 하나씩 밀어주면서 빈자리가 있으면 추가 + if tIdx <= k: + if nList[i] == [0, 0]: + if tList[tIdx] <= time: + nList[i] = [tIdx, 0] + usedDesk[tIdx][0] = i + tIdx += 1 + if waiting: + for i in range(m): + # 빈자리라면 waiting에서 하나 추가 + if mList[i] == [0, 0]: + idx = waiting.pop(0) + usedDesk[idx][1] = i + mList[i] = [idx, 0] + if not waiting: + break + + for i in range(m): + # 빈자리가 아니면 1초 추가 + if mList[i][0] != 0: + mList[i][1] += 1 + # 시간을 다 채웠다면 complete로 + if mList[i][1] == bList[i]: + complete.append(mList[i][0]) + mList[i] = [0, 0] + # 모두 다 complete에 들어왔는지 체크하고 while 탈출 + if len(complete) == k: + break + time += 1 + + # 조건에 맞다면 result에 더해주기 + for i in range(1, len(usedDesk)): + if usedDesk[i] == [a-1, b-1]: + result += i + + if result == 0: + print("#{} -1".format(test_case)) + else: + print("#{} {}".format(test_case, result)) \ No newline at end of file From 7070d96b8566c394e6eb4c7f7116391f9517c9ed Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Thu, 15 Sep 2022 00:23:25 +0900 Subject: [PATCH 295/822] complete --- ...\354\202\254\354\213\234\352\260\204.java" | 374 +++++++++--------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git "a/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" index 735da3c..b8953ed 100644 --- "a/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" +++ "b/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" @@ -1,188 +1,188 @@ -import java.io.*; -import java.util.*; - -public class Main_2383_점심_식사시간 { - static int N, result; - static int[][] arr; - static int[] ans; - static List personList; - static Stair[] stairArr; - static int finalTime; // 가장 늦게 도착한 사람의 시간. - - static class Person { - int num; - int x; - int y; - int minMin; - - public Person(int num, int x, int y, int minMin) { - this.num = num; - this.x = x; - this.y = y; - this.minMin = minMin; - } - } // End of Person class - - static class Stair { - int x; - int y; - int time; - List waitingList; - - public Stair(int x, int y, int time, List waitingList) { - this.x = x; - this.y = y; - this.time = time; - this.waitingList = waitingList; - } - } // End of Stair class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2383.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - N = Integer.parseInt(br.readLine()); - init(); - - int stairIndex = 0; - int manCount = 0; - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - if (arr[i][j] == 1) { - personList.add(new Person(manCount, i, j, Integer.MAX_VALUE)); - manCount++; - } else if (arr[i][j] > 1) { - stairArr[stairIndex] = new Stair(i, j, arr[i][j], new LinkedList<>()); - stairIndex++; - } - } - } - - ans = new int[manCount]; - DFS(0, manCount); - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void DFS(int depth, int depthLimit) { - - if (depth == depthLimit) { - int finalTime1 = Integer.MIN_VALUE; - int finalTime2 = Integer.MIN_VALUE; - - for (Stair s : stairArr) { - s.waitingList = new ArrayList<>(); - } - - for (int i = 0; i < depthLimit; i++) { - int stairIndex = ans[i] - 1; - int manNum = i; // 사람 번호 - int distTime = minCalc(personList.get(manNum).x, stairArr[stairIndex].x, personList.get(manNum).y, stairArr[stairIndex].y); - - stairArr[stairIndex].waitingList.add(distTime); - // index에 해당하는 계단으로 이동, - } - - - // 가장 마지막에 빠져나온 사람을 기준으로 result 값을 최솟값으로 갱신 - for (int i = 0; i < 2; i++) { - Stair s = stairArr[i]; - int stairTime = s.time; - - // 대기열이 비었으면 진행 X - if (s.waitingList.isEmpty()) continue; - - Collections.sort(s.waitingList); - - // 대기열이 3이하까지는 상관없음 - if (s.waitingList.size() <= 3) { - finalTime1 = Math.max(finalTime1, (s.waitingList.get(s.waitingList.size() - 1) + stairTime)); - } else { - Deque deque = new LinkedList<>(); - int time = 0; - - for (int j = 0; j < 3; j++) { - deque.offerLast(s.waitingList.remove(0) + s.time); - } - - for (; ; ) { - - while (!deque.isEmpty() && deque.peekFirst() == time) { - deque.pollFirst(); - } - - - if (deque.size() < 3) { - int dif = 3 - deque.size(); - int removeCount = 0; - - for (int j = 0; j < dif; j++) { - if (s.waitingList.isEmpty()) { - break; - } - - if (time < s.waitingList.get(0)) { - break; - } else if (time + s.time == s.waitingList.get(0)) { - deque.offerLast(s.waitingList.get(0) + s.time); - removeCount++; - } else if (time + s.time > s.waitingList.get(0)) { - deque.offerLast(time + s.time); - removeCount++; - } - - s.waitingList.remove(0); - } - } - - if (deque.size() <= 3 && s.waitingList.isEmpty()) { - time = deque.pollLast(); - break; - } - - if (time == 100) break; - time++; - } - - finalTime2 = Math.max(finalTime2, time); - } // End of else of if - } // End of for(i); - - // 모든 값이 계산되고 나면 종료 - finalTime = Math.max(finalTime1, finalTime2); - result = Math.min(finalTime, result); - return; - } - - for (int i = 1; i <= 2; i++) { - ans[depth] = i; - DFS(depth + 1, depthLimit); - } - } // End of DFS - - private static int minCalc(int pr, int sr, int pc, int sc) { - int time = Math.abs(pr - sr) + Math.abs(pc - sc); - return time + 1; // 계단을 내려가는 시간이 기준이므로 + 1을 해줌. - } // End of minCalc - - private static void init() { - result = Integer.MAX_VALUE; - arr = new int[N][N]; - stairArr = new Stair[2]; - personList = new ArrayList<>(); - finalTime = Integer.MIN_VALUE; - } // End of init +import java.io.*; +import java.util.*; + +public class Main_2383_점심_식사시간 { + static int N, result; + static int[][] arr; + static int[] ans; + static List personList; + static Stair[] stairArr; + static int finalTime; // 가장 늦게 도착한 사람의 시간. + + static class Person { + int num; + int x; + int y; + int minMin; + + public Person(int num, int x, int y, int minMin) { + this.num = num; + this.x = x; + this.y = y; + this.minMin = minMin; + } + } // End of Person class + + static class Stair { + int x; + int y; + int time; + List waitingList; + + public Stair(int x, int y, int time, List waitingList) { + this.x = x; + this.y = y; + this.time = time; + this.waitingList = waitingList; + } + } // End of Stair class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2383.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); + + int stairIndex = 0; + int manCount = 0; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + if (arr[i][j] == 1) { + personList.add(new Person(manCount, i, j, Integer.MAX_VALUE)); + manCount++; + } else if (arr[i][j] > 1) { + stairArr[stairIndex] = new Stair(i, j, arr[i][j], new LinkedList<>()); + stairIndex++; + } + } + } + + ans = new int[manCount]; + DFS(0, manCount); + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int depth, int depthLimit) { + + if (depth == depthLimit) { + int finalTime1 = Integer.MIN_VALUE; + int finalTime2 = Integer.MIN_VALUE; + + for (Stair s : stairArr) { + s.waitingList = new ArrayList<>(); + } + + for (int i = 0; i < depthLimit; i++) { + int stairIndex = ans[i] - 1; + int manNum = i; // 사람 번호 + int distTime = minCalc(personList.get(manNum).x, stairArr[stairIndex].x, personList.get(manNum).y, stairArr[stairIndex].y); + + stairArr[stairIndex].waitingList.add(distTime); + // index에 해당하는 계단으로 이동, + } + + + // 가장 마지막에 빠져나온 사람을 기준으로 result 값을 최솟값으로 갱신 + for (int i = 0; i < 2; i++) { + Stair s = stairArr[i]; + int stairTime = s.time; + + // 대기열이 비었으면 진행 X + if (s.waitingList.isEmpty()) continue; + + // 대기시간 오름차순으로 정렬 + Collections.sort(s.waitingList); + + // 대기열이 3이하까지는 상관없음 + if (s.waitingList.size() <= 3) { + finalTime1 = Math.max(finalTime1, (s.waitingList.get(s.waitingList.size() - 1) + stairTime)); + } else { + Deque deque = new LinkedList<>(); + int time = 0; + + // 먼저 3개를 일단 덱에 탈출시간으로 지정해서 집어넣음. + for (int j = 0; j < 3; j++) { + deque.offerLast(s.waitingList.remove(0) + s.time); + } + + // 조건에 만족해서 탈출할 때 까지 무한반복 + for (; ; ) { + while (!deque.isEmpty() && deque.peekFirst() == time) { + deque.pollFirst(); + } + + if (deque.size() < 3) { + int dif = 3 - deque.size(); + int removeCount = 0; + + for (int j = 0; j < dif; j++) { + if (s.waitingList.isEmpty()) { + break; + } + + if (time < s.waitingList.get(0)) { + break; + } else if (time + s.time == s.waitingList.get(0)) { + deque.offerLast(s.waitingList.get(0) + s.time); + removeCount++; + } else if (time + s.time > s.waitingList.get(0)) { + deque.offerLast(time + s.time); + removeCount++; + } + + s.waitingList.remove(0); + } + } + + if (deque.size() <= 3 && s.waitingList.isEmpty()) { + time = deque.pollLast(); + break; + } + + time++; + } + + finalTime2 = Math.max(finalTime2, time); + } // End of else of if + } // End of for(i); + + // 모든 값이 계산되고 나면 종료 + finalTime = Math.max(finalTime1, finalTime2); + result = Math.min(finalTime, result); + return; + } + + for (int i = 1; i <= 2; i++) { + ans[depth] = i; + DFS(depth + 1, depthLimit); + } + } // End of DFS + + private static int minCalc(int pr, int sr, int pc, int sc) { + int time = Math.abs(pr - sr) + Math.abs(pc - sc); + return time + 1; // 계단을 내려가는 시간이 기준이므로 + 1을 해줌. + } // End of minCalc + + private static void init() { + result = Integer.MAX_VALUE; + arr = new int[N][N]; + stairArr = new Stair[2]; + personList = new ArrayList<>(); + finalTime = Integer.MIN_VALUE; + } // End of init } // End of Main class \ No newline at end of file From e7942a1a61ee36d33c1c7eae7117251c3c38a51c Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 15 Sep 2022 04:40:22 +0900 Subject: [PATCH 296/822] =?UTF-8?q?Create=20=EC=A0=90=EC=8B=AC=EC=8B=9D?= =?UTF-8?q?=EC=82=AC=EC=8B=9C=EA=B0=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\254\354\213\234\352\260\204.java" | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 "09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" diff --git "a/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" new file mode 100644 index 0000000..f8b044d --- /dev/null +++ "b/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" @@ -0,0 +1,196 @@ +import java.util.*; +import java.io.*; + +public class 점심식사시간_2383 { + static int[][] map; + static ArrayList person; + static ArrayList groupa, groupb; + static ArrayList k; + static boolean[] vis; + static int ans, n, index, resulta, resultb; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int t = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= t; tc++) { + + n = Integer.parseInt(br.readLine()); + map = new int[n][n]; + person = new ArrayList<>(); + k = new ArrayList<>(); + ans = Integer.MAX_VALUE; + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < n; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + if (map[i][j] > 1) + k.add(new Point(i, j, map[i][j])); + } + } + + // 사람마다 좌표와 계단 두 개까지의 거리를 입력 + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (map[i][j] == 1) { + int timea = Math.abs(i - k.get(0).r) + Math.abs(j - k.get(0).c); + int timeb = Math.abs(i - k.get(1).r) + Math.abs(j - k.get(1).c); + person.add(new Person(i, j, timea, timeb)); + } + } + } + + // 한 그룹에 사람 0명~전부 한 계단을 이용할 그룹 편성 + vis = new boolean[person.size()]; + makeorder(0); + + System.out.printf("#%d %d\n", tc, ans); + } + } + + static void makeorder(int idx) { + if (idx == person.size()) { + + // a, b계단 이용할 그룹 편성 + groupa = new ArrayList<>(); + groupb = new ArrayList<>(); + for (int i = 0; i < person.size(); i++) { + if (vis[i]) { + int time = person.get(i).timea; + groupa.add(new Group(time, 0, 0)); + } else { + int time = person.get(i).timeb; + groupb.add(new Group(time, 0, 0)); + } + } + + resulta = 0; + resultb = 0; + // a계단 시작 + if (groupa.size() != 0) { + groupa.sort(new Comparator() { // 그룹을 시간에 대해 오름차순으로 정렬 + @Override + public int compare(Group g1, Group g2) { + // TODO Auto-generated method stub + return g1.time - g2.time; + } + }); + move(0, groupa.get(0).time, groupa, 0, 0, 0); + } + + // b계단 시작 + if (groupb.size() != 0) { + groupb.sort(new Comparator() { // 그룹을 시간에 대해 오름차순으로 정렬 + @Override + public int compare(Group g1, Group g2) { + // TODO Auto-generated method stub + return g1.time - g2.time; + } + }); + + move(1, groupb.get(0).time, groupb, 0, 0, 0); + } + + int result = Math.max(resulta, resultb); + ans = Math.min(ans, result); + return; + } + vis[idx] = true; + makeorder(idx + 1); + vis[idx] = false; + makeorder(idx + 1); + } + + static void move(int knum, int time, ArrayList group, int complete, int wtemp, int stemp) { + if (complete == group.size()) { + if (knum == 0) + resulta = time - 1; + else if (knum == 1) + resultb = time - 1; + return; + } + int wait = wtemp; + int stair = stemp; + int cpl = complete; + + for (int i = 0; i < group.size(); i++) { + + // 이동 완료 + if (group.get(i).entertime == 0 && time == group.get(i).time + 1 + k.get(knum).time) { + group.get(i).status = 3; + cpl++; + stair--; + } else if (group.get(i).entertime != 0 && time == group.get(i).entertime + k.get(knum).time) { + + group.get(i).status = 3; + cpl++; + stair--; + } + + // 계단 입장 + if (time == group.get(i).time + 1 || group.get(i).status == 5) { + if (stair < 3) { + if (group.get(i).status == 5) { + group.get(i).entertime = time; + } + group.get(i).status = 2; + stair++; + wait--; + } + } + // 계단 입구 도착 + if (time == group.get(i).time || group.get(i).status == 4) { + if (wait < 3) { + group.get(i).status = 1; + wait++; + } + } + + // 시간 지났는데 밀려서 못간 사람 + if (time >= group.get(i).time) { + if (group.get(i).status == 0 && wait == 3) { + group.get(i).status = 4; + } else if (group.get(i).status == 1 && stair == 3) { + group.get(i).status = 5; + } + } + + } + + move(knum, time + 1, group, cpl, wait, stair); + } + + public static class Point { + int r, c, time; + + public Point(int r, int c, int time) { + this.r = r; + this.c = c; + this.time = time; + } + } + + public static class Group { + int time, status, entertime; // 밀리면 entertime에 밀린 시간 넣어줌 + + public Group(int time, int status, int entertime) { + this.time = time; + this.status = status; // 0:입구 도착 전, 1:입구도착, 2:계단, 3:이동완료, 4:입구도착 밀림, 5:계단 입장 밀림, + this.entertime = entertime; + } + } + + public static class Person { + int r, c, timea, timeb; + + public Person(int r, int c, int timea, int timeb) { + this.r = r; + this.c = c; + this.timea = timea; + this.timeb = timeb; + } + } +} From 5279ae16eecf6b8292732d3fccd59746cb443598 Mon Sep 17 00:00:00 2001 From: LeeJiYoon Date: Thu, 15 Sep 2022 17:09:56 +0900 Subject: [PATCH 297/822] =?UTF-8?q?Create=20=EC=A0=90=EC=8B=AC=EC=8B=9C?= =?UTF-8?q?=EA=B0=84.python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit . --- ...35\354\202\254\354\213\234\352\260\204.py" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" diff --git "a/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" "b/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" new file mode 100644 index 0000000..622cefb --- /dev/null +++ "b/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" @@ -0,0 +1,108 @@ +# import sys; sys.stdin = open("input.txt") +from collections import deque + +PERSON_TYPE, STAIR_TYPE = 1, 2 +PERSON_NUM, PERSONS = 0, [] +STAIR_NUM, STAIRS = 2, [] + +def downStairs(_stair1, _stair2): + global answer + wait1, wait2 = deque(_stair1), deque(_stair2) + stair1, stair2 = deque(), deque() + time, count_people = 0, 0 + while count_people!=PERSON_NUM: + time += 1 + # (1) 계단 로직 처리 + while stair1: + if stair1[0] == time: + stair1.popleft() + count_people += 1 + continue + break + while stair2: + if stair2[0] == time: + stair2.popleft() + count_people += 1 + continue + break + # (2) waiting 로직 처리 + while wait1: + if wait1[0]==time: + if len(stair1) < 3: + time_people = wait1.popleft() + stair1.append(time_people + stair_times_result[1]) + continue + else : + for wait_index in range(len(wait1)): + if wait1[wait_index]==time: wait1[wait_index] += 1 + else : break + break + while wait2: + if wait2[0]==time: + if len(stair2) < 3: + time_people = wait2.popleft() + stair2.append(time_people + stair_times_result[2]) + continue + else : + for wait_index in range(len(wait2)): + if wait2[wait_index]==time: wait2[wait_index] += 1 + else : break + break + answer = min(answer, time) + return + +def combination_dfs(_depth, _choices): # DFS + if _depth==PERSON_NUM: # 종료 조건 : 깊이==사람수, 즉 사람 마다 계단 선택을 결정 완료 했을 때. (항상 계단은 0 or 1, 2개 중 하나) + stair1_move_time, stair2_move_time = [], [] + for choice_index in range(PERSON_NUM): + if _choices[choice_index]==1: stair1_move_time.append(distances_result[choice_index][1]) + else : stair2_move_time.append(distances_result[choice_index][2]) + stair1_move_time.sort(); stair2_move_time.sort() + downStairs(stair1_move_time, stair2_move_time) + return + combination_dfs(_depth+1, _choices) + _choices[_depth] = 2 + combination_dfs(_depth+1, _choices) + _choices[_depth] = 1 + + +def calculate_values() -> (list, list): # Memoization - 계단까지 가는 소요 시간, 계단에서 내려가는 소요 시간 + stair_arr, distant_arr = [0], [] + for person_index in range(PERSON_NUM): # (1) 계단까지 가는 소요시간 + dist1 = move_to_stair_time(PERSONS[person_index][0], PERSONS[person_index][1], STAIRS[0][0], STAIRS[0][1]) + dist2 = move_to_stair_time(PERSONS[person_index][0], PERSONS[person_index][1], STAIRS[1][0], STAIRS[1][1]) + distant_arr.append([0, dist1, dist2]) + for stair_index in range(STAIR_NUM): # (2) 계단에서 내려가는 소요시간 + time = move_stair_time(arr[STAIRS[stair_index][1]][STAIRS[stair_index][0]]) + stair_arr.append(time) + return stair_arr, distant_arr + +def move_stair_time(_stair_size) -> int: + return _stair_size + +def move_to_stair_time(_px, _py, _sx, _sy) -> int: + return abs(_px-_sx) + abs(_py-_sy) + 1 # [※주의] 1분 후 계단을 내려갈 수 있음. + +def init(): + global PERSON_NUM + PERSON_NUM = 0 + PERSONS.clear() + STAIRS.clear() + +T = int(input()) +for t in range(1, T+1): + n = int(input()) + arr = []; init() + for row_index in range(n): + row = list(map(int, input().split())) + for col_index in range(n): + if row[col_index]==PERSON_TYPE : + PERSONS.append((col_index, row_index)) + PERSON_NUM += 1 + if row[col_index]>=STAIR_TYPE : + STAIRS.append((col_index, row_index)) + arr.append(row) + stair_times_result, distances_result = calculate_values() + answer = float("inf") + combination_dfs(0, [1]*PERSON_NUM) + print(f"#{t} {answer}") \ No newline at end of file From 40f33a6b1b513b7e51feace86707599aecd06ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 15 Sep 2022 20:51:20 +0900 Subject: [PATCH 298/822] Create reademe.md --- .../reademe.md" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/reademe.md" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/reademe.md" "b/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/reademe.md" new file mode 100644 index 0000000..9adac4d --- /dev/null +++ "b/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/reademe.md" @@ -0,0 +1,13 @@ +# 09.19 프로그래머스 + +1) 괄호 회전하기 +https://school.programmers.co.kr/learn/courses/30/lessons/76502 + +2) k진수에서 소수 개수 구하기 +https://school.programmers.co.kr/learn/courses/30/lessons/92335 + +3) 하노이의 탑 +https://school.programmers.co.kr/learn/courses/30/lessons/12946 + +4) N-Queen +https://school.programmers.co.kr/learn/courses/30/lessons/12952 From 1ac5409d548b43fd1ec86904b6d400c71f0a72c9 Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:13:41 +0900 Subject: [PATCH 299/822] 09.12 readme.md --- 09.12/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 09.12/Readme.md diff --git a/09.12/Readme.md b/09.12/Readme.md new file mode 100644 index 0000000..5f2257c --- /dev/null +++ b/09.12/Readme.md @@ -0,0 +1,5 @@ +# 09/12(월) +- 보호 필름 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V1SYKAaUDFAWu +- 벌꿀채취 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V4A46AdIDFAWu +- 홈 방범 서비스 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V61LqAf8DFAWu +- 미생물 격리 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV597vbqAH0DFAVl From 5e1337194c53d7ba6a0927e95e5380494b0de4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:15:07 +0900 Subject: [PATCH 300/822] Create N-Queen.cpp --- .../N-Queen.cpp" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" "b/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" new file mode 100644 index 0000000..3e60f3e --- /dev/null +++ "b/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" @@ -0,0 +1,35 @@ +#include +#include +#include + +using namespace std; + +int N; +int answer = 0; +void queen(int index, vector> queens) { + if (index == N) { + answer++; + return; + } + for (int i = 0; i < N; i++) { + bool flag = true; + for (int k = 0; k < queens.size(); k++) { + if (queens[k].first == index || queens[k].second == i || + abs(queens[k].first - index) == abs(queens[k].second - i)) { + flag = false; + break; + } + } + if (flag) { + vector> tmp(queens.begin(), queens.end()); + tmp.push_back({ index,i }); + queen(index + 1, tmp); + } + } +} + +int solution(int n) { + N = n; + queen(0, {}); + return answer; +} From 7b8bce5eb2eb2c5d356d83ab357c973116b380ce Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:15:09 +0900 Subject: [PATCH 301/822] 09.15 readme.md --- 09.15/Readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 09.15/Readme.md diff --git a/09.15/Readme.md b/09.15/Readme.md new file mode 100644 index 0000000..847e9a9 --- /dev/null +++ b/09.15/Readme.md @@ -0,0 +1,3 @@ +# 09/15(목) +- 점심 식사시간 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5-BEE6AK0DFAVl +- 차량 정비소 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV6c6bgaIuoDFAXy From 6af2a0951467a51a95cd6aa12c24f436263ac38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:17:39 +0900 Subject: [PATCH 302/822] =?UTF-8?q?Create=20=EC=A0=90=EC=8B=AC=EC=8B=9D?= =?UTF-8?q?=EC=82=AC=EC=8B=9C=EA=B0=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\254\354\213\234\352\260\204.java" | 292 ++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 "09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" diff --git "a/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" new file mode 100644 index 0000000..700efe4 --- /dev/null +++ "b/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" @@ -0,0 +1,292 @@ +import java.io.*; +import java.util.*; + +public class 점심식사시간 { + static long Astairs[], Bstairs[], arr[][]; + static ArrayList Person, Person2; + static LinkedList Await, Bwait; + static LinkedList

direction; + static int[][] map; + static int n, k, l, ans; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + n = Integer.parseInt(br.readLine()); + k = Integer.parseInt(br.readLine()); + map = new int[n][n]; + snake = new ArrayList<>(); + copy = new ArrayList<>(); + direction = new ArrayList<>(); + snake.add(new Point(0, 0)); + + // 사과 입력 + for (int i = 0; i < k; i++) { + st = new StringTokenizer(br.readLine()); + int r = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + map[r - 1][c - 1] = 1; + } + + // 방향 전환 list 생성 + l = Integer.parseInt(br.readLine()); + for (int i = 0; i < l; i++) { + st = new StringTokenizer(br.readLine()); + int time = Integer.parseInt(st.nextToken()); + char dir = st.nextToken().charAt(0); + direction.add(new Dir(time, dir)); + } + + int time = 0; + int dir = 1; + // 제한시간 1초이므로 DFS 사용x + while (true) { + time++; + Point nextHead = new Point(snake.get(0).r + dy[dir], snake.get(0).c + dx[dir]); + boolean check = checkDone(nextHead.r, nextHead.c); + if (check == false) { + // 다음 칸에 사과가 있으면 nextHead를 0번 인덱스에 넣고, 원본 배열을 그 뒤에 이어줌(길이 +1) + copy.clear(); + copy.addAll(snake); + snake.clear(); + snake.add(nextHead); + snake.addAll(copy); + if (map[nextHead.r][nextHead.c] == 1) { + map[nextHead.r][nextHead.c] = 0; + } else if (map[nextHead.r][nextHead.c] != 1) { // 사과 없으면 맨 뒤 remove(이동 후 길이 그대로) + snake.remove(snake.size() - 1); + } + + // 방향 전환할 때인지 체크하고 맞으면 방향 전환 + if (direction.size() > 0 && direction.get(0).time == time) { // 시간 순서대로 주어지므로 0번 인덱스 참조하고 remove + if (direction.get(0).dir == 'D') { + dir++; + if (dir >= 4) + dir = 0; + } else if (direction.get(0).dir == 'L') { + dir--; + if (dir < 0) + dir = 3; + } + direction.remove(0); + } + } else if (check == true) { + break; + } + } + + System.out.println(time); + } + + // 게임 끝났는지 검사 + static boolean checkDone(int r, int c) { + if (r < 0 || r >= n || c < 0 || c >= n || checkTouchMyBody(r, c)) { + return true; + } else + return false; + } + + // 자기 몸 부딛혔는지 검사 + static boolean checkTouchMyBody(int r, int c) { + for (int i = 0; i < snake.size(); i++) { + if (snake.get(i).r == r && snake.get(i).c == c) { + return true; + } + } + //contains()로 객체 포함 여부를 비교하기 위해서는 객체에 equals()를 정의해야함 +// Point temp = new Point(r, c); +// if (snake.contains(temp)) +// return true; +// else + return false; + } + + public static class Point { + int r, c; + + public Point(int r, int c) { + this.r = r; + this.c = c; + } + } + + public static class Dir { + int time; + char dir; + + public Dir(int time, char dir) { + this.time = time; + this.dir = dir; + } + } +} From fb58cdb6df258d7fc7001a52928e397b56d5d930 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 27 Oct 2022 00:25:25 +0900 Subject: [PATCH 397/822] =?UTF-8?q?Create=20=EC=9D=B8=ED=98=95=EB=BD=91?= =?UTF-8?q?=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\230\225\353\275\221\352\270\260.java" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" diff --git "a/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" "b/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" new file mode 100644 index 0000000..9fc9c35 --- /dev/null +++ "b/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" @@ -0,0 +1,33 @@ +import java.util.*; +import java.io.*; + +public class 크레인인형뽑기게임 { + + public static void main(String[] args) { + int[][] board = { { 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 3 }, { 0, 2, 5, 0, 1 }, { 4, 2, 4, 4, 2 }, + { 3, 5, 1, 3, 1 } }; + int[] moves = { 1, 5, 3, 5, 1, 2, 1, 4 }; + int answer = 0; + + Stack stack = new Stack<>(); + stack.add(0); + for(int j=0; j Date: Thu, 27 Oct 2022 12:22:35 +0900 Subject: [PATCH 398/822] =?UTF-8?q?Create=203190=5F=EB=B1=80.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3190_\353\261\200.cpp" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" diff --git "a/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" "b/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" new file mode 100644 index 0000000..daa19f6 --- /dev/null +++ "b/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; + +vector> togo; +int board[101][101] = { 0 }; +int N, K, L; + +int dx[] = { 0,1,0,-1 }; +int dy[] = { 1,0,-1,0 }; +deque> dq; + +int getLastTime() { + dq.push_back({ 1,1 }); + board[1][1] = 1; + int type = 0, time = 0; + for (auto go : togo) { + for (; time < go.first; time++) { + pair head = dq.front(); + int nextX = head.first + dx[type]; + int nextY = head.second + dy[type]; + if (nextX < 1 || nextX > N || nextY < 1 || nextY > N //범위를 벗어남 + || board[nextX][nextY] == 1) { //몸과 부딪힘 + return time; + } + if (board[nextX][nextY] == 0) { //사과와 만나지 않음 + pair tail = dq.back(); + board[tail.first][tail.second] = 0; + dq.pop_back(); + } + dq.push_front({ nextX,nextY }); //머리 움직임 + board[nextX][nextY] = 1; + } + if (go.second == 'L') { + type = (type - 1) < 0 ? 3 : type - 1; + } + else if(go.second == 'D'){ + type = (type + 1) > 3 ? 0 : type + 1; + } + } +} + +int main() { + cin >> N >> K; + for (int i = 0; i < K; i++) { + int x, y; cin >> x >> y; + board[x][y] = 2; //사과 + } + cin >> L; + for (int i = 0; i < L; i++) { + int t; cin >> t; + char C; cin >> C; + togo.push_back({ t,C }); + } + togo.push_back({ 1000000,'O' }); + cout << getLastTime()+1 << "\n"; + return 0; +} From 7911f2334cf6b84513146382c2dea32cb7de3d72 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:21:06 +0900 Subject: [PATCH 399/822] =?UTF-8?q?Create=20=EB=B1=80=5Fdfs.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\261\200_dfs.java" | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 "10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" diff --git "a/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" "b/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" new file mode 100644 index 0000000..3338135 --- /dev/null +++ "b/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" @@ -0,0 +1,127 @@ +import java.util.*; +import java.io.*; + +public class 뱀 { + + static int[] dx = { 0, 1, 0, -1 }; + static int[] dy = { -1, 0, 1, 0 }; + static ArrayList snake, copy; + static ArrayList direction; + static int[][] map; + static int n, k, l, time, dir; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + n = Integer.parseInt(br.readLine()); + k = Integer.parseInt(br.readLine()); + map = new int[n][n]; + snake = new ArrayList<>(); + copy = new ArrayList<>(); + direction = new ArrayList<>(); + snake.add(new Point(0, 0)); + + // 사과 입력 + for (int i = 0; i < k; i++) { + st = new StringTokenizer(br.readLine()); + int r = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + map[r - 1][c - 1] = 1; + } + + // 방향 전환 list 생성 + l = Integer.parseInt(br.readLine()); + for (int i = 0; i < l; i++) { + st = new StringTokenizer(br.readLine()); + int time = Integer.parseInt(st.nextToken()); + char dir = st.nextToken().charAt(0); + direction.add(new Dir(time, dir)); + } + + time = 0; + dir = 1; + + dfs(); + + System.out.println(time); + } + + static void dfs() { + time++; + Point nextHead = new Point(snake.get(0).r + dy[dir], snake.get(0).c + dx[dir]); + boolean check = checkDone(nextHead.r, nextHead.c); + if (check) + return; + + // 다음 칸에 사과가 있으면 nextHead를 0번 인덱스에 넣고, 원본 배열을 그 뒤에 이어줌(길이 +1) + copy.clear(); + copy.addAll(snake); + snake.clear(); + snake.add(nextHead); + snake.addAll(copy); + if (map[nextHead.r][nextHead.c] == 1) { + map[nextHead.r][nextHead.c] = 0; + } else if (map[nextHead.r][nextHead.c] != 1) { // 사과 없으면 맨 뒤 remove(이동 후 길이 그대로) + snake.remove(snake.size() - 1); + } + + // 방향 전환할 때인지 체크하고 맞으면 방향 전환 + if (direction.size() > 0 && direction.get(0).time == time) { // 시간 순서대로 주어지므로 0번 인덱스 참조하고 remove + if (direction.get(0).dir == 'D') { + dir++; + if (dir >= 4) + dir = 0; + } else if (direction.get(0).dir == 'L') { + dir--; + if (dir < 0) + dir = 3; + } + direction.remove(0); + } + + dfs(); + } + + // 게임 끝났는지 검사 + static boolean checkDone(int r, int c) { + if (r < 0 || r >= n || c < 0 || c >= n || checkTouchMyBody(r, c)) { + return true; + } else + return false; + } + + // 자기 몸 부딛혔는지 검사 + static boolean checkTouchMyBody(int r, int c) { + for (int i = 0; i < snake.size(); i++) { + if (snake.get(i).r == r && snake.get(i).c == c) { + return true; + } + } + // contains()로 객체 포함 여부를 비교하기 위해서는 객체에 equals()를 정의해야함 +// Point temp = new Point(r, c); +// if (snake.contains(temp)) +// return true; +// else + return false; + } + + public static class Point { + int r, c; + + public Point(int r, int c) { + this.r = r; + this.c = c; + } + } + + public static class Dir { + int time; + char dir; + + public Dir(int time, char dir) { + this.time = time; + this.dir = dir; + } + } +} From 115ed0bbbeeca28ff1bfe6a84f21d43ae669ede7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:27:40 +0900 Subject: [PATCH 400/822] =?UTF-8?q?Create=20=EC=9D=B8=ED=98=95=EB=BD=91?= =?UTF-8?q?=EA=B8=B0=20=EA=B2=8C=EC=9E=84.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\270\260 \352\262\214\354\236\204.cpp" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" diff --git "a/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" "b/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" new file mode 100644 index 0000000..44d3790 --- /dev/null +++ "b/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" @@ -0,0 +1,28 @@ +#include +#include +#include + +using namespace std; + +int solution(vector> board, vector moves) { + int answer = 0; + stack st; + st.push(0); + for (int m : moves) { //이동 + for (int i = 0; i < board.size(); i++) { + if (board[i][m-1] != 0) { //가장 위에 있는 것 찾기 + if (st.top() == board[i][m-1]) { //stack top과 같으면 + st.pop(); + answer += 2; + } + else { //다르면 input + st.push(board[i][m-1]); + } + board[i][m-1] = 0; + break; + } + } + } + + return answer; +} From 497c6c64356d1ee9401f239f536e58d6ec286c74 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 27 Oct 2022 22:26:57 +0900 Subject: [PATCH 401/822] solve --- 11.01/readme.md | 7 +++++ ...0\353\246\254 \353\233\260\352\270\260.kt" | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 11.01/readme.md create mode 100644 "11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" diff --git a/11.01/readme.md b/11.01/readme.md new file mode 100644 index 0000000..4999030 --- /dev/null +++ b/11.01/readme.md @@ -0,0 +1,7 @@ +# 10/26(수) + +## 백준 +- 뱀 : https://www.acmicpc.net/problem/3190 + +## 프로그래머스 +- 크레인 인형뽑기 : https://school.programmers.co.kr/learn/courses/30/lessons/64061 diff --git "a/11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" "b/11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" new file mode 100644 index 0000000..858e45e --- /dev/null +++ "b/11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" @@ -0,0 +1,30 @@ +package com.ssafy.algorithm + + + +fun main() { + val sl = Solution() + val n = 3 + println(sl.solution(n)) + +} + +class Solution { + var arr = LongArray(2001) //2000까지 초기화 + fun solution(n: Int): Long { + dp(arr) + return arr[n] + } + + fun dp(arr : LongArray){ //dp로 인덱스 값 넣어주기 + arr[1] = 1 + arr[2] = 2 + + for (i in 3 until arr.size){ + arr[i] = (arr[i-1] + arr[i-2]) % 1234567 //인덱스가 커지면 값이 커지므로 미리 1234567로 나머지 연산을 실행 + } + } +} + + + From d7a964555e6446947472d7516ce98723580c3dc1 Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Thu, 27 Oct 2022 22:28:00 +0900 Subject: [PATCH 402/822] Update readme.md --- 11.01/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/11.01/readme.md b/11.01/readme.md index 4999030..d2d0c08 100644 --- a/11.01/readme.md +++ b/11.01/readme.md @@ -4,4 +4,4 @@ - 뱀 : https://www.acmicpc.net/problem/3190 ## 프로그래머스 -- 크레인 인형뽑기 : https://school.programmers.co.kr/learn/courses/30/lessons/64061 +- 멀리 뛰기 : https://school.programmers.co.kr/learn/courses/30/lessons/12914 From 08637f5a77b3b2af21d5713254ee39091cfb52f2 Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Thu, 27 Oct 2022 22:28:51 +0900 Subject: [PATCH 403/822] Update readme.md --- 11.01/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/11.01/readme.md b/11.01/readme.md index d2d0c08..64bff7e 100644 --- a/11.01/readme.md +++ b/11.01/readme.md @@ -1,7 +1,7 @@ # 10/26(수) ## 백준 -- 뱀 : https://www.acmicpc.net/problem/3190 +- 보물 : https://www.acmicpc.net/problem/3190 ## 프로그래머스 - 멀리 뛰기 : https://school.programmers.co.kr/learn/courses/30/lessons/12914 From 139ad85e3192106e316f0fcaa41c45320a4c7b5c Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Thu, 27 Oct 2022 22:29:28 +0900 Subject: [PATCH 404/822] Update readme.md --- 11.01/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/11.01/readme.md b/11.01/readme.md index 64bff7e..70b941d 100644 --- a/11.01/readme.md +++ b/11.01/readme.md @@ -1,7 +1,7 @@ # 10/26(수) ## 백준 -- 보물 : https://www.acmicpc.net/problem/3190 +- 보물 : https://www.acmicpc.net/problem/1026 ## 프로그래머스 - 멀리 뛰기 : https://school.programmers.co.kr/learn/courses/30/lessons/12914 From 0cb17f71b57de4bd133f6777f443fe4b7571791f Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Fri, 28 Oct 2022 09:12:42 +0900 Subject: [PATCH 405/822] solve --- .../\353\263\264\353\254\274.kt" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" diff --git "a/11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" "b/11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" new file mode 100644 index 0000000..510ad7f --- /dev/null +++ "b/11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" @@ -0,0 +1,41 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.* +import kotlin.collections.ArrayList + + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + + val N = br.readLine().toInt() + + val A = ArrayList() + val B = ArrayList() + + repeat(2) { time -> + val token = StringTokenizer(br.readLine()) + + repeat(N) { + when (time) { + 0 -> A.add(token.nextToken().toInt()) + 1 -> B.add(token.nextToken().toInt()) + } + } + } + + var sum = 0 + + //A의 가장 큰수 * B의 가장 작은 수 곱하기 및 체크배열로 체크해주기 + while (A.isNotEmpty()){ + sum += A.maxOrNull()!! * B.minOrNull()!! + A.remove(A.maxOrNull()) + B.remove(B.minOrNull()) + } + + println(sum) +} + + + + From c293dc840acc72cd29fab2985bb74c0f84dd163d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 28 Oct 2022 13:35:11 +0900 Subject: [PATCH 406/822] =?UTF-8?q?Create=201026=5F=EB=B3=B4=EB=AC=BC.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1026_\353\263\264\353\254\274.cpp" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" diff --git "a/11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" "b/11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" new file mode 100644 index 0000000..2dea371 --- /dev/null +++ "b/11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" @@ -0,0 +1,24 @@ +#include +#include +#include +using namespace std; +int main() { + int N; cin >> N; + vector A,B; + for (int i = 0; i < N; i++) { + int n; cin >> n; + A.push_back(n); + } + for (int i = 0; i < N; i++) { + int n; cin >> n; + B.push_back(n); + } + sort(A.begin(), A.end()); + sort(B.begin(), B.end(), greater()); + int answer = 0; + for (int i = 0; i < N; i++) { + answer += A[i] * B[i]; + } + cout << answer << endl; + return 0; +} From 4daa1c1162a084e4cf045b2de691894bce9dfa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 28 Oct 2022 13:39:02 +0900 Subject: [PATCH 407/822] =?UTF-8?q?Create=20=EB=A9=80=EB=A6=AC=EB=9B=B0?= =?UTF-8?q?=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\200\353\246\254\353\233\260\352\270\260.cpp" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" diff --git "a/11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" "b/11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" new file mode 100644 index 0000000..98f5f87 --- /dev/null +++ "b/11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" @@ -0,0 +1,15 @@ +#include +#include + +using namespace std; + +int dp[2001] = { 0 }; + +long long solution(int n) { + dp[1] = 1; dp[2] = 2; + for (int i = 3; i <= n; i++) { + dp[i] = dp[i - 1] + dp[i - 2]; + dp[i] %= 1234567; + } + return dp[n]; +} From a40f50f8b25c03c252778a8524e4a4d0b4432310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 30 Oct 2022 18:54:22 +0900 Subject: [PATCH 408/822] =?UTF-8?q?Create=20=EB=A9=80=EB=A6=AC=EB=9B=B0?= =?UTF-8?q?=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...51\200\353\246\254\353\233\260\352\270\260.java" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" diff --git "a/11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" "b/11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" new file mode 100644 index 0000000..e59249e --- /dev/null +++ "b/11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" @@ -0,0 +1,13 @@ +class Solution { + static int dp[]; + public long solution(int n) { + dp = new int [2001]; // 왜 n + 1하면 터질까요? + dp[1] = 1; + dp[2] = 2; + + for(int i=3; i<=n; i++){ + dp[i] = (dp[i-2] + dp[i-1]) % 1234567; + } + return dp[n]; + } +} From 6d8db7d8461580ca83ecba42f71b4e1806ba55bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 30 Oct 2022 19:17:24 +0900 Subject: [PATCH 409/822] =?UTF-8?q?Create=20=EB=B3=B4=EB=AC=BC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\263\264\353\254\274.java" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" diff --git "a/11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" "b/11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" new file mode 100644 index 0000000..1bd994f --- /dev/null +++ "b/11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" @@ -0,0 +1,36 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.StringTokenizer; + +public class Boj_1026_보물 { + static int n, a[]; + static Integer b[]; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st, st2; + + n = Integer.parseInt(br.readLine()); + a = new int[n]; + b = new Integer[n]; + + st = new StringTokenizer(br.readLine()); + st2 = new StringTokenizer(br.readLine()); + for (int i = 0; i < n; i++) { + a[i] = Integer.parseInt(st.nextToken()); + b[i] = Integer.parseInt(st2.nextToken()); + } + + Arrays.sort(a); + Arrays.sort(b, Collections.reverseOrder()); + + long answer = 0; + for(int i=0; i Date: Mon, 31 Oct 2022 06:34:35 +0900 Subject: [PATCH 410/822] =?UTF-8?q?Create=20=EB=B3=B4=EB=AC=BC.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\263\264\353\254\274.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" diff --git "a/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" "b/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" new file mode 100644 index 0000000..3b00a5a --- /dev/null +++ "b/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" @@ -0,0 +1,12 @@ +def solution() -> int: + arr_a.sort(reverse=True) + arr_b.sort() + res = 0 + for i in range(n): + res += (arr_a[i]*arr_b[i]) + +n = int(input()) +arr_a = list(map(int, input().split())) +arr_b = list(map(int, input().split())) +answer = solution() +print(answer) From 007771af95464673c82a58958d984407907601cf Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Mon, 31 Oct 2022 06:38:32 +0900 Subject: [PATCH 411/822] =?UTF-8?q?Update=20=EB=B3=B4=EB=AC=BC.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\263\264\353\254\274.py" | 1 + 1 file changed, 1 insertion(+) diff --git "a/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" "b/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" index 3b00a5a..a7734b8 100644 --- "a/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" +++ "b/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" @@ -4,6 +4,7 @@ def solution() -> int: res = 0 for i in range(n): res += (arr_a[i]*arr_b[i]) + return res n = int(input()) arr_a = list(map(int, input().split())) From ac4059fdad6b65f2a84cb873001fb52b215da6bb Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Mon, 31 Oct 2022 06:40:07 +0900 Subject: [PATCH 412/822] =?UTF-8?q?Create=20=EB=A9=80=EB=A6=AC=EB=9B=B0?= =?UTF-8?q?=EA=B8=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\251\200\353\246\254\353\233\260\352\270\260.py" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" diff --git "a/11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" "b/11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" new file mode 100644 index 0000000..6097dd4 --- /dev/null +++ "b/11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" @@ -0,0 +1,9 @@ +def solution(n): + if n<3: + return n + d=[0]*(n+1) + d[1]=1 + d[2]=2 + for i in range(3,n+1): + d[i]=d[i-1]+d[i-2] + return d[n]%1234567 From 85658b69d1f10f6a6a5379a5d7d501356a6e7012 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Mon, 31 Oct 2022 13:31:21 +0900 Subject: [PATCH 413/822] complete --- .../Main_1026_\353\263\264\353\254\274.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" diff --git "a/11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" "b/11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" new file mode 100644 index 0000000..9d72b2c --- /dev/null +++ "b/11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Comparator; +import java.util.StringTokenizer; + +public class Main_1026_보물 { + static int N, result; + static Integer[] arr, arr2, comb; + static boolean[] isVisited; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1026.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + arr = new Integer[N]; + arr2 = new Integer[N]; + comb = new Integer[N]; + isVisited = new boolean[N]; + result = Integer.MAX_VALUE; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(arr); + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr2[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(arr2, Comparator.reverseOrder()); + + int ans = 0; + for (int i = 0; i < N; i++) { + ans += arr[i] * arr2[i]; + } + + System.out.println(ans); + } // End of main +} // End of Main class From 18591257b081725a3f3ae9bbc84ae5216a7e226a Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Mon, 31 Oct 2022 13:39:57 +0900 Subject: [PATCH 414/822] =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {11.01 => 10.31}/readme.md | 0 .../1026_\353\263\264\353\254\274.cpp" | 0 .../\353\251\200\353\246\254\353\233\260\352\270\260.cpp" | 0 .../\353\251\200\353\246\254\353\233\260\352\270\260.py" | 0 .../\353\263\264\353\254\274.py" | 0 .../\353\251\200\353\246\254 \353\233\260\352\270\260.kt" | 0 .../\353\263\264\353\254\274.kt" | 0 .../Main_1026_\353\263\264\353\254\274.java" | 0 .../\353\251\200\353\246\254\353\233\260\352\270\260.java" | 0 .../\353\263\264\353\254\274.java" | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {11.01 => 10.31}/readme.md (100%) rename "11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" => "10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" (100%) rename "11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" => "10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" (100%) rename "11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" => "10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" (100%) rename "11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" => "10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" (100%) rename "11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" => "10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" (100%) rename "11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" => "10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" (100%) rename "11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" => "10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" (100%) rename "11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" => "10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" (100%) rename "11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" => "10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" (100%) diff --git a/11.01/readme.md b/10.31/readme.md similarity index 100% rename from 11.01/readme.md rename to 10.31/readme.md diff --git "a/11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" "b/10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" similarity index 100% rename from "11.01/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" rename to "10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" diff --git "a/11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" "b/10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" similarity index 100% rename from "11.01/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" rename to "10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" diff --git "a/11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" "b/10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" similarity index 100% rename from "11.01/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" rename to "10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" diff --git "a/11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" "b/10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" similarity index 100% rename from "11.01/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" rename to "10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" diff --git "a/11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" "b/10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" similarity index 100% rename from "11.01/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" rename to "10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" diff --git "a/11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" "b/10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" similarity index 100% rename from "11.01/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" rename to "10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" diff --git "a/11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" "b/10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" similarity index 100% rename from "11.01/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" rename to "10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" diff --git "a/11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" "b/10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" similarity index 100% rename from "11.01/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" rename to "10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" diff --git "a/11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" "b/10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" similarity index 100% rename from "11.01/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" rename to "10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" From 90e659158ef4fe0e61a87d925b190c0234a2317b Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Mon, 31 Oct 2022 14:14:50 +0900 Subject: [PATCH 415/822] Add files via upload --- ...\244\200_1026_\353\263\264\353\254\274.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" diff --git "a/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" "b/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" new file mode 100644 index 0000000..ed9efbc --- /dev/null +++ "b/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" @@ -0,0 +1,19 @@ +n = int(input()) + +aList = list(map(int, input().split())) +bList = list(map(int, input().split())) +minValue = 10 ** 9 + + +def calculate(tempA): + global minValue + result = 0 + for i in range(n): + result += tempA[i] * bList[i] + + return result + +aList.sort() +bList.sort(reverse=True) + +print(calculate(aList)) \ No newline at end of file From 22cbc1028db0fb9f87dee9cbc388c10685f5e5bd Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:02:34 +0900 Subject: [PATCH 416/822] kihun --- ...00\353\246\254\353\233\260\352\270\260.py" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" diff --git "a/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" "b/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" new file mode 100644 index 0000000..ef6de67 --- /dev/null +++ "b/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" @@ -0,0 +1,33 @@ +import math + + +def solution(n): + count1 = 0 + count2 = n // 2 + answer = 0 + + for i in range(count2 + 1): + count1 = n - i * 2 + answer += math.factorial(count1 + i) // (math.factorial(count1) * math.factorial(i)) + + return answer % 1234567 + + +""" +def solution(n): + count1 = 0 + count2 = n // 2 + answer = 0 + + for i in range(count2+1): + count1 = n - i * 2 + answer += factorial(count1+i) // (factorial(count1) * factorial(i)) + + return answer % 1234567 + +def factorial(x): + if x > 1: + return x * factorial(x-1) + else: + return 1 +""" From 5b0cf38fb6e54ba5bf03817de1cb016cb8c65496 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Mon, 31 Oct 2022 20:29:47 +0900 Subject: [PATCH 417/822] =?UTF-8?q?Create=20=EB=A9=80=EB=A6=AC=EB=9B=B0?= =?UTF-8?q?=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\246\254\353\233\260\352\270\260.java" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" diff --git "a/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" "b/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" new file mode 100644 index 0000000..118b2f1 --- /dev/null +++ "b/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" @@ -0,0 +1,19 @@ +class Solution { + public long solution(int n) { + long answer = 0; + if(n==1) return 1; + else if(n==2) return 2; + int[] dp = new int[n+1]; + dp[1] = 1; + dp[2] = 2; + + + + for(int i=3; i Date: Mon, 31 Oct 2022 20:30:21 +0900 Subject: [PATCH 418/822] Create bj1026.java --- .../bj1026.java" | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" diff --git "a/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" "b/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" new file mode 100644 index 0000000..7ce1e90 --- /dev/null +++ "b/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" @@ -0,0 +1,78 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; + +import java.util.Scanner; + + + +public class bj1026 { + + static Scanner scan=new Scanner(System.in); + + + + public static void main(String[] args) { + + // TODO Auto-generated method stub + + int N=scan.nextInt(); + + int[] A=new int[N]; + + Integer[] B=new Integer[N]; + + int[] C=new int[N]; + + HashMap> h=new HashMap<>(); + + for(int i=0;ilist=new ArrayList<>(); +// +// list.add(i); +// +// h.put(B[i], list); +// +// } +// +// else{//이미 키값이 있을 때 +// +// ArrayList list=h.get(B[i]); +// +// list.add(i); +// +// h.put(B[i], list); +// +// } + + + + } + + Arrays.sort(A); + Arrays.sort(B,Collections.reverseOrder()); + int sum=0; + for(int i=0;i Date: Tue, 1 Nov 2022 11:15:01 +0900 Subject: [PATCH 419/822] solve --- 11.03/readme.md | 7 +++ ...1\354\235\230 \352\260\234\354\210\230.kt" | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 11.03/readme.md create mode 100644 "11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" diff --git a/11.03/readme.md b/11.03/readme.md new file mode 100644 index 0000000..70b941d --- /dev/null +++ b/11.03/readme.md @@ -0,0 +1,7 @@ +# 10/26(수) + +## 백준 +- 보물 : https://www.acmicpc.net/problem/1026 + +## 프로그래머스 +- 멀리 뛰기 : https://school.programmers.co.kr/learn/courses/30/lessons/12914 diff --git "a/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" "b/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" new file mode 100644 index 0000000..0fab78e --- /dev/null +++ "b/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" @@ -0,0 +1,50 @@ +package com.ssafy.algorithm + +fun main(){ + val elements = intArrayOf(7,9,1,1,4) + println(Solution().solution(elements)) +} + +class Solution { + + lateinit var set : HashSet //숫자합 set + lateinit var visited : BooleanArray + var isComplete = false //다음 인덱스 넘어가는 체크 배열 + + fun solution(elements: IntArray): Int { + set = HashSet() + visited = BooleanArray(elements.size) + + for (i in 1..elements.size){ + isComplete = false + combination(0,0,0,i,0,elements) + } + + return set.size + } + + private fun combination(size : Int, start : Int,lastIndex : Int , max : Int, sum : Int, elements: IntArray){ + + if (size == max){ + set.add(sum) + isComplete = true + return + } + + //원형 수열이므로 마지막인덱스에서도 + size만큼 숫자 뽑기 + for (i in start until elements.size-1+max){ + if (size == 0) isComplete = false //연속된 수열이 아니면 break + if (size == 0 && i == elements.size) break //마지막인덱스를 지나면 break + + if (!isComplete) combination(size+1,i+1,i,max,sum+elements[i%elements.size],elements) + else break + } + } +} + + + + + + + From 7baea762008d3d8122ee9ffe2d35e27494d97e6f Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Tue, 1 Nov 2022 12:50:41 +0900 Subject: [PATCH 420/822] Update readme.md --- 11.03/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/11.03/readme.md b/11.03/readme.md index 70b941d..4f53f25 100644 --- a/11.03/readme.md +++ b/11.03/readme.md @@ -1,7 +1,7 @@ # 10/26(수) ## 백준 -- 보물 : https://www.acmicpc.net/problem/1026 +- 보물 : https://www.acmicpc.net/problem/14499 ## 프로그래머스 -- 멀리 뛰기 : https://school.programmers.co.kr/learn/courses/30/lessons/12914 +- 연속 부분 수열 합의 개수 : https://school.programmers.co.kr/learn/courses/30/lessons/131701 From 8055fae1d47f01824b279010271e010f67e7298e Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Tue, 1 Nov 2022 12:50:53 +0900 Subject: [PATCH 421/822] Update readme.md --- 11.03/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/11.03/readme.md b/11.03/readme.md index 4f53f25..767675e 100644 --- a/11.03/readme.md +++ b/11.03/readme.md @@ -1,7 +1,7 @@ # 10/26(수) ## 백준 -- 보물 : https://www.acmicpc.net/problem/14499 +- 주사위 굴리기 : https://www.acmicpc.net/problem/14499 ## 프로그래머스 - 연속 부분 수열 합의 개수 : https://school.programmers.co.kr/learn/courses/30/lessons/131701 From d8df1196e0b11f3839082603d538989704d2f374 Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Tue, 1 Nov 2022 23:31:42 +0900 Subject: [PATCH 422/822] Update readme.md --- 10.31/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/10.31/readme.md b/10.31/readme.md index 70b941d..443eaf5 100644 --- a/10.31/readme.md +++ b/10.31/readme.md @@ -1,4 +1,4 @@ -# 10/26(수) +# 10/31(월) ## 백준 - 보물 : https://www.acmicpc.net/problem/1026 From 3c079065908cc7f425abdce0bcdf6ea026eb6993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 2 Nov 2022 00:11:31 +0900 Subject: [PATCH 423/822] =?UTF-8?q?=EC=A3=BC=EC=82=AC=EC=9C=84=20=EA=B5=B4?= =?UTF-8?q?=EB=A6=AC=EA=B8=B0=20=EC=89=AC=EC=9A=B4=EB=8D=B0=EC=9A=94=20=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\265\264\353\246\254\352\270\260.java" | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 "11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" diff --git "a/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" "b/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" new file mode 100644 index 0000000..22709a5 --- /dev/null +++ "b/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" @@ -0,0 +1,154 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + static int N, M, X, Y, K, map[][], order[], dice[]; + static int dx[] = {0, 0, 0, -1, +1}; // 동서북남 + static int dy[] = {0, 1, -1, 0, 0}; // 동서북남 + static int botton = 6; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + X = Integer.parseInt(st.nextToken()); + Y = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + order = new int[K]; + dice = new int[7]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < K; i++) { + order[i] = Integer.parseInt(st.nextToken()); + } + + int nx = X; + int ny = Y; + int diceTemp[] = new int[7]; + boolean inRange = false; + for (int i = 0; i < K; i++) { + inRange = false; + if (order[i] == 1) { // 동 + if (rangeCheck(nx + dx[1], ny + dy[1])) { // 다음 칸이 존재하는 칸이면 + nx += dx[1]; // 칸으로 값을 옮겨주고 + ny += dy[1]; + + inRange = true; // 입실 체크 + + rollDice(1); // 주사위 굴려, + + if (map[nx][ny] > 0) { // 칸에 값이 적혀있으면, 주사위 바닥에 복사, 칸은 0 + dice[6] = map[nx][ny]; + map[nx][ny] = 0; + } else { // 주사의 바닥 값을 칸에 복사, + map[nx][ny] = dice[6]; + } + } + } else if (order[i] == 2) { + if (rangeCheck(nx + dx[2], ny + dy[2])) { + nx += dx[2]; + ny += dy[2]; + + inRange = true; // 입실 체크 + + rollDice(2); + + if (map[nx][ny] > 0) { // 칸에 값이 적혀있으면, 주사위 바닥에 복사, 칸은 0 + dice[6] = map[nx][ny]; + map[nx][ny] = 0; + } else { // 주사의 바닥 값을 칸에 복사, + map[nx][ny] = dice[6]; + } + + } + } else if (order[i] == 3) { + if (rangeCheck(nx + dx[3], ny + dy[3])) { + nx += dx[3]; + ny += dy[3]; + + inRange = true; // 입실 체크 + + rollDice(3); + + if (map[nx][ny] > 0) { // 칸에 값이 적혀있으면, 주사위 바닥에 복사, 칸은 0 + dice[6] = map[nx][ny]; + map[nx][ny] = 0; + } else { // 주사의 바닥 값을 칸에 복사, + map[nx][ny] = dice[6]; + } + } + } else if (order[i] == 4) { + if (rangeCheck(nx + dx[4], ny + dy[4])) { + nx += dx[4]; + ny += dy[4]; + + inRange = true; // 입실 체크 + + rollDice(4); + + if (map[nx][ny] > 0) { // 칸에 값이 적혀있으면, 주사위 바닥에 복사, 칸은 0 + dice[6] = map[nx][ny]; + map[nx][ny] = 0; + } else { // 주사의 바닥 값을 칸에 복사, + map[nx][ny] = dice[6]; + } + } + } + + if (inRange) + System.out.println(dice[1]); + + } + + + } + + + static void rollDice(int i) { + int temp = 0; + if (i == 1) { //동 : 3->1, 1->4, 4->6, 6->3 + temp = dice[6]; + dice[6] = dice[4]; + dice[4] = dice[1]; + dice[1] = dice[3]; + dice[3] = temp; + } else if (i == 2) { // 서 : 4->1, 1->3, 3->6, 6->4 + temp = dice[6]; + dice[6] = dice[3]; + dice[3] = dice[1]; + dice[1] = dice[4]; + dice[4] = temp; + } else if (i == 3) { // 북 : 1->2, 2->6, 6->5, 5->1 + temp = dice[1]; + dice[1] = dice[2]; + dice[2] = dice[6]; + dice[6] = dice[5]; + dice[5] = temp; + } else if (i == 4) { // 남 : 2->1, 1->5, 5->6, 6->2 + temp = dice[2]; + dice[2] = dice[1]; + dice[1] = dice[5]; + dice[5] = dice[6]; + dice[6] = temp; + } + } + + static boolean rangeCheck(int x, int y) { + return 0 <= x && x < N && 0 <= y && y < M; + } +} From cea259b57a8c144eee8825eddfe8bc135b7186fc Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Wed, 2 Nov 2022 11:25:56 +0900 Subject: [PATCH 424/822] solve --- ...4 \352\265\264\353\246\254\352\270\260.kt" | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 "11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" diff --git "a/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" "b/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" new file mode 100644 index 0000000..f26ad3a --- /dev/null +++ "b/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" @@ -0,0 +1,107 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.* + +private val direction = arrayOf(intArrayOf(0, 0), intArrayOf(0, 1), intArrayOf(0, -1), intArrayOf(-1, 0), intArrayOf(1, 0)) //방향 배열 +private lateinit var map: Array //지도 +private var dice = intArrayOf(0,0,0,0,0,0,0) //주사위 + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + var token = StringTokenizer(br.readLine()) + + val N = token.nextToken().toInt() + val M = token.nextToken().toInt() + var y = token.nextToken().toInt() //현재 주사위 x좌표 + var x = token.nextToken().toInt() //현재 주사위 y좌표 + var K = token.nextToken().toInt() + + map = Array(N) { IntArray(M) } + + repeat(N) { row -> + token = StringTokenizer(br.readLine()) + repeat(M) { col -> + map[row][col] = token.nextToken().toInt() + } + } + + token = StringTokenizer(br.readLine()) + val commands = IntArray(K) + + repeat(K) { + commands[it] = token.nextToken().toInt() + } + + for (command in commands){ //명령 시작 + //정상범위일 때 + if (rangeCheck(x + direction[command][1], y + direction[command][0],N,M)){ + //주사위 위치 갱신 + x += direction[command][1] + y += direction[command][0] + + dice = roll(command) //주사위 굴리기 + + //맵에 숫자가 0이 아닐 때 + if (map[y][x] != 0){ + dice[6] = map[y][x] + map[y][x] = 0 + }else{ //맵에 숫자가 0일 때때 + if (dice[6] != 0) map[y][x] = dice[6] + } + + bw.write("${dice[1]}\n") + } + + } + bw.flush() + bw.close() +} + +//범위 체크 +private fun rangeCheck(x : Int, y : Int, N : Int, M : Int) = x in 0 until M && y in 0 until N + +//굴리기 +private fun roll(command : Int) : IntArray { + var changeDice = intArrayOf(0,0,0,0,0,0,0) + when(command){ + //동 + 1 -> { + changeDice[1] = dice[4] + changeDice[2] = dice[2] + changeDice[3] = dice[1] + changeDice[4] = dice[6] + changeDice[5] = dice[5] + changeDice[6] = dice[3] + } + //서 + 2 -> { + changeDice[1] = dice[3] + changeDice[2] = dice[2] + changeDice[3] = dice[6] + changeDice[4] = dice[1] + changeDice[5] = dice[5] + changeDice[6] = dice[4] + } + //북 + 3 -> { + changeDice[1] = dice[5] + changeDice[2] = dice[1] + changeDice[3] = dice[3] + changeDice[4] = dice[4] + changeDice[5] = dice[6] + changeDice[6] = dice[2] + } + //남 + 4 -> { + changeDice[1] = dice[2] + changeDice[2] = dice[6] + changeDice[3] = dice[3] + changeDice[4] = dice[4] + changeDice[5] = dice[1] + changeDice[6] = dice[5] + } + } + return changeDice +} \ No newline at end of file From 20d2bb19fc8c6542c2030344261344d05ee3f94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 2 Nov 2022 23:09:22 +0900 Subject: [PATCH 425/822] =?UTF-8?q?Create=2014499=5F=EC=A3=BC=EC=82=AC?= =?UTF-8?q?=EC=9C=84=5F=EA=B5=B4=EB=A6=AC=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\352\265\264\353\246\254\352\270\260.cpp" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" diff --git "a/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" "b/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" new file mode 100644 index 0000000..a8004de --- /dev/null +++ "b/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" @@ -0,0 +1,83 @@ +#include +#include +using namespace std; + +int N, M, x, y, K; +vector> board; +int dir = 6; //현재 바닥에 있는 방향 +int dice[7] = { 0 }; //주사위 + +void checkDir(int n) { + int tmp; + switch (n) { + case 1 : + tmp = dice[4]; + dice[4] = dice[1]; + dice[1] = dice[3]; + dice[3] = dice[6]; + dice[6] = tmp; + break; + case 2: + tmp = dice[3]; + dice[3] = dice[1]; + dice[1] = dice[4]; + dice[4] = dice[6]; + dice[6] = tmp; + break; + case 3: + tmp = dice[5]; + dice[5] = dice[1]; + dice[1] = dice[2]; + dice[2] = dice[6]; + dice[6] = tmp; + break; + case 4: + tmp = dice[2]; + dice[2] = dice[1]; + dice[1] = dice[5]; + dice[5] = dice[6]; + dice[6] = tmp; + break; + } +} +int dx[] = { 0,0,0,-1,1 }; +int dy[] = { 0,1,-1,0,0 }; + +void goDir(int next) { + //이동 + int xx = x + dx[next]; + int yy = y + dy[next]; + if (0 <= xx && xx < N && 0 <= yy && yy < M) { + x = xx; + y = yy; + } + else return; + checkDir(next); + //쓰기 + if (board[x][y] == 0) { + board[x][y] = dice[6]; + } + else { + dice[6] = board[x][y]; + board[x][y] = 0; + } + //출력 + cout << dice[1] << endl; +} + +int main() { + cin >> N >> M >> x >> y >> K; + for (int i = 0; i < N; i++) { + vector list; + for (int k = 0; k < M; k++) { + int n; cin >> n; + list.push_back(n); + } + board.push_back(list); + } + for (int i = 0; i < K; i++) { + int n; cin >> n; + goDir(n); + } + return 0; +} From 7a6a35bf8d90e0dd8f079b700ae6fdfd148d5f5d Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Thu, 3 Nov 2022 01:20:39 +0900 Subject: [PATCH 426/822] Create BJ14499.java --- .../BJ14499.java" | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 "11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" diff --git "a/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" "b/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" new file mode 100644 index 0000000..d5bdf02 --- /dev/null +++ "b/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" @@ -0,0 +1,238 @@ +import java.util.Scanner; + + + +public class BJ14499 { + + static Scanner scan=new Scanner(System.in); + + static int N,M,x,y,K; + + static int[][]arr; + + static int [] move; + + static int[]dx= {0,0,-1,1}; + + static int[]dy= {1,-1,0,0}; + + static class pos2{ + + int x,y; + + public pos2(int x,int y) { + + this.x=x; + + this.y=y; + + } + + } + + static class dto{ + pos2 pos; //리턴할 좌표 + int[] dice; + boolean issuccess; + public dto(pos2 pos,int[] dice,boolean issuccess) { + this.pos=pos; + this.dice=dice; + this.issuccess=issuccess; + } + + } + public static void main(String[] args) { + + + + //격자의 크기 + + N=scan.nextInt(); + + M=scan.nextInt(); + + //좌표 + + x=scan.nextInt(); + + y=scan.nextInt(); + + K=scan.nextInt(); //명령의 개수 + + + + arr=new int[N][M]; + + move=new int[K]; + + for(int i=0;i=N||y>=M) { //격자 탈출할라카면 + return new dto(new pos2(pos.x,pos.y),dice,false); + } + else return new dto(new pos2(x,y),dice_cp,true); + + } + + else if(dir==2) { + + dice_cp[1]=dice[3]; + + dice_cp[2]=dice[2]; + + dice_cp[3]=dice[6]; + + dice_cp[4]=dice[1]; + + dice_cp[5]=dice[5]; + + dice_cp[6]=dice[4]; + + int x=pos.x+dx[dir-1]; + + int y=pos.y+dy[dir-1]; + if(x<0||y<0||x>=N||y>=M) { //격자 탈출할라카면 + return new dto(new pos2(pos.x,pos.y),dice,false); + } + else return new dto(new pos2(x,y),dice_cp,true); + } + + else if(dir==3) { + + dice_cp[1]=dice[5]; + + dice_cp[2]=dice[1]; + + dice_cp[3]=dice[3]; + + dice_cp[4]=dice[4]; + + dice_cp[5]=dice[6]; + + dice_cp[6]=dice[2]; + + int x=pos.x+dx[dir-1]; + + int y=pos.y+dy[dir-1]; + if(x<0||y<0||x>=N||y>=M) { //격자 탈출할라카면 + return new dto(new pos2(pos.x,pos.y),dice,false); + } + else return new dto(new pos2(x,y),dice_cp,true); + } + + else if(dir==4) { + + dice_cp[1]=dice[2]; + + dice_cp[2]=dice[6]; + + dice_cp[3]=dice[3]; + + dice_cp[4]=dice[4]; + + dice_cp[5]=dice[1]; + + dice_cp[6]=dice[5]; + + int x=pos.x+dx[dir-1]; + + int y=pos.y+dy[dir-1]; + if(x<0||y<0||x>=N||y>=M) { //격자 탈출할라카면 + return new dto(new pos2(pos.x,pos.y),dice,false); + } + else return new dto(new pos2(x,y),dice_cp,true); + + } + return null; + + } + + + +} From 152cbae4c57e1de24fefcd1a6b5bd2b0cbc482c2 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 3 Nov 2022 01:51:39 +0900 Subject: [PATCH 427/822] =?UTF-8?q?Create=20=EC=A3=BC=EC=82=AC=EC=9C=84?= =?UTF-8?q?=EA=B5=B4=EB=A6=AC=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\265\264\353\246\254\352\270\260.java" | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 "11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" diff --git "a/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" "b/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" new file mode 100644 index 0000000..70f1f38 --- /dev/null +++ "b/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" @@ -0,0 +1,110 @@ +import java.util.*; +import java.io.*; + +public class 주사위굴리기_14499 { + + static int[] dx = { 1, -1, 0, 0 }; + static int[] dy = { 0, 0, -1, 1 }; + static ArrayList dice, copy, dir; + static int[][] map; + static int n, m, k, curR, curC; + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + curR = Integer.parseInt(st.nextToken()); + curC = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + + map = new int[n][m]; + dice = new ArrayList<>(); + dir = new ArrayList<>(); + copy = new ArrayList<>(); + + // 배열 입력 + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < m; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + //주사위 입력(초기값 0) + for(int i=0; i<6; i++) { + dice.add(0); + } + + // 주사위 굴릴 방향 입력(0 ~ 3) + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < k; i++) { + dir.add(Integer.parseInt(st.nextToken()) - 1); + } + + for (int i = 0; i < k; i++) { + check(); + } + + } + + static void check() { + int nextR = curR + dy[dir.get(0)]; + int nextC = curC + dx[dir.get(0)]; + + if (0 <= nextR && nextR < n && 0 <= nextC && nextC < m) { // 다음 좌표가 배열 범위 안에 있을 때만 실행 + curR = nextR; + curC = nextC; + + move(dir.get(0)); // 주사위 굴려줌 + + // 주사위 밑부분과 닿은 칸 확인하고 작업 + if (map[curR][curC] == 0) { + map[curR][curC] = dice.get(5); + } else if (map[curR][curC] != 0) { + dice.set(5, map[curR][curC]); + map[curR][curC] = 0; + } + + System.out.println(dice.get(0)); // 주사위 윗 면 출력 + } + dir.remove(0); + } + + static void move(int direction) { + copy.clear(); + copy.addAll(dice); + switch (direction) { + case 0: { // 동쪽 이동 + dice.set(0, copy.get(2)); + dice.set(2, copy.get(5)); + dice.set(3, copy.get(0)); + dice.set(5, copy.get(3)); + break; + } + case 1: { // 서쪽 이동 + dice.set(0, copy.get(3)); + dice.set(2, copy.get(0)); + dice.set(3, copy.get(5)); + dice.set(5, copy.get(2)); + break; + } + case 2: { // 북쪽 이동 + dice.set(0, copy.get(1)); + dice.set(1, copy.get(5)); + dice.set(4, copy.get(0)); + dice.set(5, copy.get(4)); + break; + } + case 3: { // 남쪽 이동 + dice.set(0, copy.get(4)); + dice.set(1, copy.get(0)); + dice.set(4, copy.get(5)); + dice.set(5, copy.get(1)); + break; + } + } + } +} From c8f42d10c027794eec2be662cb893fe7fbbceb26 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 3 Nov 2022 02:43:27 +0900 Subject: [PATCH 428/822] =?UTF-8?q?Create=20=EC=97=B0=EC=86=8D=EB=B6=80?= =?UTF-8?q?=EB=B6=84=EC=88=98=EC=97=B4=ED=95=A9=EC=9D=98=EA=B0=9C=EC=88=98?= =?UTF-8?q?.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\230\352\260\234\354\210\230.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" diff --git "a/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" "b/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" new file mode 100644 index 0000000..13a8c60 --- /dev/null +++ "b/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" @@ -0,0 +1,30 @@ +import java.util.HashSet; +import java.util.Set; + +public class 연속부분수열합의개수2 { + static int[] elements = { 7, 9, 1, 1, 4 }; + static int answer = 0; + + public static void main(String[] args) { + + Set set = new HashSet<>(); + + int[] ele = new int[elements.length * 2]; + for (int i = 0; i < elements.length * 2; i++) { + ele[i] = elements[i % elements.length]; + } + + for (int len = 1; len <= elements.length; len++) { + for (int start = 0; start < elements.length; start++) { + int temp = 0; + for (int point = start; point < start + len; point++) { + temp += ele[point]; + } + set.add(temp); + } + } + answer = set.size(); + + System.out.println(answer); + } +} From 8604838f6f71b411fdc8b91a9548a62e27a6c905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 3 Nov 2022 11:04:44 +0900 Subject: [PATCH 429/822] =?UTF-8?q?Create=20=EB=B6=80=EB=B6=84=ED=95=A9?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\352\265\254\355\225\230\352\270\260.cpp" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" diff --git "a/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" "b/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..bbf6a49 --- /dev/null +++ "b/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" @@ -0,0 +1,21 @@ +#include +#include +#include + +using namespace std; + +int solution(vector elements) { + set s; + vector tmp(elements.begin(), elements.end()); + tmp.insert(tmp.end(), elements.begin(), elements.end()); + for (int i = 1; i <= elements.size(); i++) { + for (int t = 0; t < elements.size(); t++) { + int num = 0; + for (int k = 0; k < i; k++) { + num += tmp[t + k]; + } + s.insert(num); + } + } + return s.size(); +} From 12ba86f7fc0a9019f0726169c8d973b1588e5331 Mon Sep 17 00:00:00 2001 From: JUHYEON KWON <38181228+rnjswngus275@users.noreply.github.com> Date: Thu, 3 Nov 2022 15:36:48 +0900 Subject: [PATCH 430/822] =?UTF-8?q?Create=20=EB=B6=80=EB=B6=84=ED=95=A9.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\266\200\353\266\204\355\225\251.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" diff --git "a/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" "b/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" new file mode 100644 index 0000000..286ba0d --- /dev/null +++ "b/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" @@ -0,0 +1,30 @@ +import java.util.*; +class Solution { + Set set=new HashSet(); + public int solution(int[] elements) { + int answer = 0; + int leng=elements.length; + int[] arr=new int[leng*2+1]; + System.arraycopy(elements,0,arr,0,leng); + System.arraycopy(elements,0,arr,leng,leng); + + // for(int i=0;i Date: Thu, 3 Nov 2022 20:06:45 +0900 Subject: [PATCH 431/822] =?UTF-8?q?Create=20=EC=97=B0=EC=86=8D=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=88=98=EC=97=B4=20=ED=95=A9=EC=9D=98=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\235\230 \352\260\234\354\210\230.java" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" diff --git "a/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" "b/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" new file mode 100644 index 0000000..24310d5 --- /dev/null +++ "b/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" @@ -0,0 +1,28 @@ +import java.util.*; + +class Solution { + static ArrayList list = new ArrayList<>(); + static int size; + static int arr[]; + static HashSet set; + + public int solution(int[] elements) { + size = elements.length; + arr = new int[size * 2]; + set = new HashSet<>(); + for (int i = 0; i < size * 2; i++) { + arr[i] = elements[i % size]; + } + for (int start = 0; start < size; start++) { // 시작점 잡고 + int sum = 0; + int i = 0; + while(i < size && i + start < size * 2) { // 1개부터 size개까지 + sum += arr[i + start]; + set.add(sum); + i++; + } + } + return set.size(); + } + +} From 47b555f0c257ae517f56c75b3ba3f3912d4e3116 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 3 Nov 2022 20:08:51 +0900 Subject: [PATCH 432/822] kihun --- ...1\354\235\230_\352\260\234\354\210\230.py" | 11 +++++ ...04\352\265\264\353\246\254\352\270\260.py" | 43 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 "11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" create mode 100644 "11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" diff --git "a/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" "b/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" new file mode 100644 index 0000000..570e4ce --- /dev/null +++ "b/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" @@ -0,0 +1,11 @@ +def solution(elements): + n = len(elements) + resultSet = set() + elements = elements + elements + for i in range(n): + for j in range(n): + sumValue = sum(elements[j:j+i+1]) + resultSet.add(sumValue) + + answer = len(resultSet) + return answer \ No newline at end of file diff --git "a/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" "b/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" new file mode 100644 index 0000000..64a0ba4 --- /dev/null +++ "b/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" @@ -0,0 +1,43 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +maxY, maxX, startY, startX, n = map(int, input().split()) + +matrix = [] + +for _ in range(maxY): + matrix.append(list(map(int, input().split()))) + +moveList = list(map(int, input().split())) + +# 동 서 북 남 +dy = [0, 0, -1, 1] +dx = [1, -1, 0, 0] +dice = [0, 0, 0, 0, 0, 0] +y, x = startY, startX +for i in range(n): + d = moveList[i] - 1 + nY = y + dy[d] + nX = x + dx[d] + + if 0 <= nY < maxY and 0 <= nX < maxX: + if d == 0: + dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2] + elif d == 1: + dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3] + elif d == 2: + dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1] + elif d == 3: + dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4] + + # 이동한 칸에 0이 쓰여져 있으면 복사 + if matrix[nY][nX] == 0: + matrix[nY][nX] = dice[5] + # 아니면 바닥면에 복사하고 칸은 0으로 + else: + dice[5] = matrix[nY][nX] + matrix[nY][nX] = 0 + + y, x = nY, nX + print(dice[0]) From 185d5e030f11aff85fa50785ff57896ba0e34e38 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sat, 5 Nov 2022 16:50:44 +0900 Subject: [PATCH 433/822] =?UTF-8?q?Create=20=EB=93=9C=EB=9E=98=EA=B3=A4?= =?UTF-8?q?=EC=BB=A4=EB=B8=8C.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\263\244\354\273\244\353\270\214.java" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" diff --git "a/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" "b/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" new file mode 100644 index 0000000..790dea0 --- /dev/null +++ "b/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" @@ -0,0 +1,72 @@ +package baekjoon; + +import java.util.*; +import java.io.*; + +public class 드래곤커브_15685 { + static int[][] board; + static int ans, n, startR, dir, startC, gen; + static ArrayList dirTemp; + static int[] dx = { 1, 0, -1, 0 }; + static int[] dy = { 0, -1, 0, 1 }; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + n = Integer.parseInt(br.readLine()); + board = new int[101][101]; + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + startC = Integer.parseInt(st.nextToken()); + startR = Integer.parseInt(st.nextToken()); + dir = Integer.parseInt(st.nextToken()); + gen = Integer.parseInt(st.nextToken()); + + dirTemp = new ArrayList<>(); + dirTemp.add(dir); + board[startR][startC] = 1; + makeDir(); + draw(); + } + + checkResult(); + System.out.println(ans); + } + + static void makeDir() { + // 그려야하는 선의 개수는 2^gen 개수 + if (dirTemp.size() == Math.pow(2, gen)) { + return; + } + for (int i = dirTemp.size() - 1; i >= 0; i--) { + int nextDir = dirTemp.get(i)+1; + if(nextDir > 3) nextDir = 0; + dirTemp.add(nextDir); + } + makeDir(); + } + + static void draw() { + for (int i = 0; i < dirTemp.size(); i++) { + int direction = dirTemp.get(i); + int nextR = startR + dy[direction]; + int nextC = startC + dx[direction]; + + board[nextR][nextC] = 1; + startR = nextR; + startC = nextC; + } + } + + static void checkResult() { + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { + if (board[i][j] == 1 && board[i + 1][j] == 1 && board[i][j + 1] == 1 && board[i + 1][j + 1] == 1) { + ans++; + } + } + } + } +} From 57b7b2703ed79603f66dae9410b197bad17c175c Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sat, 5 Nov 2022 16:50:58 +0900 Subject: [PATCH 434/822] =?UTF-8?q?Update=20=EB=93=9C=EB=9E=98=EA=B3=A4?= =?UTF-8?q?=EC=BB=A4=EB=B8=8C.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...23\234\353\236\230\352\263\244\354\273\244\353\270\214.java" | 2 -- 1 file changed, 2 deletions(-) diff --git "a/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" "b/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" index 790dea0..d4259cb 100644 --- "a/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" +++ "b/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" @@ -1,5 +1,3 @@ -package baekjoon; - import java.util.*; import java.io.*; From 5f41a4016d740220708dcb229cf1079e1107ca7b Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 5 Nov 2022 19:21:10 +0900 Subject: [PATCH 435/822] complete --- ...\352\265\264\353\246\254\352\270\260.java" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" diff --git "a/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" "b/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" new file mode 100644 index 0000000..6a8db3a --- /dev/null +++ "b/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" @@ -0,0 +1,101 @@ +import java.io.*; +import java.util.*; + +public class Main_14499_주사위_굴리기 { + static int N, M, startX, startY; + static int[][] map = new int[21][21]; + static int[] dice = new int[7]; + static int[] dirX = {1, -1, 0, 0}; + static int[] dirY = {0, 0, - 1, 1}; + static StringBuilder sb; + + // 가장 처음에 주사위에는 모든 면에 0이 적혀있다. + // 동쪽은 1, 서쪽은 2, 북쪽은 3 남쪽은 4 + // 이동한 칸에 쓰여있는 수가 0이면, 주사위의 바닥면에 쓰여 있는 수가 칸에 복사된다. + // 0이 아닌경우에는 칸에 쓰여있는 수가 주사위 바닥면으로 복사되며, 칸에 쓰여있는 수는 0이 된다. + + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/14499.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + startY = Integer.parseInt(st.nextToken()); + startX = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < K; i++) { + move(Integer.parseInt(st.nextToken())); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void move(int direction) { + int nowX = startX + dirX[direction - 1]; + int nowY = startY + dirY[direction - 1]; + + if (!rangeCheck(nowX, nowY)) return; + + roll(direction, nowX, nowY); + startX = nowX; + startY = nowY; + } // End of move + + private static void roll(int num, int x, int y) { + int temp = dice[3]; + + if (num == 1) { + dice[3] = dice[4]; + dice[4] = dice[6]; + dice[6] = dice[2]; + dice[2] = temp; + } else if (num == 2) { + dice[3] = dice[2]; + dice[2] = dice[6]; + dice[6] = dice[4]; + dice[4] = temp; + } else if (num == 3) { + dice[3] = dice[5]; + dice[5] = dice[6]; + dice[6] = dice[1]; + dice[1] = temp; + } else if (num == 4) { + dice[3] = dice[1]; + dice[1] = dice[6]; + dice[6] = dice[5]; + dice[5] = temp; + } + + if (map[y][x] == 0) { + map[y][x] = dice[6]; + } else { + dice[6] = map[y][x]; + map[y][x] = 0; + } + + sb.append(dice[3]).append('\n'); + } // End of roll + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < M && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + sb = new StringBuilder(); + } // End of init +} // End of Main class \ No newline at end of file From e9aad88c5a93d34c991c02d2688a0c1a91172762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 5 Nov 2022 21:21:14 +0900 Subject: [PATCH 436/822] =?UTF-8?q?Create=20=EB=B0=B0=EB=8B=AC.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\260\353\213\254.cpp" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" diff --git "a/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" "b/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" new file mode 100644 index 0000000..d521312 --- /dev/null +++ "b/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" @@ -0,0 +1,37 @@ +#include +#include +#include +#include +using namespace std; + +int solution(int N, vector> road, int K) { + int answer = 0; + vector>> board(N+1,vector>()); + for (auto r: road) { + board[r[0]].push_back({ r[1], r[2] }); + board[r[1]].push_back({ r[0], r[2] }); + } + priority_queue> pq; + vector visited(N + 1, false); + pq.push({ 0,1 }); + visited[1] = true; + while (!pq.empty()) { + int cnt = pq.top().first * -1; + int now = pq.top().second; + pq.pop(); + visited[now] = true; + for (auto b : board[now]) { + if (!visited[b.first] && cnt + b.second <= K) { + pq.push({ -1 * (b.second + cnt), b.first}); + } + } + } + + for (int i = 1; i <= N; i++) { + if (visited[i]) { + answer++; + } + } + + return answer; +} From 22f8f0e1fc8888f9c2d2c2ac8aa042d34f1be8ea Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 6 Nov 2022 16:43:23 +0900 Subject: [PATCH 437/822] solve --- ...0\352\263\244 \354\273\244\353\270\214.kt" | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 "11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" diff --git "a/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" "b/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" new file mode 100644 index 0000000..c867e95 --- /dev/null +++ "b/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" @@ -0,0 +1,102 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.StringTokenizer + +val direction = arrayOf(intArrayOf(1,0), intArrayOf(0,-1), intArrayOf(-1,0), intArrayOf(0,1)) //방향 +var endX = 0 +var endY = 0 +lateinit var board : Array +var count = 0 + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + + val N = br.readLine().toInt() + board = Array(101){IntArray(101)} + var dList = ArrayList() + + repeat(N){ + val token = StringTokenizer(br.readLine()) + + val x = token.nextToken().toInt() + val y = token.nextToken().toInt() + val d = token.nextToken().toInt() + val g = token.nextToken().toInt() + + dList.clear() + board[y][x] = 1 + + for (i in 0 .. g){ + when(i){ + 0 -> { + dList.add(d) + endX = x + direction[d][0] + endY = y + direction[d][1] + board[endY][endX] = 1 + + } + 1 ->{ + val curveDirection = if (d - 1 < 0) 3 else d - 1 + dList.add(0,curveDirection) + val nextX = endX - direction[curveDirection][0] + val nextY = endY - direction[curveDirection][1] + endX = nextX + endY = nextY + board[endY][endX] = 1 + }else -> { + curve(dList) + } + } + } + } + + //정사각형 찾기 + for (i in 0..100){ + for (j in 0..100){ + if (board[i][j] == 1){ + square(j,i) + } + } + } + + println(count) + +} + +//드래곤 커브 +fun curve(dList : ArrayList){ + + val tempList = ArrayList() + val startIndex = dList.size + + for (i in dList.size-1 downTo 0){ //방향 추가해주기 + val curveDirection = if (dList[i] - 1 < 0) 3 else dList[i] - 1 + tempList.add(curveDirection) //다음 세대 드래곤 커브 방향 추가 + } + + dList.addAll(0,tempList) + + for (i in startIndex-1 downTo 0){ //방향이 끝 점 기준으로 처음에는 나가는 방향 그 다음은 들어오는 방향 규칙 + if(i % 2 != 0){ //끝 점을 기준으로 나가는 방향 + val nextX = endX + direction[dList[i]][0] + val nextY = endY + direction[dList[i]][1] + endX = nextX + endY = nextY + }else{ //끝 점을 기준으로 들어오는 방향 + val nextX = endX - direction[dList[i]][0] + val nextY = endY - direction[dList[i]][1] + endX = nextX + endY = nextY + } + board[endY][endX] = 1 + } +} + +//4점이 정사각형인지 체크 +fun square(x : Int, y : Int){ + if (x + 1 < 101 && y + 1 < 101){ //범위체크 + if (board[y][x+1] == 1 && board[y+1][x] == 1 && board[y+1][x+1] == 1) count++ //세점이 1일때 + } +} + From 8dc64d474173447dfd0765909627025e0ee5c0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Sun, 6 Nov 2022 17:31:02 +0900 Subject: [PATCH 438/822] =?UTF-8?q?=EC=96=B4=EB=A0=B5=EA=B5=B0=EC=9A=94..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\263\244_\354\273\244\353\270\214.java" | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" diff --git "a/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" "b/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" new file mode 100644 index 0000000..ea5a98e --- /dev/null +++ "b/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" @@ -0,0 +1,112 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int N, X, Y, D, G; + static ArrayList> list = new ArrayList<>(); + static ArrayList

set = new ArrayList<>(); + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + + for (int i = 0; i < N; i++) { + list = new ArrayList<>(); + st = new StringTokenizer(br.readLine()); + X = Integer.parseInt(st.nextToken()); + Y = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()) + 1; + G = Integer.parseInt(st.nextToken()); + + for (int k = 0; k <= G; k++) { + list.add(new ArrayList<>()); + } + + draw(); + } + + int ans = 0; + for (P p : set) { + if ((rangeCheck(p.x, p.y) && rangeCheck(p.x, p.y + 1) && rangeCheck(p.x + 1, p.y) && rangeCheck(p.x + 1, p.y + 1))) { + if (set.contains(new P(p.x, p.y + 1)) && + set.contains(new P(p.x + 1, p.y)) && + set.contains(new P(p.x + 1, p.y + 1))) { + ++ans; + } + } + } + + System.out.println(ans); + } + + static void draw() { + // 1.list에 방향을 넣고 + // 2. 그 방향대로 이동한 후 끝점을 X, Y에 넣고 + // 3. set에 방문한 점을 넣어준다. + if (!set.contains(new P(X, Y))) + set.add(new P(X, Y)); + list.get(0).add(D); // 세대 방향 + moveXY(D); // XY이동 + if (!set.contains(new P(X, Y))) + set.add(new P(X, Y)); // 방문 체크 + + if (1 <= G) { + list.get(1).add(D % 4 + 1); // 1세대 방향 + moveXY(D % 4 + 1); // XY이동 + if (!set.contains(new P(X, Y))) + set.add(new P(X, Y)); // 방문 체크 + } + + for (int i = 2; i <= G; i++) { + // 2세대 뒤에서부터 + for (int a = i - 1; a >= 0; a--) { // 1, 0 + for (int b = list.get(a).size() - 1; b >= 0; b--) { + int d = list.get(a).get(b) % 4 + 1; + list.get(i).add(d); + moveXY(d); + if (!set.contains(new P(X, Y))) + set.add(new P(X, Y)); // 방문 체크 + } + } + } + } + + static void moveXY(int d) { + if (d == 1) { + X += 1; + } else if (d == 2) { + Y -= 1; + } else if (d == 3) { + X -= 1; + } else if (d == 4) { + Y += 1; + } + } + + static boolean rangeCheck(int x, int y) { + return 0 <= x && x <= 100 && 0 <= y && y <= 100; + } + + static class P { + int x; + int y; + + P(int x, int y) { + this.x = x; + this.y = y; + } + + + // 이거 없으면 객체 값 비교 안 됨 = contains 안됨 + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + P p = (P) o; + return x == p.x && y == p.y; + } + } +} From 4f0ed5acb262a333234131d088c50feff20e5828 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 6 Nov 2022 23:17:55 +0900 Subject: [PATCH 439/822] solve --- .../\353\260\260\353\213\254.kt" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" diff --git "a/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" "b/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" new file mode 100644 index 0000000..8f3188a --- /dev/null +++ "b/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" @@ -0,0 +1,65 @@ +package com.ssafy.algorithm + +import java.util.* +import kotlin.collections.HashMap + +fun main() { + val N = 5 + val road = arrayOf( + intArrayOf(1, 2, 1), intArrayOf(2, 3, 3), intArrayOf(5, 2, 2), intArrayOf(1, 4, 2), + intArrayOf(5, 3, 1), intArrayOf(5, 4, 2) + ) + val K = 3 + println(Solution().solution(N, road, K)) +} + +class Solution { + lateinit var graph: Array> + lateinit var visited: IntArray //음식 배달한 가능 시간 안에 들어오는 배열 + fun solution(N: Int, road: Array, k: Int): Int { + + graph = Array(N + 1) { HashMap() } + + for (info in road) { //양방향 그래프 정보 입력 + + if(graph[info[0]].containsKey(info[1])){ //최소거리로 갱신하기 + if(graph[info[0]][info[1]]!! > info[2]){ + graph[info[0]][info[1]] = info[2] + graph[info[1]][info[0]] = info[2] + } + }else{ + graph[info[0]][info[1]] = info[2] + graph[info[1]][info[0]] = info[2] + } + } + + visited = IntArray(N + 1){-1} + + bfs(1) //탐색 시작 + + return visited.filter { it != -1 && it <= k }.size + } + + fun bfs(node : Int) { + visited[node] = 0 + var queue : Queue = LinkedList() + queue.add(node) + + while (queue.isNotEmpty()){ + + val qPoll = queue.poll() + + for (next in graph[qPoll].keys){ + var distance = graph[qPoll][next] //거리 + + if(visited[next]==-1){ //방문했던 곳이 아니면 초기화 + queue.add(next) + visited[next] = distance!!+visited[qPoll] + }else if(visited[next] > visited[qPoll]+distance!!){ //이미 방문한 노드면 최소거리로 갱신 + visited[next] = visited[qPoll]+distance + queue.add(next) + } + } + } + } +} \ No newline at end of file From b85fdb63104dec9c83b6cc8273fa60506ecf8751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 7 Nov 2022 11:13:27 +0900 Subject: [PATCH 440/822] Create readme.md --- 11.07/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 11.07/readme.md diff --git a/11.07/readme.md b/11.07/readme.md new file mode 100644 index 0000000..6cea667 --- /dev/null +++ b/11.07/readme.md @@ -0,0 +1,7 @@ +# 11.07(월) 스터디 + +15685_드래곤_커브 +https://www.acmicpc.net/problem/15685 + +배달 +https://school.programmers.co.kr/learn/courses/30/lessons/12978 From 51e97f010a4df001103dfb269921ac5662c5464c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 7 Nov 2022 13:42:02 +0900 Subject: [PATCH 441/822] =?UTF-8?q?Create=2015685=5F=EB=93=9C=EB=9E=98?= =?UTF-8?q?=EA=B3=A4=EC=BB=A4=EB=B8=8C.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\352\263\244\354\273\244\353\270\214.cpp" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" diff --git "a/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" "b/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" new file mode 100644 index 0000000..eae751d --- /dev/null +++ "b/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +using namespace std; + +vector> board(101,vector(101,false)); +int x, y, d, g; + +int dy[] = {0,-1,0,1}; +int dx[] = {1,0,-1,0}; +int N; +int checkCycle() { + int answer = 0; + for (int i = 0; i < 100; i++) { + for (int k = 0; k < 100; k++) { + if (board[i][k]) { + if (board[i][k + 1] && board[i + 1][k] && board[i + 1][k + 1]) { + answer++; + } + } + } + } + return answer; +} + +void goDragon() { + stack go; + go.push(d); + vector list; + for (int i = 0; i <= g; i++) { + while (!go.empty()) { + board[y][x] = true; + d = go.top(); go.pop(); + list.push_back(d); + y += dy[d]; + x += dx[d]; + } + board[y][x] = true; + for (int n : list) { + go.push(n + 1 > 3 ? 0 : n + 1); + } + } +} + +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + cin >> x >> y >> d >> g; + goDragon(); + } + cout << checkCycle() << "\n"; + return 0; +} From c58addf02e3d823a4b45d91967073918a20c395b Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Mon, 7 Nov 2022 19:49:18 +0900 Subject: [PATCH 442/822] =?UTF-8?q?=EB=82=B4=EA=B0=80=20=EC=A0=9C=EC=9D=BC?= =?UTF-8?q?=20=EC=A2=8B=EC=95=84=ED=95=98=EB=8A=94=20=EB=8B=A4=EC=9D=B5?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main_PRG_\353\260\260\353\213\254.java" | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 "11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" diff --git "a/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" "b/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" new file mode 100644 index 0000000..09f3e07 --- /dev/null +++ "b/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" @@ -0,0 +1,104 @@ +import java.util.*; + +public class Main_PRG_배달 { + private static final int INF = Integer.MAX_VALUE; + static int N, K; + static int[][] road; + static List> nodeList; + + static class Node implements Comparable { + int nodeNum; + int weight; + + public Node(int nodeNum, int weight) { + this.nodeNum = nodeNum; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return weight - o.weight; + } + } // End of Node class + + public static void main(String[] args) { + Main_PRG_배달 m = new Main_PRG_배달(); + + int N = 6; + int[][] road = {{1, 2, 1}, {1, 3, 2}, {2, 3, 2}, {3, 4, 3}, {3, 5, 2}, {3, 5, 3}, {5, 6, 1}}; + int K = 4; + + System.out.println(m.solution(N, road, K)); + } // End of main + + // 참고 + // 양방향으로 통행 가능 + + private int solution(int N, int[][] road, int K) { + this.N = N; // 마을의 개수 (노드) + this.road = road; // 도로 (간선) + this.K = K; // 음식 배달이 가능한 시간 (제한 사항) + init(); + + // K시간 이내로 받을 수 있는 집. 찾기 + + int len = road.length; + for (int i = 0; i < len; i++) { + int a = road[i][0]; + int b = road[i][1]; + int c = road[i][2]; + + nodeList.get(a).add(new Node(b, c)); + nodeList.get(b).add(new Node(a, c)); + } + + // 1번 마을에 있는 음식점이 K 이하의 시간에 배달이 가능한 마을의 개수를 return 하면 됩니다. + return resultCheck(dijkstra(1)); + } // End of solution + + private static int[] dijkstra(int startNodeNum) { + PriorityQueue pque = new PriorityQueue<>(); + boolean[] isVisited = new boolean[N + 1]; + int dist[] = new int[N + 1]; + + Arrays.fill(dist, INF); + dist[startNodeNum] = 0; + pque.offer(new Node(startNodeNum, 0)); + + while (!pque.isEmpty()) { + Node pollNode = pque.poll(); + + if (isVisited[pollNode.nodeNum]) continue; + isVisited[pollNode.nodeNum] = true; + + for (Node node : nodeList.get(pollNode.nodeNum)) { + if (!isVisited[node.nodeNum] && dist[node.nodeNum] > dist[pollNode.nodeNum] + node.weight) { + dist[node.nodeNum] = dist[pollNode.nodeNum] + node.weight; + pque.offer(new Node(node.nodeNum, dist[node.nodeNum])); + } + } + } + + return dist; + } // End of dijkstra + + private static int resultCheck(int[] dist) { + int sum = 0; + for (int i = 1; i <= N; i++) { + if (dist[i] <= K) { + sum++; + } + } + + return sum; + } // End of resultCheck + + private static void init() { + nodeList = new ArrayList<>(); + + for (int i = 0; i <= N; i++) { + nodeList.add(new ArrayList<>()); + } + + } // End of init +} // End of Main class From 711796fb931e740307c374e37936ffa86a0a489f Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Mon, 7 Nov 2022 20:22:52 +0900 Subject: [PATCH 443/822] =?UTF-8?q?=ED=9A=8C=EC=A0=84=20=ED=9A=8C=EC=98=A4?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\263\244_\354\273\244\353\270\214.java" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" diff --git "a/11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" "b/11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" new file mode 100644 index 0000000..635a6f9 --- /dev/null +++ "b/11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" @@ -0,0 +1,59 @@ +import java.io.*; +import java.util.*; + + +public class Main_15685_드래곤_커브 { + static int N; + static boolean[][] map = new boolean[101][101]; + static int[] dirX = {1, 0, -1, 0}; + static int[] dirY = {0, -1, 0, 1}; + // 0 우 1 : 상 2 : 좌 3 : 하 : 4 + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/15685.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int result = 0; + + N = Integer.parseInt(br.readLine()); + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); // 커브의 시작 점 x + int y = Integer.parseInt(st.nextToken()); // 커브의 시작 점 y + int d = Integer.parseInt(st.nextToken()); // 시작 방향 + int g = Integer.parseInt(st.nextToken()); // 세대 + + solution(x, y, d, g); + } + + for (int i = 0; i < 100; i++) { + for (int j = 0; j < 100; j++) { + if (map[i][j] && map[i][j + 1] && map[i + 1][j] && map[i + 1][j + 1]) { + result++; + } + } + } + + System.out.println(result); + } // End of main + + private static void solution(int x, int y, int d, int g) { + List list = new ArrayList<>(); + list.add(d); + + int size = list.size(); + for (int i = 1; i <= g; i++) { + for (int j = size - 1; j >= 0; j--) { + list.add((list.get(j) + 1) % 4); + } + } + + map[y][x] = true; + for (int i : list) { + x += dirX[i]; + y += dirY[i]; + map[y][x] = true; + } + + } // End of solution +} // End of Main class From feb036cb8fe298ad956a1a8776450d276fcceb03 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 7 Nov 2022 20:56:45 +0900 Subject: [PATCH 444/822] kihun --- .../pgm_lv2_\353\260\260\353\213\254.py" | 31 ++++++++++++++ ...30\352\263\244\354\273\244\353\270\214.py" | 42 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 "11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" create mode 100644 "11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" diff --git "a/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" "b/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" new file mode 100644 index 0000000..3030377 --- /dev/null +++ "b/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" @@ -0,0 +1,31 @@ +from collections import deque + + +def solution(N, road, K): + graph = [[0 for _ in range(N + 1)] for _ in range(N + 1)] + + for a, b, c in road: + if graph[a][b] == 0: + graph[a][b] = c + graph[b][a] = c + else: + graph[a][b] = min(graph[a][b], c) + graph[b][a] = min(graph[b][a], c) + + distance = [10 ** 9 for _ in range(N + 1)] + + distance[1] = 0 + q = deque() + q.append(1) + while q: + now = q.popleft() + for i in range(1, N + 1): + if graph[now][i] == 0: + continue + + if (distance[i] > distance[now] + graph[now][i] + and distance[now] + graph[now][i] <= K): + distance[i] = distance[now] + graph[now][i] + q.append(i) + + return len([x for x in distance if x <= K]) diff --git "a/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" "b/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" new file mode 100644 index 0000000..2ff0e74 --- /dev/null +++ "b/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" @@ -0,0 +1,42 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +dy = [0, -1, 0, 1] +dx = [1, 0, -1, 0] + +# 전 세대 + (전 세대 뒤집기+1), generation 만들기 +def makeGen(d, g): + generation = [d] + for _ in range(g): + temp = [] + for i in range(len(generation)): + temp.append((generation[-i -1] + 1) % 4) + generation += temp + return generation + +n = int(input()) +result = 0 +matrix = [[0] * 101 for _ in range(101)] + +for _ in range(n): + x, y, d, g = map(int, input().split()) + matrix[x][y] = 1 + + moveGen = makeGen(d, g) + + for move in moveGen: + nY = y + dy[move] + nX = x + dx[move] + matrix[nX][nY] = 1 + y, x = nY, nX + +for i in range(100): + for j in range(100): + if (matrix[i][j] == 1 + and matrix[i+1][j] == 1 + and matrix[i][j+1] == 1 + and matrix[i+1][j+1] == 1): + result += 1 + +print(result) From 7ae6aa7d75e1d6cc25957fc17770c1b49e9e2c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Tue, 8 Nov 2022 12:04:06 +0900 Subject: [PATCH 445/822] solve --- 11.10/readme.md | 7 + ...4\352\263\274 \354\227\260\354\202\260.kt" | 156 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 11.10/readme.md create mode 100644 "11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" diff --git a/11.10/readme.md b/11.10/readme.md new file mode 100644 index 0000000..6cea667 --- /dev/null +++ b/11.10/readme.md @@ -0,0 +1,7 @@ +# 11.07(월) 스터디 + +15685_드래곤_커브 +https://www.acmicpc.net/problem/15685 + +배달 +https://school.programmers.co.kr/learn/courses/30/lessons/12978 diff --git "a/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" "b/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" new file mode 100644 index 0000000..be0ae80 --- /dev/null +++ "b/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" @@ -0,0 +1,156 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.StringTokenizer +import kotlin.math.max + +lateinit var array: ArrayList> +var visited = IntArray(101) //숫자가 몇번 나오는지 체크 배열 + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + + var token = StringTokenizer(br.readLine()) + val r = token.nextToken().toInt() + val c = token.nextToken().toInt() + val k = token.nextToken().toInt() + + array = ArrayList(ArrayList()) + + repeat(3) { + token = StringTokenizer(br.readLine()) + val list = ArrayList() + list.add(token.nextToken().toInt()) + list.add(token.nextToken().toInt()) + list.add(token.nextToken().toInt()) + array.add(list) + } + + var count = 0 + + while (count <= 100) { + //array list 사이즈가 해당좌표를 포함하고 k일때 break + if (array.size >= r && array[0].size >= c && array[r - 1][c - 1] == k) break + count++ + + if (array.size >= array[0].size) { //행의 개수 >= 열의 개수 + array = operationR() + } else { //행의 개수 < 열의 개수 + array = operationC() + } + } + + if(count > 100) count = -1 + println(count) + +} + +fun operationR(): ArrayList> { + var tempArr = ArrayList>() + var changeArr : ArrayList + var maxRow = 0 + for (i in array.indices) { + visited = IntArray(101) //카운트 초기화 + var row = 0 //행의 길이 + changeArr = ArrayList() + + for (num in array[i]) { + visited[num]++ + } + + val countList = ArrayList>() + + for (j in 1 until visited.size) { + if (visited[j] >= 1 && countList.size <= 100) { + countList.add(Pair(j, visited[j])) + row += 2 + } + } + + maxRow = max(maxRow, row) //최대 행 길이 갱신 + + countList.sortWith(compareBy> { it.second }.thenBy { it.first }) //나온 횟수로 오름차순 정렬하고 같은 횟수면 나온 숫자로 오름차순 정렬 + + for (pair in countList) { + changeArr.add(pair.first) + changeArr.add(pair.second) + } + + tempArr.add(changeArr) + } + + val resultArr = Array(array.size){IntArray(maxRow)} //최대 열 길이만큼 배열 초기화 + + for (i in tempArr.indices){ + for (j in tempArr[i].indices){ + resultArr[i][j] = tempArr[i][j] + } + } + + tempArr = ArrayList() + + for (i in resultArr.indices){ + var tempList = ArrayList() + for (j in resultArr[i].indices){ + tempList.add(resultArr[i][j]) + } + tempArr.add(tempList) + } + + return tempArr +} + +fun operationC(): ArrayList> { + var tempArr = ArrayList>() + var changeArr : ArrayList + var maxCol = 0 + for (i in array[0].indices) { + visited = IntArray(101) //카운트 초기화 + var col = 0 //행의 길이 + changeArr = ArrayList() + + for (num in array) { + visited[num[i]]++ + } + + val countList = ArrayList>() + + for (j in 1 until visited.size) { + if (visited[j] >= 1 && countList.size <= 100) { + countList.add(Pair(j, visited[j])) + col += 2 + } + } + + maxCol = max(maxCol, col) //최대 열 길이 갱신 + + countList.sortWith(compareBy> { it.second }.thenBy { it.first }) //나온 횟수로 오름차순 정렬하고 같은 횟수면 나온 숫자로 오름차순 정렬 + + for (pair in countList) { + changeArr.add(pair.first) + changeArr.add(pair.second) + } + + tempArr.add(changeArr) + } + + val resultArr = Array(maxCol){IntArray(array[0].size)} //최대 열 길이만큼 배열 초기화 + + for (i in tempArr.indices){ + for (j in tempArr[i].indices){ + resultArr[j][i] = tempArr[i][j] + } + } + + tempArr = ArrayList() + + for (i in resultArr.indices){ + var tempList = ArrayList() + for (j in resultArr[i].indices){ + tempList.add(resultArr[i][j]) + } + tempArr.add(tempList) + } + + return tempArr +} \ No newline at end of file From 124b6e3901122c82b73891add2a992ce46cb310a Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Tue, 8 Nov 2022 12:06:00 +0900 Subject: [PATCH 446/822] Update readme.md --- 11.10/readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/11.10/readme.md b/11.10/readme.md index 6cea667..ee3a1b5 100644 --- a/11.10/readme.md +++ b/11.10/readme.md @@ -1,7 +1,7 @@ -# 11.07(월) 스터디 +# 11.10(목) 스터디 -15685_드래곤_커브 -https://www.acmicpc.net/problem/15685 +17140_이차원 배열과 연산 +https://www.acmicpc.net/problem/17140 -배달 -https://school.programmers.co.kr/learn/courses/30/lessons/12978 +멀쩡한 사각형 +https://school.programmers.co.kr/learn/courses/30/lessons/62048 From ac492e01b57bd54b37996149d2dc10a0ba092adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Tue, 8 Nov 2022 12:52:28 +0900 Subject: [PATCH 447/822] solve --- ...4 \354\202\254\352\260\201\355\230\225.kt" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" diff --git "a/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" "b/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" new file mode 100644 index 0000000..3bdfef8 --- /dev/null +++ "b/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" @@ -0,0 +1,35 @@ +package com.ssafy.algorithm + +fun main() { + val w = 8 + val h = 12 + println(Solution().solution(w, h)) +} + +class Solution { + var big = 0L + var small = 0L + fun solution(w: Int, h: Int): Long { + + if (w > h) { + big = w.toLong() + small = h.toLong() + } else { + big = h.toLong() + small = w.toLong() + } + + //전체 사각형의 개수 w * h - 대각선라인에 걸친 사각형의 수 (big + samll) - w,h의 최대공약수 + return big * small - (big + small - gcd(big, small)) + } + + fun gcd(big: Long, small: Long): Long { + if (small == 0.toLong()) { + return big + } else { + return gcd(small, big % small) + } + } +} + + From b8546683abdca6d9c04b7ca43a23135136ca329e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:07:00 +0900 Subject: [PATCH 448/822] =?UTF-8?q?Create=20=EB=A9=80=EC=A9=A1=ED=95=9C=20?= =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...234 \354\202\254\352\260\201\355\230\225.cpp" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" diff --git "a/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" "b/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" new file mode 100644 index 0000000..919a460 --- /dev/null +++ "b/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" @@ -0,0 +1,16 @@ +#include +using namespace std; + +int GCD(int a, int b) { + if (b < 1) { + return a; + } + return GCD(b, a%b); +} + +long long solution(int w, int h) { + long long answer = (long long)h*w; + int gcd = GCD(max(w, h), min(w, h)); + int minus = (h + w - gcd); + return answer - (long long)minus; +} From 8a097fa779ea78691072c07362c5eeded10833ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 8 Nov 2022 16:41:52 +0900 Subject: [PATCH 449/822] =?UTF-8?q?Create=2017140=5F=EC=9D=B4=EC=B0=A8?= =?UTF-8?q?=EC=9B=90=5F=EB=B0=B0=EC=97=B4=EA=B3=BC=5F=EC=97=B0=EC=82=B0.cp?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\263\274_\354\227\260\354\202\260.cpp" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" diff --git "a/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" "b/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" new file mode 100644 index 0000000..962136e --- /dev/null +++ "b/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" @@ -0,0 +1,79 @@ +#include +#include +#include +using namespace std; + +int main() { + int r, c, k; cin >> r >> c >> k; + r -= 1; c -= 1; + vector> board(100,vector(100)); + for (int i = 0; i < 3; i++) { + for (int k = 0; k < 3; k++) { + cin >> board[i][k]; + } + } + int answer = 0; + int h=3, w=3; + while (true) { + if (answer > 100) break; + if (r < h && c < w && board[r][c] == k) { + break; + } + answer++; + if (h >= w) { //행 정렬 + int nw = 0; + for (int i = 0; i < h; i++) { + int sum[101] = { 0 }; + for (int k = 0; k < w; k++) { + sum[board[i][k]]++; + board[i][k] = 0; + } + vector> sorted; + for (int k = 1; k < 101; k++) { + if (sum[k] > 0) { + sorted.push_back({ sum[k],k }); + } + } + int index = 0; + sort(sorted.begin(), sorted.end()); + for (auto s : sorted) { + board[i][index++] = s.second; + board[i][index++] = s.first; + } + nw = max(nw, index); + } + w = nw; + } + else { //열 정렬 + int nh = 0; + for (int i = 0; i < w; i++) { + int sum[101] = { 0 }; + for (int k = 0; k < h; k++) { + sum[board[k][i]]++; + board[k][i] = 0; + } + vector> sorted; + for (int k = 1; k < 101; k++) { + if (sum[k] > 0) { + sorted.push_back({ sum[k],k }); + } + } + int index = 0; + sort(sorted.begin(), sorted.end()); + for (auto s : sorted) { + board[index++][i] = s.second; + board[index++][i] = s.first; + } + nh = max(nh, index); + } + h = nh; + } + } + if (answer > 100) { + cout << -1 << endl; + } + else { + cout << answer << endl; + } + return 0; +} From 867b4c809c3d3536a2173f747456ce5ae65951cf Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 9 Nov 2022 00:48:30 +0900 Subject: [PATCH 450/822] =?UTF-8?q?Create=20=EB=B0=B0=EB=8B=AC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\260\353\213\254.java" | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 "11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" diff --git "a/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" "b/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" new file mode 100644 index 0000000..199b7d9 --- /dev/null +++ "b/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" @@ -0,0 +1,93 @@ +import java.util.*; + +public class 배달 { + static int N = 5; + static int[][] road = {{1, 2, 1}, {2,3,3}, {5,2,2}, {1,4,2}, {5,3,1}, {5,4,2}}; + static int K = 3; + static ArrayList> nodeList; + public static void main(String[] args){ + + 배달 m = new 배달(); + m.solution(N, road, K); + } + + void solution(int N, int[][] road, int K) { + int answer = 0; + + this.N = N; + this.road = road; + this.K = K; + + nodeList = new ArrayList<>(); + + for(int i=0; i<=N; i++) { + nodeList.add(new ArrayList<>()); + } + + int len = road.length; + for(int i=0; i pq = new PriorityQueue<>(); + boolean[] vis = new boolean[N+1]; + int dist[] = new int[N+1]; //노드간 최단거리가 들어갈 배열 + + Arrays.fill(dist, Integer.MAX_VALUE); + dist[startNum] = 0; + pq.add(new Node(startNum, 0)); + + while(!pq.isEmpty()) { + Node pollNode = pq.poll(); + + if(!vis[pollNode.nodeNum]) { + + vis[pollNode.nodeNum] = true; + + for(Node nextNode : nodeList.get(pollNode.nodeNum)) {//nodeList에 있는 노드 중 현재노드(pollNode)와의 가중치 체크 + if(!vis[nextNode.nodeNum] && dist[nextNode.nodeNum] > dist[pollNode.nodeNum] + nextNode.weight) { + dist[nextNode.nodeNum] = dist[pollNode.nodeNum] + nextNode.weight; + pq.add(new Node(nextNode.nodeNum, dist[nextNode.nodeNum])); + } + } + } + } + + return dist; + } + + static int checkResult(int[] dist) { + int result = 0; + for(int i=1; i<=N; i++) { + if(dist[i] <= K) { + result++; + } + } + + return result; + } + + static class Node implements Comparable{ + int nodeNum, weight; + + public Node(int nodeNum, int weight) { + this.nodeNum = nodeNum; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return weight - o.weight; + } + + } +} From 4c3b7dd849f63aae703f56cb4ce05689dded0ad6 Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:53:26 +0900 Subject: [PATCH 451/822] =?UTF-8?q?Create=20=EB=A9=80=EC=A9=A1=ED=95=9C=20?= =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95=5F=EC=8B=9C=EA=B0=84=EC=B4=88?= =?UTF-8?q?=EA=B3=BC.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5_\354\213\234\352\260\204\354\264\210\352\263\274.py" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" diff --git "a/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" "b/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" new file mode 100644 index 0000000..447002c --- /dev/null +++ "b/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" @@ -0,0 +1,8 @@ +# [넓이를 적분하는 방식] -> 시간초과 발생.(83점) +def solution(w,h): + answer = 0 + for i in range(1, w): + max_height = -1*(h/w)*i + h + height = int(max_height) + answer += height + return answer*2 From b5323075feca5bffe5302be86cde339b2ce6e339 Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:57:53 +0900 Subject: [PATCH 452/822] =?UTF-8?q?Create=20=EB=A9=80=EC=A9=A1=ED=95=9C=20?= =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95=5Fgcd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\225\234 \354\202\254\352\260\201\355\230\225_gcd" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" diff --git "a/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" "b/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" new file mode 100644 index 0000000..13c377a --- /dev/null +++ "b/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" @@ -0,0 +1,11 @@ +import math + +def gcd(a, b) : + while b>0: + a, b = b, a%b + return a + +def solution(w,h): + answer = w*h + gdc = gcd(w,h) #math.gcd(w,h) + return answer - (w+h-gdc) From 903521d0cb0a5295b60f1f5c4d3d0aaa3d3fca61 Mon Sep 17 00:00:00 2001 From: JI YOON LEE <50359789+jiy00nLee@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:58:55 +0900 Subject: [PATCH 453/822] =?UTF-8?q?Rename=20=EB=A9=80=EC=A9=A1=ED=95=9C=20?= =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95=5Fgcd=20to=20=EB=A9=80=EC=A9=A1?= =?UTF-8?q?=ED=95=9C=20=EC=82=AC=EA=B0=81=ED=98=95=5Fgcd.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" => "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" (100%) diff --git "a/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" "b/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" similarity index 100% rename from "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd" rename to "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" From d4f6284766c81f1e4c20786a3bce5ecc96013987 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 10 Nov 2022 00:40:58 +0900 Subject: [PATCH 454/822] =?UTF-8?q?Create=20=EC=9D=B4=EC=B0=A8=EC=9B=90?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=EA=B3=BC=EC=97=B0=EC=82=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\263\274\354\227\260\354\202\260.java" | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 "11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" diff --git "a/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" "b/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" new file mode 100644 index 0000000..ee45a65 --- /dev/null +++ "b/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" @@ -0,0 +1,215 @@ +import java.util.*; +import java.io.*; + +public class 이차원배열과연산_17140 { + + static int r, c, k, time, ans, R, C; + static int[][] arr; + static ArrayList list; + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + r = Integer.parseInt(st.nextToken()) - 1; + c = Integer.parseInt(st.nextToken()) - 1; + k = Integer.parseInt(st.nextToken()); + + arr = new int[100][100]; + list = new ArrayList<>(); + ans = -1; + time = 0; + R = 3; + C = 3; + + for (int i = 0; i < 3; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + while (time <= 100) { + checkRC(); + + if (checkResult()) { + ans = time; + break; + } + + if (R >= C) { + calR(); + } else { + calC(); + } + + time++; + + checkRC(); + } + + System.out.println(ans); + } + + static boolean checkResult() { + if (arr[r][c] == k) { + return true; + } else { + return false; + } + } + + static void checkRC() { + // 행 수 체크 + Loop1: for (int i = 0; i < 100; i++) { + int rTemp = 0; + for (int j = 0; j < 100; j++) { + if (arr[0][i] == 0) { + break Loop1; + } + if (arr[j][i] == 0) { + break; + } else if (arr[j][i] != 0) { + rTemp++; + R = Math.max(R, rTemp); + } + } + } + + // 열 수 체크 + Loop1: for (int i = 0; i < 100; i++) { + int cTemp = 0; + for (int j = 0; j < 100; j++) { + if (arr[i][0] == 0) { + break Loop1; + } + if (arr[i][j] == 0) { + break; + } else if (arr[i][j] != 0) { + cTemp++; + C = Math.max(C, cTemp); + } + } + } + } + + static void calR() { + for (int i = 0; i < R; i++) { + list.clear(); + for (int j = 0; j < C; j++) { + if (arr[i][j] != 0) { // list에 입력 + if (!checkListDuplicate(arr[i][j])) {// list에 arr[i][j]가 없으면 list에 넣어줌 + list.add(new Value(arr[i][j], 1)); + } else { // list에 이미 arr[i][j]가 있으면 등장 회수 증가 + for (int t = 0; t < list.size(); t++) { + if (list.get(t).value == arr[i][j]) { + list.get(t).times++; + } + } + } + } + } + // 수 오름차순으로 먼저 정렬하고 등장회수 오름차순으로 정렬 -> 등장회수 오름차순이 1순위 + list.sort(new Comparator() { + + @Override + public int compare(Value o1, Value o2) { + // TODO Auto-generated method stub + return o1.value - o2.value; + } + }); + list.sort(new Comparator() { + + @Override + public int compare(Value o1, Value o2) { + // TODO Auto-generated method stub + return o1.times - o2.times; + } + }); + + + // 배열 갱신 + int idx = 0; + int size = list.size(); + if(size > 100) size = 100; + for (int k = 0; k < size; k++) { + arr[i][idx++] = list.get(k).value; + arr[i][idx++] = list.get(k).times; + } + for(int k=idx; k<100; k++) { //뒤쪽 전부 0으로 만들어줌 + arr[i][k] = 0; + } + } + } + + static void calC() { + for (int i = 0; i < C; i++) { + list.clear(); + for (int j = 0; j < R; j++) { + if (arr[j][i] != 0) { // list에 입력 + if (!checkListDuplicate(arr[j][i])) {// list에 arr[j][i]가 없으면 list에 넣어줌 + list.add(new Value(arr[j][i], 1)); + } else { // list에 이미 arr[i][j]가 있으면 등장 회수 증가 + for (int t = 0; t < list.size(); t++) { + if (list.get(t).value == arr[j][i]) { + list.get(t).times++; + } + } + } + } + } + // 수 오름차순으로 먼저 정렬하고 등장회수 오름차순으로 정렬 -> 등장회수 오름차순이 1순위 + list.sort(new Comparator() { + + @Override + public int compare(Value o1, Value o2) { + // TODO Auto-generated method stub + return o1.value - o2.value; + } + }); + list.sort(new Comparator() { + + @Override + public int compare(Value o1, Value o2) { + // TODO Auto-generated method stub + return o1.times - o2.times; + } + }); + + // 배열 갱신 + int idx = 0; + int size = list.size(); + if(size > 100) size = 100; + for (int k = 0; k < size; k++) { + arr[idx++][i] = list.get(k).value; + arr[idx++][i] = list.get(k).times; + } + for(int k=idx; k<100; k++) { + arr[k][i] = 0; + } + } + } + + static boolean checkListDuplicate(int num) { + if (list.size() != 0) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i).value == num) { + return true; + } + } + return false; + } else { + return false; + } + } + + public static class Value { + int value, times; + + public Value(int value, int times) { + this.value = value; + this.times = times; + } + } +} From d410713604b6d81906e175015c527af75323e7c3 Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 10 Nov 2022 00:42:14 +0900 Subject: [PATCH 455/822] =?UTF-8?q?Create=20=EB=A9=80=EC=A9=A1=ED=95=9C?= =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\254\352\260\201\355\230\225.java" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" diff --git "a/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" "b/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" new file mode 100644 index 0000000..50de5ce --- /dev/null +++ "b/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" @@ -0,0 +1,28 @@ +import java.util.*; + +public class 멀쩡한사각형 { + + public static void main(String[] args) { + System.out.println(solution(8, 12)); + } + + public static long solution(int w, int h) { + long answer = 1; + + long tmp = Math.max(w, h); + long tmp2 = Math.min(w, h); + + w = (int) tmp2; + h = (int) tmp; + answer = w * h - (w + h - getGCD(h, w)); + + return answer; + } + + static int getGCD(int x, int y) { + if (x % y == 0) + return y; + + return getGCD(y, x % y); + } +} From 15da0e80f360bf4cbf210dfbdb6a8edbd7fade5e Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 10 Nov 2022 00:51:59 +0900 Subject: [PATCH 456/822] =?UTF-8?q?Update=20=EC=9D=B4=EC=B0=A8=EC=9B=90?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=EA=B3=BC=EC=97=B0=EC=82=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\260\354\227\264\352\263\274\354\227\260\354\202\260.java" | 2 -- 1 file changed, 2 deletions(-) diff --git "a/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" "b/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" index ee45a65..721bb96 100644 --- "a/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" +++ "b/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" @@ -45,8 +45,6 @@ public static void main(String[] args) throws IOException { } time++; - - checkRC(); } System.out.println(ans); From 0f14e6a0213f18ce469aefefa2c672f46ae9f0ac Mon Sep 17 00:00:00 2001 From: hojoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 10 Nov 2022 09:26:51 +0900 Subject: [PATCH 457/822] =?UTF-8?q?Update=20=EC=9D=B4=EC=B0=A8=EC=9B=90?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=EA=B3=BC=EC=97=B0=EC=82=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\260\354\227\264\352\263\274\354\227\260\354\202\260.java" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" "b/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" index 721bb96..7e37340 100644 --- "a/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" +++ "b/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" @@ -135,7 +135,7 @@ public int compare(Value o1, Value o2) { arr[i][idx++] = list.get(k).value; arr[i][idx++] = list.get(k).times; } - for(int k=idx; k<100; k++) { //뒤쪽 전부 0으로 만들어줌 + for(int k=idx; k Date: Thu, 10 Nov 2022 11:15:36 +0900 Subject: [PATCH 458/822] =?UTF-8?q?=EC=9C=A0=ED=81=B4=EB=A6=AC=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\254\352\260\201\355\230\225.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" diff --git "a/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" "b/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" new file mode 100644 index 0000000..0b1c49d --- /dev/null +++ "b/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" @@ -0,0 +1,40 @@ +import java.util.*; + +// w, h가 공약수가 있다면 문제를 공약수를 나눈 w' 과 h'으로 축소시킬 수 있다. +// w'과 h'이 서로소라 가정했을 때 대각선은 반대쪽 코너에 도달하기 전 w'-1 세로선과 h'-1 가로선을 지나고 +// 지날 때 마다 새로운 정사각형이 추가됩니다. +// 그래서 첫 정사각형을 포함 1 + (w'-1) + (h'-1) = w' + h' - 1개의 정사각형을 지나게 되므로, +// 공약수를 다시 곱해주면 w + h - gcd(w, h)개의 정사각형을 지나는 것을 찾을 수 있다. + +public class Main_PRG_멀쩡한_사각형 { + public static void main(String[] args) throws Exception { + Main_PRG_멀쩡한_사각형 m = new Main_PRG_멀쩡한_사각형(); + + int w = 8; + int h = 12; + + System.out.println(m.solution(w, h)); + } // End of main + + public static long solution(int w, int h) { + int gcd = 0; + if (w < h) { + gcd = GCD(h, w); + } else { + gcd = GCD(w, h); + } + + long total = (long) w * h; + return total - (w + h - gcd); + } // End of solution + + // 유클리드 호제법 + private static int GCD(int x, int y) { + if (y == 0) { + return x; + } + + return GCD(y, x % y); + } // End of GCD + +} // End of Main class From 3366c1eb6ce55d56a4e73c8d47429a30ce5e1a62 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Thu, 10 Nov 2022 20:54:24 +0900 Subject: [PATCH 459/822] complete --- ...352\263\244_\354\273\244\353\270\214.java" | 59 ----- ...352\263\274_\354\227\260\354\202\260.java" | 216 ++++++++++++++++++ 2 files changed, 216 insertions(+), 59 deletions(-) delete mode 100644 "11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" create mode 100644 "11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" diff --git "a/11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" "b/11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" deleted file mode 100644 index 635a6f9..0000000 --- "a/11.07/\354\265\234\354\260\275\354\230\201/Main_15685_\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" +++ /dev/null @@ -1,59 +0,0 @@ -import java.io.*; -import java.util.*; - - -public class Main_15685_드래곤_커브 { - static int N; - static boolean[][] map = new boolean[101][101]; - static int[] dirX = {1, 0, -1, 0}; - static int[] dirY = {0, -1, 0, 1}; - // 0 우 1 : 상 2 : 좌 3 : 하 : 4 - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/15685.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st; - int result = 0; - - N = Integer.parseInt(br.readLine()); - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - int x = Integer.parseInt(st.nextToken()); // 커브의 시작 점 x - int y = Integer.parseInt(st.nextToken()); // 커브의 시작 점 y - int d = Integer.parseInt(st.nextToken()); // 시작 방향 - int g = Integer.parseInt(st.nextToken()); // 세대 - - solution(x, y, d, g); - } - - for (int i = 0; i < 100; i++) { - for (int j = 0; j < 100; j++) { - if (map[i][j] && map[i][j + 1] && map[i + 1][j] && map[i + 1][j + 1]) { - result++; - } - } - } - - System.out.println(result); - } // End of main - - private static void solution(int x, int y, int d, int g) { - List list = new ArrayList<>(); - list.add(d); - - int size = list.size(); - for (int i = 1; i <= g; i++) { - for (int j = size - 1; j >= 0; j--) { - list.add((list.get(j) + 1) % 4); - } - } - - map[y][x] = true; - for (int i : list) { - x += dirX[i]; - y += dirY[i]; - map[y][x] = true; - } - - } // End of solution -} // End of Main class diff --git "a/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" "b/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" new file mode 100644 index 0000000..e7ae477 --- /dev/null +++ "b/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" @@ -0,0 +1,216 @@ +import java.io.*; +import java.util.*; + +public class Main_17140_이차원_배열과_연산 { + private static final int N = 101; + static int R, C, K, xLen, yLen; + static int[][] map = new int[N][N]; + static int[][] tempMap; + + static class Coordinates { + int x; + int y; + + public Coordinates(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Coordinates class + + static class Number implements Comparable { + int num; + int freq; + + public Number(int num, int freq) { + this.num = num; + this.freq = freq; + } + + @Override + public int compareTo(Number o) { + + if (freq > o.freq) { + return 1; + } else if (freq == o.freq) { + return num - o.num; + } else { + return -1; + } + } + } // End of Number class + + // 100초가 지나도 A[r][c] = k가 되지 않으면 -1을 출력한다. + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/17140.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + xLen = 3; + yLen = 3; + + for (int i = 0; i < 3; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + System.out.println(solution()); + } // End of main + + // 행 또는 열의 크기가 커진 곳에는 0이 채워진다. 수를 정렬할 때 0은 무시해야 한다 + // 행과 열의 위치를 파악할 때는 0,0을 1,1로 해야된다. + // 0이 아닌 것의 개수 + private static int solution() { + + for (int t = 0; t < 101; t++) { + if (map[R - 1][C - 1] == K) { + // 가장 먼저 해당 위치에 K값이 일치하는지 체크. + // 일치한다면 곧 바로 t를 return + return t; + } + + // 행과 열의 수를 알아내기. + Coordinates cor = rowLine_ColumnLine_Check(); + + // 행과 열의 수에 따른 정렬 실행 + if (cor.x <= cor.y) { + // R연산 (행을 기준으로 정렬) + calcR(); + } else { + // C연산 (열을 기준으로 정렬) + calcC(); + } + } + + return -1; + } + + // 행,열 수 체크 + private static Coordinates rowLine_ColumnLine_Check() { + // 가장 큰 행을 기준으로 모든 행의 크기가 변하고, + // 가장 큰 열을 기준으로 모든 열의 크기가 변한다. + + int maxRow = -1; + int maxCol = -1; + for (int i = 0; i < N; i++) { + int rowLen = 0; + int colLen = 0; + for (int j = 0; j < N; j++) { + if (map[i][j] != 0) { + rowLen++; + } + + if (map[j][i] != 0) { + colLen++; + } + } + + maxRow = Math.max(maxRow, rowLen); + maxCol = Math.max(maxCol, colLen); + } + + return new Coordinates(maxRow, maxCol); + } // End of rowLine_ColumnLine_Check + + // R연산 (행을 기준으로 정렬) + private static void calcR() { + tempMap = new int[N][N]; + int maxCol = -1; + + for (int i = 0; i < N; i++) { + HashMap rowHashMap = new HashMap<>(); + PriorityQueue pque = new PriorityQueue<>(); + + for (int j = 0; j < N; j++) { + int num = map[i][j]; + if (num == 0) continue; + + rowHashMap.put(num, rowHashMap.getOrDefault(num, 0) + 1); + } + + // 횟수가 적은 순으로 나열 해야됨. + // key값을 기준으로 정렬. + Iterator> iter = rowHashMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entrySet = iter.next(); + int key = entrySet.getKey(); + int value = entrySet.getValue(); + + pque.offer(new Number(key, value)); + } + + int index = -1; + while (!pque.isEmpty()) { + Number num = pque.poll(); + + tempMap[i][++index] = num.num; + if (index >= 100) break; + + tempMap[i][++index] = num.freq; + if (index >= 100) break; + } + + + maxCol = Math.max(index, maxCol); + } + + copy(); + } // End of calcR + + // C연산 (열을 기준으로 정렬) + private static void calcC() { + tempMap = new int[N][N]; + int maxRow = -1; + + for (int i = 0; i < N; i++) { + HashMap colHashMap = new HashMap<>(); + PriorityQueue pque = new PriorityQueue<>(); + + for (int j = 0; j < N; j++) { + int num = map[j][i]; + if (num == 0) continue; + + colHashMap.put(num, colHashMap.getOrDefault(num, 0) + 1); + } + + // 횟수가 적은 순으로 나열 해야됨. + // key값을 기준으로 정렬. + Iterator> iter = colHashMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entrySet = (Map.Entry) iter.next(); + int key = entrySet.getKey(); + int value = entrySet.getValue(); + + pque.offer(new Number(key, value)); + } + + int index = -1; + while (!pque.isEmpty()) { + Number num = pque.poll(); + + tempMap[++index][i] = num.num; + if (index >= 100) break; + tempMap[++index][i] = num.freq; + if (index >= 100) break; + } + + + maxRow = Math.max(index, maxRow); + } + + copy(); + } // End of calcC + + private static void copy() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + map[i][j] = tempMap[i][j]; + } + } + } // End of copy +} // End of Main class \ No newline at end of file From d1ab34629c3dd127fc9a0f653cd1ee271d0a1bf6 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 10 Nov 2022 21:00:50 +0900 Subject: [PATCH 460/822] kihun --- ...4_\354\202\254\352\260\201\355\230\225.py" | 22 ++++ ...64\352\263\274\354\227\260\354\202\260.py" | 111 ++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 "11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" create mode 100644 "11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" diff --git "a/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" "b/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" new file mode 100644 index 0000000..f257d9b --- /dev/null +++ "b/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" @@ -0,0 +1,22 @@ +def gcd(w, h): + a, b = w, h + while (True): + remainder = a % b + if remainder == 0: + return b + else: + a, b = b, remainder + +def solution(w,h): + answer = w * h - (w+h-gcd(w, h)) + return answer + +# 시간초과 +# import math + +# def solution(w,h): +# answer = 0 +# for i in range(1, w): +# cutHeight = math.ceil(h / w * i) +# answer += (h - cutHeight) +# return answer * 2 \ No newline at end of file diff --git "a/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" "b/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" new file mode 100644 index 0000000..b89069d --- /dev/null +++ "b/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" @@ -0,0 +1,111 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + + +def check(matrix): + y = len(matrix) + x = len(matrix[0]) + + if y < r or x < c: + return False + if matrix[r - 1][c - 1] == k: + return True + return False + + +def calculateR(matrix): + sortedDicts = [] + for i in range(len(matrix)): + numDict = dict() + rowList = matrix[i] + for num in rowList: + if num == 0: + continue + if num not in numDict: + numDict[num] = 1 + else: + numDict[num] += 1 + sortedDict = sorted(numDict.items(), key=lambda item: [item[1], item[0]]) + sortedDicts.append(sortedDict) + maxLength = max(map(len, sortedDicts)) * 2 + if maxLength > 100: + maxLength = 100 + result = [[0 for _ in range(maxLength)] for _ in range(len(sortedDicts))] + + y = 0 + for sortedDict in sortedDicts: + x = 0 + for element in sortedDict: + result[y][x] = element[0] + result[y][x + 1] = element[1] + x += 2 + if x == 100: + break + y += 1 + if y == 100: + break + + return result + + +def calculateC(matrix): + sortedDicts = [] + for x in range(len(matrix[0])): + numDict = dict() + columnList = [] + for y in range(len(matrix)): + columnList.append(matrix[y][x]) + for num in columnList: + if num == 0: + continue + if num not in numDict: + numDict[num] = 1 + else: + numDict[num] += 1 + sortedDict = sorted(numDict.items(), key=lambda item: [item[1], item[0]]) + sortedDicts.append(sortedDict) + maxLength = max(map(len, sortedDicts)) * 2 + if maxLength > 100: + maxLength = 100 + result = [[0 for _ in range(len(sortedDicts))] for _ in range(maxLength)] + + x = 0 + for sortedDict in sortedDicts: + y = 0 + for element in sortedDict: + result[y][x] = element[0] + result[y + 1][x] = element[1] + y += 2 + if y == 100: + break + x += 1 + if x == 100: + break + + return result + + +def solution(r, c, k, A): + t = 0 + + while t <= 100: + if check(A): + return t + + nowR = len(A) + nowC = len(A[0]) + + if nowR >= nowC: + A = calculateR(A) + else: + A = calculateC(A) + t += 1 + + return -1 + + +r, c, k = map(int, input().split()) +A = [list(map(int, input().split())) for _ in range(3)] + +print(solution(r, c, k, A)) From 02f265def149fad2b0d20f1ec3114201bd0d83db Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 10 Nov 2022 22:40:59 +0900 Subject: [PATCH 461/822] solve --- 11.14/readme.md | 7 ++ .../Puyo Puyo.kt" | 99 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 11.14/readme.md create mode 100644 "11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" diff --git a/11.14/readme.md b/11.14/readme.md new file mode 100644 index 0000000..ee3a1b5 --- /dev/null +++ b/11.14/readme.md @@ -0,0 +1,7 @@ +# 11.10(목) 스터디 + +17140_이차원 배열과 연산 +https://www.acmicpc.net/problem/17140 + +멀쩡한 사각형 +https://school.programmers.co.kr/learn/courses/30/lessons/62048 diff --git "a/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" "b/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" new file mode 100644 index 0000000..90cd3d9 --- /dev/null +++ "b/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" @@ -0,0 +1,99 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.* +import kotlin.collections.ArrayList + +data class Point(val r: Int, val c: Int) + +lateinit var field: Array //필드 +val direction = arrayOf(intArrayOf(-1, 0), intArrayOf(1, 0), intArrayOf(0, -1), intArrayOf(0, 1)) +lateinit var visited: Array + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + + field = Array(12) { CharArray(6) } + + repeat(12) { r -> + val rowInfo = br.readLine() + rowInfo.forEachIndexed { c, info -> + field[r][c] = info + } + } + + var combo = 0 + while (true) { + var isPop = false + for (i in field.indices) { + for (j in field[i].indices) { + var check = false + if (field[i][j] != '.') { + visited = Array(12) { BooleanArray(6) } + check = pop(i, j, field[i][j]) + } + if (check) isPop = true + } + } + + if (isPop) { //연쇄작용이 터지면 + combo++ + shiftDown() + } else break + } + println(combo) +} + +fun pop(startR: Int, startC: Int, target: Char): Boolean { + var queue: Queue = LinkedList() + val pointList = ArrayList() //터질 때의 점들의 좌표 + queue.offer(Point(startR, startC)) + visited[startR][startC] = true + var count = 1 + + while (queue.isNotEmpty()) { + val point = queue.poll() + + for (i in direction.indices) { + val r = point.r + direction[i][0] + val c = point.c + direction[i][1] + + if (r in 0..11 && c in 0..5 && !visited[r][c] && field[r][c] == target) { + visited[r][c] = true + queue.add(Point(r, c)) + pointList.add(Point(r, c)) + count++ + } + } + } + if (count >= 4) { //연쇄작용이 일어나면 초기좌표와 리스트에 좌표 .으로 갱신 + field[startR][startC] = '.' + for (point in pointList) { + field[point.r][point.c] = '.' + } + return true + } + return false +} + +fun shiftDown() { + repeat(6) { c -> + val shiftList = Stack() + repeat(12) { r -> + if (field[r][c] != '.') { + shiftList.push(field[r][c]) + field[r][c] = '.' + } + } + var row = 11 + + while (shiftList.isNotEmpty()) { //제일 밑에 행부터 채워주기 + field[row][c] = shiftList.pop() + row-- + } + } +} + + + + From 22ff2a0330f1f7d629b996023bfabb5ca7ebb4cf Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Thu, 10 Nov 2022 22:42:55 +0900 Subject: [PATCH 462/822] Update readme.md --- 11.14/readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/11.14/readme.md b/11.14/readme.md index ee3a1b5..b88b063 100644 --- a/11.14/readme.md +++ b/11.14/readme.md @@ -1,7 +1,7 @@ -# 11.10(목) 스터디 +# 11.14(월) 스터디 -17140_이차원 배열과 연산 -https://www.acmicpc.net/problem/17140 +11559_Puyo Puyo +https://www.acmicpc.net/problem/11559 -멀쩡한 사각형 -https://school.programmers.co.kr/learn/courses/30/lessons/62048 +다리를 지나는 트럭 +https://school.programmers.co.kr/learn/courses/30/lessons/42583 From 5e7655d1d59a9800003a12825ad1bcd0557f4447 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 10 Nov 2022 22:42:51 +0900 Subject: [PATCH 463/822] solve --- ...0\353\212\224 \355\212\270\353\237\255.kt" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" diff --git "a/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" "b/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" new file mode 100644 index 0000000..7870e67 --- /dev/null +++ "b/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" @@ -0,0 +1,65 @@ +package com.ssafy.algorithm + + +import java.util.* +import kotlin.collections.ArrayList + +fun main() { + val sl = Solution() + val bridge_length = 100 + val weight = 100 + val truck_weights = intArrayOf(10,10,10,10,10,10,10,10,10,10) + println(sl.solution(bridge_length, weight, truck_weights)) + +} + +class Solution { + lateinit var cross: BooleanArray //현재 트럭이 다리에 있는지 체크 배열 + fun solution(bridge_length: Int, weight: Int, truck_weights: IntArray): Int { + var answer = 0 + val wait: Queue = LinkedList() + val bridge: Queue = LinkedList() + + for (i in truck_weights){ //대기 트럭 + wait.offer(i) + } + + var possible = 0 + var time = 0 //시간 + + cross = BooleanArray(truck_weights.size) + val trucks = IntArray(truck_weights.size) + var index = 0 + while (true) { + time++ + if (wait.isEmpty() && bridge.isEmpty()) break //대기 트럭이랑 다리에 트럭 큐가 비어있으면 종료 + + if (wait.isNotEmpty()){ //대기트럭이 있을 때 + if (possible + wait.peek() <= weight) { //현재 다리위에 있는 트럭 + 트럭의 무게가 다리가 버틸 수 있는 무게라면 트럭추가 + val truckWeight = wait.poll() + possible += truckWeight + bridge.offer(truckWeight) + cross[index] = true + index++ + } + } + + + + for (i in cross.indices){ + if (cross[i]){ //다리위에 있는 트럭의 인덱스 + trucks[i]++ + if (trucks[i] >= bridge_length && cross[i]){ //다리를 지난경우 + cross[i] = false + possible -= bridge.poll() //다리가 버틸 수 있는 무게 증가 + } + } + + + } + } + + return time + } +} + From 40d681664ccc08561302255a7e06c296a76d9d42 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 13 Nov 2022 00:33:17 +0900 Subject: [PATCH 464/822] =?UTF-8?q?=EB=BF=8C=EC=9A=94=EB=BF=8C=EC=9A=94=20?= =?UTF-8?q?complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main_11559_Puyo_Puyo.java" | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 "11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" diff --git "a/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" "b/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" new file mode 100644 index 0000000..6623362 --- /dev/null +++ "b/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" @@ -0,0 +1,162 @@ +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/11559 +// 상대방의 필드가 주어졌을 때, 연쇄가 몇 번 연속으로 일어날지 계산 +// 포인트 -> 터질 수 있는 뿌요가 여러 그룹이 있다면 동시에 터져야 하고 여러 그룹이 터지더라도 한번의 연쇄가 추가된다. + +public class Main_11559_Puyo_Puyo { + private static final int N = 12; + private static final int M = 6; + static char[][] map = new char[N][M]; + static char[][] tempMap; + static boolean[][] isVisited; + + static int[] dirX = {-1, 1, 0, 0}; + static int[] dirY = {0, 0, -1, 1}; + static List popColorCoorList; + + static class Coordinates { + int x; + int y; + int count; + + public Coordinates(int x, int y, int count) { + this.x = x; + this.y = y; + this.count = count; + } + + public Coordinates(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Coordinates + + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/11559.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + popColorCoorList = new ArrayList<>(); + + for (int i = 0; i < N; i++) { + String temp = br.readLine(); + for (int j = 0; j < M; j++) { + map[i][j] = temp.charAt(j); + } + } + + int result = 0; // 최종 결과값 + for (; ; ) { + // 터트릴 수 있는 것들을 한번에 터트려야 하므로, 터지는 곳의 좌표를 모두 저장. + popColorCoorList = new ArrayList<>(); + isVisited = new boolean[N][M]; + + for (int i = N - 1; i >= 0; i--) { + for (int j = 0; j < M; j++) { + if (map[i][j] != '.' && !isVisited[i][j]) { + findColor(i, j, map[i][j]); + } + } + } + + // list에 들어가있는 블럭들을 터트리는 작업 진행 + if (popColorCoorList.isEmpty()) { + break; + } else { + result++; + popColor(); // 색깔 터트리기 + gravityApplication(); // 중력으로 아래로 당기기 + copy(); // 다시 배열 복사해주기. + } + } + + System.out.print(result); + } // End of main + + // 1. 현재 주어진 상황에서 어떤 색깔이 터질 수 있는지를 체크, + // 2. 터지고 나면 뿌요들을 내리는 작업을 시작. (내릴 때는 열을 기준으로 내린다.) -> 배열 복사 + private static boolean findColor(int x, int y, char color) { + Queue que = new LinkedList<>(); + List tempList = new ArrayList<>(); + + que.offer(new Coordinates(x, y, 0)); + tempList.add(new Coordinates(x, y)); + isVisited[x][y] = true; + + int totalCount = 1; + while (!que.isEmpty()) { + Coordinates pollCoor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = dirX[i] + pollCoor.x; + int nowY = dirY[i] + pollCoor.y; + int nowCount = pollCoor.count; + + if (!rangeCheck(nowX, nowY) || isVisited[nowX][nowY] || map[nowX][nowY] != color) continue; + + que.offer(new Coordinates(nowX, nowY, ++nowCount)); + tempList.add(new Coordinates(nowX, nowY)); + isVisited[nowX][nowY] = true; + totalCount++; + } + } + + if (totalCount >= 4) { + // tempList에 저장해뒀다가 전체 터트릴 수 있는 색깔의 블럭이 4개이상일 경우에만 list에 저장함. + for (Coordinates coor : tempList) { + popColorCoorList.add(new Coordinates(coor.x, coor.y)); + } + + return true; + } + + return false; + } // End of findColor + + private static void popColor() { + // 터트릴 수 있는 색깔들 터트리고 .으로 변경 + + for (Coordinates coor : popColorCoorList) { + map[coor.x][coor.y] = '.'; + } + } // End of popColor + + private static void gravityApplication() { + tempMap = new char[N][M]; + + for (int i = 0; i < M; i++) { + // 빈 공간이 있을 경우, 밑으로 내려줌 + Deque deque = new LinkedList<>(); + for (int j = N - 1; j >= 0; j--) { + + if (map[j][i] != '.') { + deque.offerFirst(map[j][i]); + } + } + + int index = N - 1; + while (!deque.isEmpty()) { + char ch = deque.pollLast(); + tempMap[index--][i] = ch; + } + + for (int j = index; j >= 0; j--) { + tempMap[j][i] = '.'; + } + } + + } // End of gravityApplication + + private static void copy() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + map[i][j] = tempMap[i][j]; + } + } + } // End of copy + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of rangeCheck +} // End of Main class From 0f860692a214ad9739231c203654553871bb90dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:23:35 +0900 Subject: [PATCH 465/822] =?UTF-8?q?Create=2011559=5F=EB=BF=8C=EC=9A=94?= =?UTF-8?q?=EB=BF=8C=EC=9A=94.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\232\224\353\277\214\354\232\224.cpp" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" diff --git "a/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" "b/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" new file mode 100644 index 0000000..6bd41b1 --- /dev/null +++ "b/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" @@ -0,0 +1,94 @@ +#include +#include +#include +using namespace std; +int N = 12, M = 6; + +vector> list; +vector board(12); +vector> visited(12, vector(6, false)); +bool check(int y, int x) { + if (0 <= y && y < N && 0 <= x && x < M) { + return true; + } + return false; +} +int dy[] = { 0,1,0,-1 }; +int dx[] = { 1,0,-1,0 }; + +int checkCnt(int y, int x, char c, int cnt) { + visited[y][x] = true; + for (int i = 0; i < 4; i++) { + int yy = y + dy[i]; + int xx = x + dx[i]; + if (check(yy, xx)) { + if (board[yy][xx] == c && !visited[yy][xx]) { + visited[yy][xx] = true; + cnt = checkCnt(yy,xx,c, cnt + 1); + } + } + } + return cnt; +} + +vector> visited2(12, vector(6, false)); +void convert(int y, int x, char c) { + visited2[y][x] = true; + board[y][x] = '.'; + list.push_back({ y,x }); + for (int i = 0; i < 4; i++) { + int yy = y + dy[i]; + int xx = x + dx[i]; + if (check(yy, xx)) { + if (board[yy][xx] == c && !visited2[yy][xx]) { + visited2[yy][xx] = true; + board[yy][xx] = '.'; + convert(yy, xx, c); + } + } + } +} + +void down(int y, int x) { + while (board[y][x] == '.' && check(y-1,x) && board[y-1][x] != '.'){ + char c = board[y - 1][x]; + board[y - 1][x] = '.'; + int xx = x, yy = y; + while (check(yy, xx) && board[yy][xx] == '.') { + yy++; + } + board[yy - 1][x] = c; + y -= 1; + } +} + +int main() { + for (int i = 0; i < N; i++) { + cin >> board[i]; + } + int answer = 0; + while(true) { + list.clear(); + visited = vector>(12, vector(6, false)); + for (int i = 0; i < N; i++) { + for (int k = 0; k < M; k++) { + if (board[i][k] != '.' && !visited[i][k]) { + int cnt = checkCnt(i, k, board[i][k], 1); + if (cnt >= 4) { + visited2 = vector>(12, vector(6, false)); + convert(i, k, board[i][k]); + } + } + } + } + if (list.empty()) { + break; + } + answer++; + for (pair d : list) { + down(d.first, d.second); + } + } + cout << answer << "\n"; + return 0; +} From 6f2d15eba88fe907bac9b8050b1f607550b40d2c Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 14 Nov 2022 01:12:03 +0900 Subject: [PATCH 466/822] =?UTF-8?q?Create=20=EB=BF=8C=EC=9A=94=EB=BF=8C?= =?UTF-8?q?=EC=9A=94.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\232\224\353\277\214\354\232\224.java" | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" diff --git "a/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" "b/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" new file mode 100644 index 0000000..c99313e --- /dev/null +++ "b/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" @@ -0,0 +1,112 @@ +import java.util.*; +import java.io.*; + +public class PuyoPuyo_11559 { + static int[] dx = { 0, 0, -1, 1 }; + static int[] dy = { -1, 1, 0, 0 }; + static char[][] board; + static boolean[][] vis; + static ArrayList group; + static int ans; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + board = new char[12][6]; + vis = new boolean[12][6]; + group = new ArrayList<>(); + ans = 0; + + for (int i = 0; i < 12; i++) { + String str = br.readLine(); + for (int j = 0; j < 6; j++) { + board[i][j] = str.charAt(j); + } + } + + while (checkStart()); + System.out.println(ans); + + } + + static boolean checkStart() { + boolean result = false; + for (int i = 0; i < 12; i++) { + for (int j = 0; j < 6; j++) { + if (board[i][j] != '.' && !vis[i][j]) { + group.clear(); + vis = new boolean[12][6]; + if (findGroup(i, j)) { + result = true; + } + } + } + } + if(result) { + move(); + } + return result; + } + + static boolean findGroup(int r, int c) { + Queue q = new LinkedList<>(); + q.add(new Point(r, c)); + vis[r][c] = true; + char value = board[r][c]; + while (!q.isEmpty()) { + Point temp = q.poll(); + group.add(new Point(temp.r, temp.c)); + for (int i = 0; i < 4; i++) { + int nextR = temp.r + dy[i]; + int nextC = temp.c + dx[i]; + if (0 <= nextR && nextR < 12 && 0 <= nextC && nextC < 6 && !vis[nextR][nextC] + && board[nextR][nextC] == value) { + q.add(new Point(nextR, nextC)); + vis[nextR][nextC] = true; + } + } + } + if (group.size() >= 4) { + for (int i = 0; i < group.size(); i++) { + board[group.get(i).r][group.get(i).c] = '.'; + } + + return true; + } else { + + return false; + } + + } + + static void move() { + ans++; + + for (int j = 0; j < 6; j++) { + Point start = new Point(-1, -1); + for (int i = 11; i >= 1; i--) { + if (board[i][j] == '.' && start.r == -1) { + start.r = i; + start.c = j; + } + if (board[i][j] == '.' && board[i - 1][j] != '.' && start.r != -1) { + board[start.r][start.c] = board[i - 1][j]; + board[i - 1][j] = '.'; + i = start.r; + start.r = -1; + start.c = -1; + } + } + } + } + + public static class Point { + int r, c; + char value; + + Point(int r, int c) { + this.r = r; + this.c = c; + } + } +} From 0170ad14ef6b2694d8abd52d940b0d398488e577 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:43:28 +0900 Subject: [PATCH 467/822] =?UTF-8?q?Create=20=EB=8B=A4=EB=A6=AC=EB=A5=BC?= =?UTF-8?q?=EC=A7=80=EB=82=98=EB=8A=94=ED=8A=B8=EB=9F=AD.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\212\224\355\212\270\353\237\255.java" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" diff --git "a/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" "b/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" new file mode 100644 index 0000000..abf29fe --- /dev/null +++ "b/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" @@ -0,0 +1,66 @@ +import java.util.*; + +public class 다리를지나는트럭 { + + public static void main(String[] args) { + + int bridge_length = 100; + int weight = 100; + int[] truck_weights = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}; + Solution s = new Solution(); + s.solution(bridge_length, weight, truck_weights); + + } + + public static class Solution { + + public int solution(int bridge_length, int weight, int[] truck_weights) { + + int answer = Integer.MAX_VALUE; + ArrayList truck = new ArrayList<>(); + ArrayList curTruck = new ArrayList<>(); + + for(int i=0; i Date: Mon, 14 Nov 2022 16:26:19 +0900 Subject: [PATCH 468/822] =?UTF-8?q?=EB=8B=A4=EB=A6=AC=20=EB=B6=80=EC=88=B4?= =?UTF-8?q?=EB=B2=84=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\212\224_\355\212\270\353\237\255.java" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" diff --git "a/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" "b/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" new file mode 100644 index 0000000..094ff56 --- /dev/null +++ "b/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" @@ -0,0 +1,77 @@ +import java.util.*; + +public class Main_PRG_다리를_지나는_트럭 { + static int weightLimit, bridge_length; + + static class Car { + int weight; + int time; + + public Car(int weight, int time) { + this.weight = weight; + this.time = time; + } + } // End of Car class + + public static void main(String[] args) { + Main_PRG_다리를_지나는_트럭 m = new Main_PRG_다리를_지나는_트럭(); + + int bridge_length = 100; + int weight = 100; + int[] truck_weights = {10,10,10,10,10,10,10,10,10,10}; + + System.out.println(m.solution(bridge_length, weight, truck_weights)); + } // End of main + + private int solution(int bridge_length, int weight, int[] truck_weights) { + weightLimit = weight; + this.bridge_length = bridge_length; + Queue bridgeQue = new LinkedList<>(); + int index = 0; + int time = 1; + for (; ; ) { + + if (index < truck_weights.length && nowBridgeWeightCheck(bridgeQue, truck_weights[index])) { + // 들어갈 수 있는 자리가 있으면 한번에 모두 들어감. + bridgeQue.offer(new Car(truck_weights[index], 0)); + index++; + } + + + //for (Car c : bridgeQue) System.out.println(c.weight + ", " + c.time); + //System.out.println("time : " + time); + + // 다리에 있는 차량들 전체 적으로 시간 증가. + increaseTime(bridgeQue); + if (index >= truck_weights.length && bridgeQue.isEmpty()) break; + time++; + } + + return time + 1; + } // End of solution + + private static boolean nowBridgeWeightCheck(Queue bridgeQue, int nextCarWeight) { // 현재 다리의 무게 체크 + int sum = 0; + for (Car car : bridgeQue) { + sum += car.weight; + if (sum >= weightLimit) return false; + } + + sum += nextCarWeight; + if (sum > weightLimit) return false; + return true; + } // End of weightCheck + + private static void increaseTime(Queue bridgeQue) { + int size = bridgeQue.size(); + for (int i = 0; i < size; i++) { + Car car = bridgeQue.poll(); + + int nextTime = car.time + 1; + if (nextTime == bridge_length) continue; + + bridgeQue.offer(new Car(car.weight, nextTime)); + } + + } // End of increaseTime +} // End of Main class From 1fdcdc2e03aa7a5bfc7dced8bac96839fcafdac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 14 Nov 2022 16:58:58 +0900 Subject: [PATCH 469/822] =?UTF-8?q?Create=20=EB=8B=A4=EB=A6=AC=EB=A5=BC?= =?UTF-8?q?=EC=A7=80=EB=82=98=EB=8A=94=ED=8A=B8=EB=9F=AD.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\212\224\355\212\270\353\237\255.cpp" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" diff --git "a/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" "b/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" new file mode 100644 index 0000000..381c88e --- /dev/null +++ "b/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" @@ -0,0 +1,26 @@ +#include +#include + +using namespace std; + +int solution(int bridge_length, int weight, vector truck_weights) { + int answer = 0; //경과 시간 + int nowWeight = 0; //현재 다리의 무게 + vector> onbridge; //다리에 있는 트럭의 남은 시간, 무게 + int i = 0; //truck_weights index + while (i < truck_weights.size() || !onbridge.empty()) { + if (!onbridge.empty() && onbridge[0].first <= 0) { //맨앞 트럭 빼기 + nowWeight -= onbridge[0].second; + onbridge.erase(onbridge.begin()); + } + if (i < truck_weights.size() && nowWeight + truck_weights[i] <= weight) { //트럭 넣기 + nowWeight += truck_weights[i]; + onbridge.push_back({ bridge_length,truck_weights[i++] }); + } + for (int k = 0; k < onbridge.size(); k++) { //남은시간 하나씩 빼기 + onbridge[k].first -= 1; + } + answer++; + } + return answer; +} From edc9fe908113b66a0292d7654118d1aab331f4c5 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 14 Nov 2022 20:16:14 +0900 Subject: [PATCH 470/822] kihun --- ...0\353\212\224_\355\212\270\353\237\255.py" | 41 +++++++++++ ...53\260\261\354\244\200_11559_Puyo_Puyo.py" | 72 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 "11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" create mode 100644 "11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" diff --git "a/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" "b/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" new file mode 100644 index 0000000..e4a797d --- /dev/null +++ "b/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" @@ -0,0 +1,41 @@ +from collections import deque + +def solution(bridge_length, weight, truck_weights): + t = 0 + bridge = [0 for _ in range(bridge_length)] + bridge_q_weight = 0 + + bridge_q = deque(bridge) + truck_q = deque(truck_weights) + while bridge_q: + t += 1 + bridge_q_weight -= bridge_q[0] + bridge_q.popleft() + + if truck_q: + if bridge_q_weight + truck_q[0] <= weight: + bridge_q_weight += truck_q[0] + bridge_q.append(truck_q.popleft()) + else: + bridge_q.append(0) + return t + +# 시간 초과. 조건문의 sum을 빼냈다. +# def solution(bridge_length, weight, truck_weights): +# t = 0 +# bridge = [0 for _ in range(bridge_length)] +# bridge_q = deque(bridge) +# truck_q = deque(truck_weights) +# while bridge_q: +# t += 1 +# bridge_q.popleft() + +# if truck_q: +# if sum(bridge_q) + truck_q[0] <= weight: +# bridge_q.append(truck_q.popleft()) +# else: +# bridge_q.append(0) + +# return t + +print(solution(2, 10, [7, 4, 5, 6])) diff --git "a/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" "b/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" new file mode 100644 index 0000000..c1ff7e0 --- /dev/null +++ "b/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" @@ -0,0 +1,72 @@ +import sys +from collections import deque + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +# 상 하 좌 우 +dy = [-1, 1, 0, 0] +dx = [0, 0, -1, 1] + +matrix = [list(input()) for _ in range(12)] + +original = [[0 for _ in range(6)] for _ in range(12)] + + +def bfs(y, x): + q = deque() + tempMatrix = [item[:] for item in original] + q.append([y, x]) + combo = 0 + count = 1 + + tempMatrix[y][x] = count + while q: + nowY, nowX = q.popleft() + for d in range(4): + nY = nowY + dy[d] + nX = nowX + dx[d] + if 0 <= nY < 12 and 0 <= nX < 6: + if (matrix[nY][nX] == matrix[nowY][nowX] + and tempMatrix[nY][nX] == 0): + count += 1 + tempMatrix[nY][nX] = 1 + q.append([nY, nX]) + + if count >= 4: + combo += 1 + for i in range(12): + for j in range(6): + if tempMatrix[i][j] == 1: + matrix[i][j] = "." + + return combo + + +def down(): + for x in range(6): + q = deque() + for y in range(11, -1, -1): + if matrix[y][x] != ".": + q.append(matrix[y][x]) + for y in range(11, -1, -1): + if q: + matrix[y][x] = q.popleft() + else: + matrix[y][x] = "." + + +result = 0 +while True: + flag = 0 + for y in range(12): + for x in range(6): + if matrix[y][x] != ".": + flag += bfs(y, x) + + if flag == 0: + print(result) + break + else: + result += 1 + + down() From dc8270f1b4806d36120b63c32756b9e6635eabbb Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 14 Nov 2022 22:01:54 +0900 Subject: [PATCH 471/822] Create readme --- 11.17/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 11.17/readme.md diff --git a/11.17/readme.md b/11.17/readme.md new file mode 100644 index 0000000..b88b063 --- /dev/null +++ b/11.17/readme.md @@ -0,0 +1,7 @@ +# 11.14(월) 스터디 + +11559_Puyo Puyo +https://www.acmicpc.net/problem/11559 + +다리를 지나는 트럭 +https://school.programmers.co.kr/learn/courses/30/lessons/42583 From 3c7f00720f373a224e5bd40372115948fabbe9e2 Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Mon, 14 Nov 2022 22:04:45 +0900 Subject: [PATCH 472/822] Update readme.md --- 11.17/readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/11.17/readme.md b/11.17/readme.md index b88b063..b372312 100644 --- a/11.17/readme.md +++ b/11.17/readme.md @@ -1,7 +1,7 @@ -# 11.14(월) 스터디 +# 11.17(목) 스터디 -11559_Puyo Puyo -https://www.acmicpc.net/problem/11559 +17142_연구소 3 +https://www.acmicpc.net/problem/17142 -다리를 지나는 트럭 -https://school.programmers.co.kr/learn/courses/30/lessons/42583 +삼각 달팽이 +https://school.programmers.co.kr/learn/courses/30/lessons/68645 From 29b860b8a6762c9092e05d2b032dc78d32a0a2e2 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 14 Nov 2022 22:04:07 +0900 Subject: [PATCH 473/822] solve --- ...\354\227\260\352\265\254\354\206\214 3.kt" | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 "11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" diff --git "a/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" "b/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" new file mode 100644 index 0000000..73b1f0d --- /dev/null +++ "b/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" @@ -0,0 +1,113 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.* +import kotlin.collections.ArrayList +import kotlin.math.min + +data class Point(val r: Int, val c: Int) +lateinit var laboratory : Array> +lateinit var virusList : ArrayList +val direction = arrayOf(intArrayOf(-1,0), intArrayOf(1,0), intArrayOf(0,-1), intArrayOf(0,1)) +var minTime = Integer.MAX_VALUE + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + var token = StringTokenizer(br.readLine()) + val N = token.nextToken().toInt() + val M = token.nextToken().toInt() + + laboratory = Array(N){Array (N){ "b" }} + virusList = ArrayList() + + repeat(N){ row -> + token = StringTokenizer(br.readLine()) + repeat(N){ col -> + val info = token.nextToken().toInt() + when(info){ + 1 -> laboratory[row][col] = "-" + 2 -> { + laboratory[row][col] = "*" + virusList.add(Point(row,col)) + } + } + } + } + + activate(0,0,M, activeArr = Array(M){Point(-1,-1)}) + if (minTime == Integer.MAX_VALUE) println(-1) else println(minTime) + +} +//바이러스 활성화 브루트포스 +fun activate(start : Int, size : Int, M : Int, activeArr : Array){ + if (size == M){ + spread(activeArr) + return + } + + for (i in start until virusList.size){ + activeArr[size] = virusList[i] + activate(i+1,size+1,M,activeArr) + } +} + +fun spread(activeArr : Array){ + val tempLab = Array(laboratory.size){Array(laboratory.size){""}} + copyLab(tempLab) + + val queue : Queue = LinkedList() + queue.addAll(activeArr) + for (activated in activeArr){ + tempLab[activated.r][activated.c] = "0" + } + + var time = 1 + var maxTime = 0 + while (queue.isNotEmpty()){ + for (i in 0 until queue.size){ + val point = queue.poll() + for (i in direction.indices){ + val pointR = point.r + direction[i][0] + val pointC = point.c + direction[i][1] + + if (pointR in laboratory.indices && pointC in laboratory.indices && tempLab[pointR][pointC] != "-"){ + if (tempLab[pointR][pointC] == "b"){ + tempLab[pointR][pointC] = "$time" + maxTime = time + queue.add(Point(pointR,pointC)) + }else if(tempLab[pointR][pointC] == "*"){ + tempLab[pointR][pointC] = "a" + queue.add(Point(pointR,pointC)) + } + } + } + } + time++ + } + + if (checkSpread(tempLab)) minTime = min(minTime,maxTime) +} +//깊은 복사 +fun copyLab(tempLab : Array>) : Array>{ + for (i in laboratory.indices){ + for (j in laboratory[i].indices){ + tempLab[i][j] = laboratory[i][j] + } + } + return tempLab +} +//바이러스가 다 퍼졌는지 검사 +fun checkSpread(tempLab : Array>) : Boolean{ + for (i in tempLab.indices){ + for (j in tempLab[i].indices) + { + if (tempLab[i][j] == "b") return false + } + } + return true +} + + + + + From 43138c022cd4f3f6c46b0fb6fd5db5aaf53fa657 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 14 Nov 2022 22:04:28 +0900 Subject: [PATCH 474/822] solve --- ...1 \353\213\254\355\214\275\354\235\264.kt" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" diff --git "a/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" "b/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" new file mode 100644 index 0000000..43a55c8 --- /dev/null +++ "b/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" @@ -0,0 +1,79 @@ +package com.android.example.kotlinproject + +import java.util.* + +fun main(){ + val n = 8 + println(Solution().solution(n)) +} + +class Solution { + fun solution(n: Int): IntArray { + + val arr = Array(n) { IntArray(n) } + + var value = 1 //배열에 넣어줄 값 + var direction = 1 //방향 + var rowMax = n - 1 //마지막 행 + var colMax = n - 1 //마지막 열 + var rowMin = 0 //시작 행 + var rowCount = 0 //현재 행 + var colCount = 0 //현재 열 + + + var sum = 0 + for (i in 1 until n) { //총 몇개의 value까지 가는지 계산 + sum += i + } + if (n == 1) return intArrayOf(1) // n = 1이면 {1} + else { + while (true) { + if (value > n + sum) break //마지막 요소 할당 끝나면 break + + when (direction) { + 1 -> { //아래 방향 + if (rowCount == rowMax) { //마지막 행에 도달했을 경우 방향 전환 + arr[rowCount][colCount] = value + colCount++ + direction = 2 + rowMin++ + } else { + arr[rowCount][colCount] = value + rowCount++ + } + } + 2 -> { //오른쪽방향 + if (colCount == colMax) { //마지막 열에 도달했을 경우 방향 전환 + arr[rowCount][colCount] = value + direction = 3 + colCount-- + rowCount-- + colMax-- + } else { + arr[rowCount][colCount] = value + colCount++ + } + } + 3 -> { //왼쪽 위 대각선 방향 + if (rowCount == rowMin) { //시작행에 도달했을 때 방향전환 + arr[rowCount][colCount] = value + direction = 1 + rowCount++ + colMax-- + rowMax-- + rowMin++ + } else { + arr[rowCount][colCount] = value + rowCount-- + colCount-- + } + } + } + value++ + } + } + + var result = arr.flatMap { it.filter { it > 0 } } //2차원배열을 일차원으로 바꾼후 0인 value를 제외하고 flattern + return result.toIntArray() + } +} \ No newline at end of file From e084e21aa2fda0509ce539eebe92daf83d4cef4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:18:45 +0900 Subject: [PATCH 475/822] =?UTF-8?q?Create=20=EC=82=BC=EA=B0=81=EB=8B=AC?= =?UTF-8?q?=ED=8C=BD=EC=9D=B4.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\353\213\254\355\214\275\354\235\264.cpp" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" diff --git "a/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" "b/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" new file mode 100644 index 0000000..ccf5c53 --- /dev/null +++ "b/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" @@ -0,0 +1,50 @@ +#include +#include + +using namespace std; + +int dy[] = { 1,0,-1 }; +int dx[] = { 0,1,-1 }; +vector> board(1001,vector(1001)); +int cnt = 1; + +void draw(int y, int x, int N) { + if (N == 0) { + board[y][x] = cnt++; + return; + } + for (int i = 0; i < 3; i++) { + for (int k = 0; k < N; k++) { + board[y][x] = cnt++; + y += dy[i]; + x += dx[i]; + } + } +} + +int getTotal(int n) { + int answer = 0; + for (int i = 1; i <= n; i++) { + answer += i; + } + return answer; +} + +vector solution(int n) { + vector answer; + int y = 0, x = 0, N = n - 1; + int total = getTotal(n); + while (cnt <= total) { + draw(y, x, N); + y += 2; + x += 1; + N -= 3; + } + //직렬화 + for (int i = 0; i < n; i++) { + for (int k = 0; k <= i; k++) { + answer.push_back(board[i][k]); + } + } + return answer; +} From 14c6223b528ca75e465771e8ba3e39e9c8c3f57d Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Tue, 15 Nov 2022 11:20:16 +0900 Subject: [PATCH 476/822] =?UTF-8?q?=EC=97=B0=EA=B5=AC=EC=86=8C=20=EB=B6=80?= =?UTF-8?q?=EC=88=B4=EB=B2=84=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\227\260\352\265\254\354\206\214_3.java" | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 "11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" diff --git "a/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" "b/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" new file mode 100644 index 0000000..fb38ca1 --- /dev/null +++ "b/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" @@ -0,0 +1,203 @@ +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/17142 +// 바이러스를 어떻게 놓아도 모든 빈 칸에 바이러스를 퍼뜨릴 수 없는 경우에는 -1을 출력 +public class Main_17142_연구소_3 { + private static final int INF = Integer.MAX_VALUE; + private static final int MAX_ARR_SIZE = 50; + static int N, M, result; + static int[][] map = new int[MAX_ARR_SIZE][MAX_ARR_SIZE]; + static int[][] tempMap = new int[MAX_ARR_SIZE][MAX_ARR_SIZE]; + static int[][] dist = new int[MAX_ARR_SIZE][MAX_ARR_SIZE]; + static Coordinates[] comb; + + static int[] dirX = {-1, 1, 0, 0}; + static int[] dirY = {0, 0, -1, 1}; + static List blankList; + static List virusList; + static boolean[] isVisited; + + static class Coordinates { + int x; + int y; + + public Coordinates(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Coordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/17142.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + init(); + + // 0은 빈칸, 1은 벽, 2는 바이러스 + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + + if (map[i][j] == 0) { + // 빈공간을 저장 + blankList.add(new Coordinates(i, j)); + } else if (map[i][j] == 2) { + virusList.add(new Coordinates(i, j)); + // 바이러스 좌표는 저장하고 -1로 표시 + map[i][j] = -1; + } + } + } + + // 빈공간이 없으면 0을 출력 + if (blankList.isEmpty()) { + System.out.println(0); + return; + } + + // 빈 공간에, 바이러스 좌표를 넣기. + isVisited = new boolean[virusList.size()]; + DFS(0, 0, virusList.size()); + + if (result == Integer.MAX_VALUE) { + System.out.println(-1); + return; + } + + System.out.println(result); + } // End of main + + private static void DFS(int index, int depth, int size) { + + if (depth == M) { + mapCopy(); // 다시 map 원상태로 복귀 + virusPlacement(); // 만들어진 조합으로 바이러스를 지도에 배치 + + int bfsResult = BFS(); // 바이러스 퍼트리기 시작. + result = Math.min(bfsResult, result); + return; + } + + for (int i = index; i < size; i++) { + if (isVisited[i]) continue; + + isVisited[i] = true; + comb[depth] = virusList.get(i); + DFS(i + 1, depth + 1, size); + isVisited[i] = false; + } + + } // End of DFS + + private static int BFS() { // 바이러스 퍼트리기. + boolean[][] isVisitedMap = new boolean[N][N]; + Queue que = new LinkedList<>(); + int maxTime = -1; + + // 바이러스 좌표들 집어넣기 + for (Coordinates coor : comb) { + que.offer(new Coordinates(coor.x, coor.y)); + isVisitedMap[coor.x][coor.y] = true; + tempMap[coor.x][coor.y] = 2; + dist[coor.x][coor.y] = 0; + } + + while (!que.isEmpty()) { + Coordinates coor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = dirX[i] + coor.x; + int nowY = dirY[i] + coor.y; + + // 해당 위치에 가장 먼저 도착한 최단 값이 들어가야된다. + // 계속해서 값을 갱신하면 안됨. + if (!rangeCheck(nowX, nowY) || isVisitedMap[nowX][nowY]) continue; + else if (!findEmptySpace()) { + // 빈 공간이 없으면 곧 바로 중지 + return findMaxTime(); + } + + if (tempMap[nowX][nowY] == -1) { + isVisitedMap[nowX][nowY] = true; + tempMap[nowX][nowY] = 2; + que.offer(new Coordinates(nowX, nowY)); + dist[nowX][nowY] = dist[coor.x][coor.y] + 1; + } else if (tempMap[nowX][nowY] == 0) { + isVisitedMap[nowX][nowY] = true; + tempMap[nowX][nowY] = 2; + que.offer(new Coordinates(nowX, nowY)); + dist[nowX][nowY] = dist[coor.x][coor.y] + 1; + } + } + } + + if (findEmptySpace()) { + // 빈 공간이 있으면 최댓값을 반환 + return Integer.MAX_VALUE; + } + + // 빈 공간이 없을 경우, 가장 많이 걸린 시간을 찾아서 반환. + return findMaxTime(); + } // End of BFS + + private static int findMaxTime() { + int maxTime = -1; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (dist[i][j] == INF) continue; + maxTime = Math.max(maxTime, dist[i][j]); + } + } + + return maxTime; + } // End of findMaxTime + + private static void virusPlacement() { + // 바이러스 활성화, 비활성화 시키기 + + for (Coordinates coor : comb) { + tempMap[coor.x][coor.y] = 2; + } + + } // End of virusPlacement + + private static boolean findEmptySpace() { + // 빈공간 찾기. + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (tempMap[i][j] == 0) { + return true; + } + } + } + + return false; // 빈 공간 없음 + } // End of findEmptySpace + + private static void mapCopy() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + tempMap[i][j] = map[i][j]; + dist[i][j] = INF; + } + } + + } // End of mapCopy + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + result = Integer.MAX_VALUE; + blankList = new ArrayList<>(); + virusList = new ArrayList<>(); + comb = new Coordinates[M]; + } // End of init +} // End of Main class From 7b481ac6be2724d6e9acf271bffe935defa7b9f6 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 17 Nov 2022 18:35:48 +0900 Subject: [PATCH 477/822] kihun --- ...1_\353\213\254\355\214\275\354\235\264.py" | 28 +++++++ ..._\354\227\260\352\265\254\354\206\2143.py" | 79 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 "11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" create mode 100644 "11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" diff --git "a/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" "b/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" new file mode 100644 index 0000000..f8870d8 --- /dev/null +++ "b/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" @@ -0,0 +1,28 @@ +def solution(n): + answer = [] + triangle = [[0 for _ in range(n)] for _ in range(n)] + + y, x = -1, 0 + number = 1 + + for i in range(n): + for j in range(i, n): + # 아래 + if i % 3 == 0: + y += 1 + # 오른쪽 + elif i % 3 == 1: + x += 1 + # 위 + elif i % 3 == 2: + y -= 1 + x -= 1 + triangle[y][x] = number + number += 1 + + for tri in triangle: + for t in tri: + if t != 0: + answer.append(t) + + return answer diff --git "a/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" "b/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" new file mode 100644 index 0000000..4bd8606 --- /dev/null +++ "b/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" @@ -0,0 +1,79 @@ +import sys +from collections import deque + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +# 우 하 좌 상 +dy = [0, 1, 0, -1] +dx = [1, 0, -1, 0] + +n, m = map(int, input().split()) + +matrix = [] +virus = [] +visited = [[-1 for _ in range(n)] for _ in range(n)] +result = 10 ** 9 + +# 벽은 -1, 바이러스는 따로 위치 저장 +wall = 0 +for y in range(n): + temp = list(map(int, input().split())) + for x in range(n): + if (temp[x] == 1): + temp[x] = -1 + wall += 1 + elif (temp[x] == 2): + virus.append((y, x)) + matrix.append(temp) + +virusCount = len(virus) + + +def pickM(index, now): + global result + if (len(now) == m): + result = min(result, bfs(now)) + return + + for i in range(index, virusCount): + pickM(i + 1, now + [virus[i]]) + + +def bfs(selected): + result = 0 + tempVisited = [item[:] for item in visited] + + q = deque(selected) + for s in selected: + tempVisited[s[0]][s[1]] = 0 + + while q: + y, x = q.popleft() + for d in range(4): + nY = y + dy[d] + nX = x + dx[d] + if (0 <= nY < n and 0 <= nX < n and tempVisited[nY][nX] == -1): + # 빈 칸일 때 + if matrix[nY][nX] == 0: + tempVisited[nY][nX] = tempVisited[y][x] + 1 + result = max(result, tempVisited[nY][nX]) + q.append([nY, nX]) + # 바이러스 일 때 + elif matrix[nY][nX] == 2: + tempVisited[nY][nX] = tempVisited[y][x] + 1 + q.append([nY, nX]) + + flatten = [] + for temp in tempVisited: + flatten += temp + if flatten.count(-1) != wall: + return 10**9 + return result + + +pickM(0, []) + +if result == 10 ** 9: + print(-1) +else: + print(result) From a6abe1e5be1ffd4d4c48a2c94c7c0a81f1b160c2 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 31 Dec 2022 01:06:03 +0900 Subject: [PATCH 478/822] complete --- .../Main 1068 \355\212\270\353\246\254.kt" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" diff --git "a/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" "b/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" new file mode 100644 index 0000000..67409aa --- /dev/null +++ "b/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" @@ -0,0 +1,83 @@ +package `DFS&BFS 부수기` + +/* + 트리에서 리프노드란, 자식의 개수가 0인 노드를 의미한다. + 트리가 주어졌을 때, 노드를 하나 지운다. 그 때, 남은 트리에서 리프 노드의 개수를 구하는 프로그램을 작성하시오. + + 노드를 지우면 그 노드와 노드의 모든 자손이 트리에서 제거된다. + 노드의 개수 N은 50보다 작은 자연수 + + 첫째 줄에 입력을 주어진 트리에서 입력으로 주어진 노드를 지웠을 때, 리프 노드의 개수를 출력한다. + */ + +import java.util.* +import java.io.* + +private var N = 0 +private val arr = IntArray(51) +private val isVisited = BooleanArray(51) + +fun main() { + val path = "C:\\Users\\Samsung\\Desktop\\코틀린 알고리즘\\src\\main\\kotlin\\DFS&BFS 부수기\\res\\1068.txt" + val br = BufferedReader(File(path).bufferedReader()) + + N = br.readLine().toInt() + val st = StringTokenizer(br.readLine()) + + for (i in 0 until N) { + arr[i] = st.nextToken().toInt() + // 배열에서 index는 각 노드의 번호가 되고, value는 부모 노드의 번호가 된다. + } + + // 루트 노드는 항상 -1의 값을 가진다. + + val deleteNodeNum = br.readLine().toInt() + // 루트 노드를 제거하면 리프노드는 존재할 수 없다. + if (arr[deleteNodeNum] == -1) { + println(0) + return + } + + // 시작하는 노드의 번호 -> 지울 노드의 번호 + DFS(deleteNodeNum) + + // 제거된 노드를 반영해야된다. + val isParent = BooleanArray(N) + for (i in 0 until N) { + // 자신을 부모로 여기는 값이 없으면 count++ + val parentNum = arr[i] + if(parentNum == -1) continue + + if(isVisited[i]) continue + isParent[parentNum] = true + } + + + // 둘다 false인 값 + var count = 0 + for (i in 0 until N) { + if (isParent[i] == false && isVisited[i] == false) { + count++ + } + } + + println(count) +} // End of main + +/* + 배열에서 + value는 자신의 부모 노드 번호를 의미하고 + index는 해당 노드의 번호를 의미한다. + */ +private fun DFS(startNum: Int) { + isVisited[startNum] = true + // 부모 노드의 번호를 가진 값들로 모두 DFS탐색 + + for (i in 0 until N) { + if (arr[i] == startNum) { + isVisited[i] = true + DFS(i) + } + } +} // End of DFS + From 683727443ec0ebdfcbd96af019f4e1188b718b60 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 31 Dec 2022 01:12:23 +0900 Subject: [PATCH 479/822] complete --- .../Main 1068 \355\212\270\353\246\254.kt" | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git "a/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" "b/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" index 67409aa..69521ef 100644 --- "a/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" +++ "b/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" @@ -14,8 +14,8 @@ import java.util.* import java.io.* private var N = 0 -private val arr = IntArray(51) -private val isVisited = BooleanArray(51) +private val arr = IntArray(50) +private val isVisited = BooleanArray(50) fun main() { val path = "C:\\Users\\Samsung\\Desktop\\코틀린 알고리즘\\src\\main\\kotlin\\DFS&BFS 부수기\\res\\1068.txt" @@ -30,7 +30,6 @@ fun main() { } // 루트 노드는 항상 -1의 값을 가진다. - val deleteNodeNum = br.readLine().toInt() // 루트 노드를 제거하면 리프노드는 존재할 수 없다. if (arr[deleteNodeNum] == -1) { @@ -41,18 +40,14 @@ fun main() { // 시작하는 노드의 번호 -> 지울 노드의 번호 DFS(deleteNodeNum) - // 제거된 노드를 반영해야된다. + // 제거된 노드를 반영하여 자신의 노드 번호를 가지고 있는 노드를 찾는다. val isParent = BooleanArray(N) for (i in 0 until N) { - // 자신을 부모로 여기는 값이 없으면 count++ - val parentNum = arr[i] - if(parentNum == -1) continue + if (arr[i] == -1 || isVisited[i]) continue // 루트 노드는 통과, - if(isVisited[i]) continue - isParent[parentNum] = true + isParent[arr[i]] = true } - // 둘다 false인 값 var count = 0 for (i in 0 until N) { @@ -79,5 +74,4 @@ private fun DFS(startNum: Int) { DFS(i) } } -} // End of DFS - +} // End of DFS \ No newline at end of file From 551aac8d0416e89e197926c273bf79a8cea9732f Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 31 Dec 2022 01:15:09 +0900 Subject: [PATCH 480/822] complete --- .../Main 1068 \355\212\270\353\246\254.kt" | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git "a/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" "b/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" index 69521ef..54064b7 100644 --- "a/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" +++ "b/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" @@ -43,15 +43,17 @@ fun main() { // 제거된 노드를 반영하여 자신의 노드 번호를 가지고 있는 노드를 찾는다. val isParent = BooleanArray(N) for (i in 0 until N) { - if (arr[i] == -1 || isVisited[i]) continue // 루트 노드는 통과, + if (arr[i] == -1 || isVisited[i]) continue // 루트 노드와, 이미 삭제된 노드는 통과 + // arr[i]의 value가 곧 자신의 부모 노드 번호. + // 즉, 자식이 있는 노드가 어떤 노드인지 파악할 수 있음 isParent[arr[i]] = true } // 둘다 false인 값 var count = 0 for (i in 0 until N) { - if (isParent[i] == false && isVisited[i] == false) { + if (!isParent[i] && !isVisited[i]) { count++ } } From af5061e749f73562d10d3845851f5ec57146e13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 3 Jan 2023 14:34:47 +0900 Subject: [PATCH 481/822] =?UTF-8?q?Create=201068=5F=ED=8A=B8=EB=A6=AC.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1068_\355\212\270\353\246\254.cpp" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" diff --git "a/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" "b/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" new file mode 100644 index 0000000..91bc070 --- /dev/null +++ "b/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" @@ -0,0 +1,42 @@ +#include +#include +#include + +using namespace std; +int N; +vector child[51]; +int removeIdx; + +int getLeaf() { + int answer = 0; + for (int i = 0; i < N; i++) { + if (child[i].empty()) answer++; + if (child[i].size() == 1 && child[i][0] == removeIdx) answer++; + } + return answer; +} + +int main() { + cin >> N; + for (int i = 0; i < N; i++) { + int n; cin >> n; + if (n >= 0) { + child[n].push_back(i); + } + } + + queue q; + cin >> removeIdx; + q.push(removeIdx); + while (!q.empty()) { + int now = q.front(); q.pop(); + if (now < 0) continue; + for (int n : child[now]) { + q.push(n); + } + child[now].push_back(-2); + } + + cout << getLeaf() << endl; + return 0; +} From 876d49a1259c2263eca35a0383992860ee2d008f Mon Sep 17 00:00:00 2001 From: "DESKTOP-KVCQHCD\\multicampus" Date: Tue, 3 Jan 2023 16:42:42 +0900 Subject: [PATCH 482/822] solve --- .../1068_\355\212\270\353\246\254.kt" | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" diff --git "a/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" "b/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" new file mode 100644 index 0000000..6a2193c --- /dev/null +++ "b/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" @@ -0,0 +1,78 @@ +package com.example.algorithm + +import java.io.BufferedReader +import java.io.InputStreamReader +import java.util.* +import kotlin.collections.ArrayList + +lateinit var childGraph : Array> //자식 정보를 담는 인접리스트 +lateinit var parentArr : IntArray //해당 노드가 가지는 부모 정보를 담는 배열 +lateinit var visited : BooleanArray //노드 방문 체크 배열 + +fun main(){ + val br = BufferedReader(InputStreamReader(System.`in`)) + val N = br.readLine().toInt() + var count = 0 + + childGraph = Array(N){ArrayList()} + + parentArr = IntArray(N){-1} + visited = BooleanArray(N) + + val token = StringTokenizer(br.readLine()) + + repeat(N){ + val parent = token.nextToken().toInt() + + if (parent != -1){ + childGraph[parent].add(it) + parentArr[it] = parent + } + + } + + val rNode = br.readLine().toInt() + + dfs(rNode) + + for (i in childGraph.indices){ //자식노드가 없고 방문한 기록이 없으면 ++ + if (childGraph[i].isEmpty() && !visited[i]) count++ + } + + println(count) +} + +fun dfs(remove : Int){ + val stack = Stack() + + if (parentArr[remove] != -1){ + childGraph[parentArr[remove]].remove(remove) //해당 자식을 가지는 부모 노드에서 자식 노드 제거 + } + + visited[remove] = true + + for (node in childGraph[remove]){ //제거하는 노드의 자식 노드들을 스택에 추가 + stack.push(node) + } + + while (childGraph[remove].isNotEmpty()){ //해당 노드에 자식들을 제거 + childGraph[remove].removeAt(0) + } + + + while (stack.isNotEmpty()){ + val node = stack.pop() + + visited[node] = true + + for (childNode in childGraph[node]){ + if (!visited[childNode]){ + stack.push(childNode) + } + } + + while (childGraph[node].isNotEmpty()){ + childGraph[node].removeAt(0) + } + } +} \ No newline at end of file From 933307307ea3cdcfd550a687b05987329c556c98 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Tue, 3 Jan 2023 16:50:35 +0900 Subject: [PATCH 483/822] complete --- ...14\354\240\204\355\225\230\352\270\260.kt" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" diff --git "a/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" "b/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" new file mode 100644 index 0000000..5ecd355 --- /dev/null +++ "b/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" @@ -0,0 +1,82 @@ +package `일반구현 부수기` + +/* + {} (), []가 문자열을 올바른 괄호 문자열이라고 정의합니다. + + 만약 A가 올바른 괄호 문자열이라면, (A), [A], {A}도 올바른 괄호 문자열입니다. + + 예를 들어 []가 올바른 괄호 문자열이므로 + + S가 매개변수로 주어질 때, S를 왼쪽으로 0 ~ s의 길이만큼 회전시켰을 때 + s가 올바른 괄호 문자열이 되게 하는 x의 개수를 return 하라 + */ + + +import java.util.* +import java.lang.StringBuilder + +private var S = "" +fun main() { + val s = "{{{{" + println(solution(s)) +} // End of main + +private fun solution(s: String): Int { + var ans = 0 + S = s + + val len = s.length + for (i in 0 until len) { + // S로 들어온 값이 올바른 괄호의 형태를 가지는가를 파악하기\ + // 서로의 괄호가 짝이 맞는가? + if (checkString(S, len)) { + ans++ + } + + println("roation String : $S") + S = rotation(S) + } + + return ans +} // End of solution + +private fun rotation(str: String): String { + // 왼쪽으로 회전 + val temp = StringBuilder() + temp.append(str.substring(1, str.length)).append(str[0]) + return temp.toString() +} // End of rotation + +private fun checkString(str: String, len: Int): Boolean { + val dque: Deque = LinkedList() + + for (i in 0 until len) { + if (str[i] == '(' || str[i] == '[' || str[i] == '{') { + dque.offerFirst(str[i]) + } else if (str[i] == ')' || str[i] == ']' || str[i] == '}') { + if (dque.isEmpty()) { + return false + } else { + if (dque.isEmpty()) { + return false + } + val temp = str[i] + val poll = dque.pollFirst() + + if (temp == ')' && poll != '(') { + return false + } else if (temp == '}' && poll != '{') { + return false + } else if (temp == ']' && poll != '[') { + return false + } + } + } + } + + if (!dque.isEmpty()) { + return false + } + + return true +} // End of checkString \ No newline at end of file From e029e08d2cd7f316988b541056ccab099ca12169 Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Wed, 4 Jan 2023 08:53:09 +0900 Subject: [PATCH 484/822] solve --- ...14\354\240\204\355\225\230\352\270\260.kt" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" diff --git "a/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" "b/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" new file mode 100644 index 0000000..c111f30 --- /dev/null +++ "b/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" @@ -0,0 +1,72 @@ +package com.ssafy.algorithm + +import java.util.* + +fun main() { + val sl = Solution() + val s = "}}}" + println(sl.solution(s)) +} + +class Solution { + fun solution(s: String): Int { + val queue: Queue = LinkedList() + var answer: Int = 0 + + for (c in s) { + queue.add(c) + } + var count = 0 + while (count < s.length) { + if (check(queue)) answer++ //올바른 괄호라면 ++ + + queue.add(queue.poll()) // 회전하기 + + count++ + + } + + return answer + } + + fun check(queue: Queue): Boolean { + val stack: Stack = Stack() + for (c in queue) { + if (stack.isEmpty()) { + if (c == ')' || c == '}' || c == ']') return false //비어있을 때 닫는 괄호가 오면 종료 + stack.add(c) + } else { + when (c) { + ')' -> + if (stack.contains('(')) { + if (stack.peek() == '(') stack.pop() //바로 앞에 같은 괄호가 있으면 stack pop + else stack.add(c) + }else{ + return false //여는 기호가 없다면 종료 + } + '}' -> + if (stack.contains('{')) { + if (stack.peek() == '{') stack.pop() + else stack.add(c) + }else{ + return false + } + ']' -> + if (stack.contains('[')) { + if (stack.peek() == '[') stack.pop() + else stack.add(c) + }else{ + return false + } + else -> stack.add(c) + } + } + } + + if (stack.isEmpty()) return true + + return false + } +} + + From dbf29b2a1daa87ae0934ccea97a53a94991d19e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 4 Jan 2023 13:16:29 +0900 Subject: [PATCH 485/822] =?UTF-8?q?Create=20=EA=B4=84=ED=98=B8=20=ED=9A=8C?= =?UTF-8?q?=EC=A0=84=ED=95=98=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\240\204\355\225\230\352\270\260.cpp" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" diff --git "a/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" "b/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..3b9045f --- /dev/null +++ "b/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" @@ -0,0 +1,45 @@ +#include +#include +#include + +using namespace std; + +int solution(string s) { + int answer = 0; + for (int i = 0; i < s.size(); i++) { + stack stacks; + string str = s.substr(i); + str += s.substr(0, i); + bool flag = true; + for (char c : str) { + if (c == '(' || c == '[' || c == '{') { + stacks.push(c); + } + else if (c == ')') { + if (stacks.top() == '(') stacks.pop(); + else { + flag = false; + break; + } + } + else if (c == ']') { + if (stacks.top() == '[') stacks.pop(); + else { + flag = false; + break; + } + } + else if (c == '}') { + if (stacks.top() == '{') stacks.pop(); + else { + flag = false; + break; + } + } + } + if (flag && stacks.empty()) { + answer++; + } + } + return answer; +} From 50f116dd0ae21ea1148ad8f55c39dd17aa17d024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 4 Jan 2023 13:21:49 +0900 Subject: [PATCH 486/822] =?UTF-8?q?Update=20=EA=B4=84=ED=98=B8=20=ED=9A=8C?= =?UTF-8?q?=EC=A0=84=ED=95=98=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\240\204\355\225\230\352\270\260.cpp" | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git "a/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" "b/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" index 3b9045f..09d5e87 100644 --- "a/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" +++ "b/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" @@ -1,11 +1,13 @@ #include #include #include +#include using namespace std; int solution(string s) { int answer = 0; + map m = { {')','('},{'}','{'},{']','['} }; for (int i = 0; i < s.size(); i++) { stack stacks; string str = s.substr(i); @@ -15,25 +17,13 @@ int solution(string s) { if (c == '(' || c == '[' || c == '{') { stacks.push(c); } - else if (c == ')') { - if (stacks.top() == '(') stacks.pop(); - else { + else if (c == ')' || c == '}' || c == ']') { + if(stacks.empty() || stacks.top() != m[c]) { flag = false; break; } - } - else if (c == ']') { - if (stacks.top() == '[') stacks.pop(); else { - flag = false; - break; - } - } - else if (c == '}') { - if (stacks.top() == '{') stacks.pop(); - else { - flag = false; - break; + stacks.pop(); } } } From 50199c606ffad247062accf7a0b3385f458212e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 4 Jan 2023 22:17:02 +0900 Subject: [PATCH 487/822] =?UTF-8?q?Create=20=ED=8A=B8=EB=A6=AC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\212\270\353\246\254.java" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" diff --git "a/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" "b/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" new file mode 100644 index 0000000..bd2d246 --- /dev/null +++ "b/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" @@ -0,0 +1,68 @@ +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class boj_트리_1068 { + static int N, D, ans = 0; + static Node[] nodes; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1068.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + nodes = new Node[N + 1]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i <= N; i++) { + nodes[i] = new Node(i); + } + + int root = 0; + for (int i = 0; i < N; i++) { + int p = Integer.parseInt(st.nextToken()); + if (p == -1) { + root = i; + continue; + } + nodes[p].child.add(nodes[i]); + } + D = Integer.parseInt(br.readLine()); + if(D != root){ + deleteNode(root); + dfs(root); + } + System.out.println(ans); + } + static void dfs(int index){ + if(nodes[index].child.size() == 0){ + ans++; + return; + } + for(Node c : nodes[index].child){ + dfs(c.index); + } + } + + static void deleteNode(int index){ + for(Node c : nodes[index].child){ + if(c.index == D){ + nodes[index].child.remove(c); + return; + } + deleteNode(c.index); + } + } + + static class Node { + int index; + ArrayList child = new ArrayList<>(); + + Node(int index) { + this.index = index; + } + } +} From 1c43bbf052dd86cd027ff54a8f426a031195dcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A7=80=EC=9B=90?= <41350477+HWNAGJIWON@users.noreply.github.com> Date: Wed, 4 Jan 2023 22:18:28 +0900 Subject: [PATCH 488/822] =?UTF-8?q?Create=20=EA=B4=84=ED=98=B8=ED=9A=8C?= =?UTF-8?q?=EC=A0=84=ED=95=98=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\240\204\355\225\230\352\270\260.java" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" diff --git "a/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" "b/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" new file mode 100644 index 0000000..b7f08b6 --- /dev/null +++ "b/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" @@ -0,0 +1,65 @@ +import java.util.*; + +class Solution { + static String s[]; + + int is_right(int point) + { + + Stack stack = new Stack<>(); + String prev; + + //스택에 괄호 전부 순서대로 넣기 + for(int i=0;i 1) + { + for(int point = 0; point < s.length; point++) + { + //System.out.println("point = "+point); + + if(is_right(point) == 1) + count++; + //System.out.println("==>> \ncnt = " + count); + //System.out.println(); + } + } + + return (count); + + } +} From 01d539f7a0e20bb67c76cd27317c44f914e4c134 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 5 Jan 2023 19:34:37 +0900 Subject: [PATCH 489/822] kihun --- ...14\354\240\204\355\225\230\352\270\260.py" | 30 ++++++++++++++++++ ...\244\200_1068_\355\212\270\353\246\254.py" | 31 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 "12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" create mode 100644 "12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" diff --git "a/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" "b/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" new file mode 100644 index 0000000..1ebaf19 --- /dev/null +++ "b/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" @@ -0,0 +1,30 @@ +from collections import deque + + +def solution(s): + answer = 0 + wordList = list(s) + length = len(wordList) + for i in range(length): + q = deque() + for j in range(length): + # 스택에 비어있으면 추가 + if not q: + q.append(wordList[j]) + # 짝이 맞으면 스택에서 삭제 + elif ( + (wordList[j] == ')' and q[-1] == '(') + or (wordList[j] == ']' and q[-1] == '[') + or (wordList[j] == '}' and q[-1] == '{') + ): + q.pop() + else: + q.append(wordList[j]) + if len(q) == 0: + answer += 1 + + # 첫 문자를 뒤로 보냄 + first = wordList.pop(0) + wordList.append(first) + + return answer diff --git "a/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" "b/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" new file mode 100644 index 0000000..39c6dc9 --- /dev/null +++ "b/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" @@ -0,0 +1,31 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + + +def dfs(num): + treeInput[num] = -9 + visited[num] = True + for i in range(n): + if visited[i] == True: + continue + if treeInput[i] == num: + dfs(i) + + +# 입력 받기 +n = int(input()) +treeInput = list(map(int, input().split())) +target = int(input()) +count = 0 +visited = [False for _ in range(n)] + +# 자식노드 삭제, 삭제된 노드는 -9 +dfs(target) + +for i in range(n): + # 삭제된 노드가 아니고 부모노드가 아니어야 한다. + if treeInput[i] != -9 and i not in treeInput: + count += 1 + +print(count) From 4d289b89542191d09b85716dad48abe7e543e235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 5 Jan 2023 20:59:49 +0900 Subject: [PATCH 490/822] Create readme.md --- 12.29/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 12.29/readme.md diff --git a/12.29/readme.md b/12.29/readme.md new file mode 100644 index 0000000..c77a4c9 --- /dev/null +++ b/12.29/readme.md @@ -0,0 +1,7 @@ +# 01.05(목) 스터디 + +백준 +https://www.acmicpc.net/problem/1068 + +프로그래머스 +https://school.programmers.co.kr/learn/courses/30/lessons/76502 From bfe238b9866a295909799b8ac3839996a8a3c1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 6 Jan 2023 09:46:00 +0900 Subject: [PATCH 491/822] Create readme.md --- 23.01.09/readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 23.01.09/readme.md diff --git a/23.01.09/readme.md b/23.01.09/readme.md new file mode 100644 index 0000000..c5b09cb --- /dev/null +++ b/23.01.09/readme.md @@ -0,0 +1,5 @@ +# 1.9(월) 스터디 + +백준 : https://www.acmicpc.net/problem/2293 + +프로그래머스 : https://school.programmers.co.kr/learn/courses/30/lessons/42895 From 0f2caa3e8993930c841e07b6fbf1294baa3634f8 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 7 Jan 2023 11:12:17 +0900 Subject: [PATCH 492/822] solve --- .../\353\217\231\354\240\204_1.kt" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" diff --git "a/23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" "b/23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" new file mode 100644 index 0000000..2fe6271 --- /dev/null +++ "b/23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" @@ -0,0 +1,37 @@ +package com.ssafy.algorithm + +import java.io.* +import java.util.* + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + + val token = StringTokenizer(br.readLine()) + val n = token.nextToken().toInt() + val k = token.nextToken().toInt() + + val coins = IntArray(n) //동전 종류를 담은 배열 + + repeat(n){ + coins[it] = br.readLine().toInt() + } + + var counts = IntArray(k+1) + counts[0] = 1 //0 크기의 경우의 수는 1 + + for (i in 0 until n){ + val coin = coins[i] //현재 동전 + for (j in coin .. k){ //현재 동전 크기부터 k크기까지 경우의 수 구하기 + counts[j] += counts[j-coin] //j 크기가 되는 경우의 수는 j 크기의 경우의 수에서 현재 코인의 크기를 해당 크기만큼 뺀 경우의 수를 더해준다. + } + } + + println(counts[k]) +} + + + + + + + From d9832f27869c4d2a68cbcb7f49e1f145a285ee26 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sat, 7 Jan 2023 13:58:58 +0900 Subject: [PATCH 493/822] complete --- {23.01.09 => 01.09}/readme.md | 0 .../\353\217\231\354\240\204_1.kt" | 0 .../Main 2293 \353\217\231\354\240\204 1.kt" | 57 +++++++++++++++++++ 3 files changed, 57 insertions(+) rename {23.01.09 => 01.09}/readme.md (100%) rename "23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" => "01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" (100%) create mode 100644 "01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" diff --git a/23.01.09/readme.md b/01.09/readme.md similarity index 100% rename from 23.01.09/readme.md rename to 01.09/readme.md diff --git "a/23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" "b/01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" similarity index 100% rename from "23.01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" rename to "01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" diff --git "a/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" "b/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" new file mode 100644 index 0000000..fee4309 --- /dev/null +++ "b/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" @@ -0,0 +1,57 @@ +package `DP 부수기` + +import java.util.* +import java.io.* +import java.lang.StringBuilder + +/* + memoization을 활용하여 최적화, + 재귀로 구현 -> + [동전의 가치][선택한 횟수(재귀의 깊이)] + 해당 깊이에서 해당 동전의 가치를 선택했을 경우에 만들어지는 금액, (가지 치기를 할 수 있다) + + ⭐ 이 문제는 재귀로는 풀 수 없는 문제이다 ⭐ + 메모리 제한으로 인해서 2차원 배열을 만들 수 없기 때문에 재귀로는 풀 수 없는 문제이다 + 따라서 Bottom Up의 방법으로만 문제를 풀 수 있다. + memo[j - 동전의 가치]를 생각해내는게 이 문제의 포인트임 + */ + +private var N = 0 +private var K = 0 + +// 동전을 선택한 횟수에서 만들어진 금액 +//private val memo = Array(10_001) { IntArray(100_000) { -1 } } +private val memo = IntArray(10_001) +private val money = IntArray(101) + +fun main() { + val path = "C:\\Users\\Samsung\\Desktop\\코틀린 알고리즘\\src\\main\\kotlin\\DP 부수기\\res\\2293.txt" + val br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + val sb = StringBuilder() + + val st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() // 동전의 개수 + K = st.nextToken().toInt() // 목표 + + for (i in 1..N) { + money[i] = br.readLine().toInt() + } + + memo[0] = 1 + DP() + sb.append(memo[K]) + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun DP() { + for (i in 1..N) { + for (j in 0..K) { + if (j - money[i] >= 0) { + memo[j] += memo[j - money[i]] + } + } + } +} // End of DP From 344817842782a0f9c68cac8c2c2e36a6ff9e5ce3 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 8 Jan 2023 17:07:24 +0900 Subject: [PATCH 494/822] complete --- ...4\353\241\234 \355\221\234\355\230\204.kt" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" diff --git "a/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" "b/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" new file mode 100644 index 0000000..4bede14 --- /dev/null +++ "b/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" @@ -0,0 +1,49 @@ +package `DP 부수기` + +import java.io.* +import java.util.* + +private var result = Int.MAX_VALUE +private var M = 0 + +fun main() { + val N = 5 + val number = 12 + println(solution(N, number)) + +} // End of main + +private fun solution(N: Int, number: Int): Int { + M = N + + DFS(0, number, 0) + + if (result == Int.MAX_VALUE) { + return -1 + } + + return result +} // End of solution + +private fun DFS(depth: Int, number: Int, total: Int) { + if (depth > 8) { + return + } + + if (number == total) { + result = Math.min(depth, result) + return + } + + var temp = 0 + for (i in 0 until 8) { + if (depth + i < 8) { + temp = temp * 10 + M + + DFS(depth + i + 1, number, total + temp) + DFS(depth + i + 1, number, total - temp) + DFS(depth + i + 1, number, total / temp) + DFS(depth + i + 1, number, total * temp) + } + } +} // End of DFS From 43a2e0829d062113d2371a75a040c0035c04eece Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 9 Jan 2023 20:06:06 +0900 Subject: [PATCH 495/822] kihun --- ...74\353\241\234\355\221\234\355\230\204.py" | 32 ++++++++++++ ...244\200_2293_\353\217\231\354\240\2041.py" | 49 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 "01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" create mode 100644 "01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" diff --git "a/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" "b/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" new file mode 100644 index 0000000..97752ad --- /dev/null +++ "b/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" @@ -0,0 +1,32 @@ +def solution(N, number): + answer = -1 + # dp = [[0개로 만든 수], [1개로 만든 수], ... [8개로 만든 수]] + dp = [[]] + + # number가 자기 자신이면 1 + if N == number: + return 1 + # i == N의 개수 + for i in range(1, 9): + temp = [] + + # 숫자 붙이기 + temp.append(int(str(N) * i)) + + for j in range(1, i): + for k in dp[j]: + for l in dp[i - j]: + temp.append(k+l) + temp.append(k-l) + temp.append(k*l) + if l != 0: + temp.append(k // l) + if number in temp: + return i + dp.append(list(set(temp))) + + return answer + + +# number에서 시작해서 N을 만드는 방법? -> 실패 +# ex) dp[4] = [dp[1], dp[3] 연산] + [dp[2], dp[2] 연산] + [dp[3], dp[1] 연산] diff --git "a/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" "b/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" new file mode 100644 index 0000000..39a363d --- /dev/null +++ "b/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" @@ -0,0 +1,49 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, k = map(int, input().split()) +coin = [] +# dp[i]는 i원을 만드는 경우의 수 +dp = [0 for _ in range(k+1)] +dp[0] = 1 + +for _ in range(n): + coin.append(int(input())) +coin.sort() + +for c in coin: + # i원이 c원보다 크다면 + for i in range(k+1): + if i >= c: + dp[i] += dp[i-c] + +print(dp[k]) + +# 메모리 초과 +# def dfs(index, money): +# global count +# if index == n: +# if money == 0: +# count += 1 +# return + +# nowCoin = coin[index] +# divisor = money // nowCoin + +# for i in range(divisor, -1, -1): +# moneyLeft = money - nowCoin * i +# if moneyLeft >= 0: +# dfs(index+1, moneyLeft) + + +# n, k = map(int, input().split()) +# coin = [] +# count = 0 +# for _ in range(n): +# coin.append(int(input())) +# coin.sort(reverse=True) + +# dfs(0, k) + +# print(count) From 0c2a4417a713cb601aea1c01c2bc7e30b73c419d Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:00:22 +0900 Subject: [PATCH 496/822] =?UTF-8?q?Create=20N=EC=9C=BC=EB=A1=9C=ED=91=9C?= =?UTF-8?q?=ED=98=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\241\234\355\221\234\355\230\204.java" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" diff --git "a/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" "b/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" new file mode 100644 index 0000000..04d2e9e --- /dev/null +++ "b/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" @@ -0,0 +1,37 @@ +import java.util.*; + +class Solution { + public int solution(int N, int number) { + List> setList = new ArrayList<>(); + + for (int i = 0; i < 9; i++) + setList.add(new HashSet<>()); + setList.get(1).add(N); + if (number == N) + return 1; + for (int i = 2; i < 9; i++) { + for (int j = 1; j <= i / 2; j++) { + unionSet(setList.get(i), setList.get(i - j), setList.get(j)); + unionSet(setList.get(i), setList.get(j), setList.get(i - j)); + } + String n = Integer.toString(N); + setList.get(i).add(Integer.parseInt(n.repeat(i))); //연속된 숫자 넣기 + for (int num : setList.get(i)) + if (num == number) + return i; + } + return -1; + } + + public void unionSet(Set union, Set a, Set b) { + for (int n1 : a) { + for (int n2 : b) { + union.add(n1 + n2); + union.add(n1 - n2); + union.add(n1 * n2); + if (n2 != 0) + union.add(n1 / n2); + } + } + } +} From 0fb732e3b1af111afac8331dd0e14b91e24f0b0a Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:00:48 +0900 Subject: [PATCH 497/822] =?UTF-8?q?Create=20=EB=8F=99=EC=A0=841.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\217\231\354\240\2041.java" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" diff --git "a/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" "b/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" new file mode 100644 index 0000000..13dfa1b --- /dev/null +++ "b/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" @@ -0,0 +1,26 @@ +package baekjoon; + +import java.io.*; +import java.util.*; + +public class 동전1_293 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + int[] dp = new int[k + 1]; + for (int t = 0; t < n; t++) { + int coin = Integer.parseInt(br.readLine()); + for (int i = 1; i <= k; i++) { + if (i - coin > 0) { + dp[i] = dp[i] + dp[i - coin]; + } else if (i - coin == 0) { + dp[i]++; + } + } + } + System.out.print(dp[k]); + } + +} From 61293702c1e5c1695a7fb4ac62a6d81bbb886cdb Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 12 Jan 2023 21:15:53 +0900 Subject: [PATCH 498/822] solve --- .../\355\224\274\353\241\234\353\217\204.kt" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "2023/01.16/\354\241\260\354\210\230\354\227\260/\355\224\274\353\241\234\353\217\204.kt" diff --git "a/2023/01.16/\354\241\260\354\210\230\354\227\260/\355\224\274\353\241\234\353\217\204.kt" "b/2023/01.16/\354\241\260\354\210\230\354\227\260/\355\224\274\353\241\234\353\217\204.kt" new file mode 100644 index 0000000..0449b74 --- /dev/null +++ "b/2023/01.16/\354\241\260\354\210\230\354\227\260/\355\224\274\353\241\234\353\217\204.kt" @@ -0,0 +1,49 @@ +package com.ssafy.algorithm + +import java.util.* +import kotlin.collections.ArrayList + +fun main() { + val sl = Solution() + val k = 80 + val dungeons = arrayOf(intArrayOf(80, 20), intArrayOf(50, 40), intArrayOf(30, 10)) + println(sl.solution(k, dungeons)) +} + + +class Solution { + lateinit var visited: BooleanArray //중복 체크 + var max = Integer.MIN_VALUE + fun solution(k: Int, dungeons: Array): Int { + var answer: Int = -1 + visited = BooleanArray(dungeons.size) + combination(0, 0, k, dungeons) + answer = max + return answer + } + + fun combination(size: Int, count: Int, k: Int, dungeons: Array) { //조합 뽑기 + if (size == visited.size) { + max = Math.max(max, count) + return + } + + for (i in visited.indices) { + if (k >= dungeons[i][0]) { //최소 피로도를 만족했을 때 + if (!visited[i]) { + visited[i] = true + combination(size + 1, count + 1, k - dungeons[i][1], dungeons) + visited[i] = false + } + }else{ //최소피로도를 만족하지 못하였을 때 + if (!visited[i]){ + visited[i] = true + combination(size+1,count,k,dungeons) + visited[i] = false + } + } + } + } +} + + From 8ff00528b8a233d1d34a10882446f374b3ec2c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 14 Jan 2023 14:47:03 +0900 Subject: [PATCH 499/822] =?UTF-8?q?Create=20=ED=94=BC=EB=A1=9C=EB=8F=84.cp?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\224\274\353\241\234\353\217\204.cpp" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "2023/01.16/\354\235\264\354\225\204\353\246\204/\355\224\274\353\241\234\353\217\204.cpp" diff --git "a/2023/01.16/\354\235\264\354\225\204\353\246\204/\355\224\274\353\241\234\353\217\204.cpp" "b/2023/01.16/\354\235\264\354\225\204\353\246\204/\355\224\274\353\241\234\353\217\204.cpp" new file mode 100644 index 0000000..ec06e01 --- /dev/null +++ "b/2023/01.16/\354\235\264\354\225\204\353\246\204/\355\224\274\353\241\234\353\217\204.cpp" @@ -0,0 +1,23 @@ +#include +#include +#include + +using namespace std; + +int maxCount = 0; +void bfs(int k, int count, vector& visited, vector>& dungeons) { + for (int i = 0; i < dungeons.size(); i++) { + if (!visited[i] && k >= dungeons[i][0]) { + visited[i] = true; + bfs(k - dungeons[i][1], count + 1, visited, dungeons); + visited[i] = false; + } + } + maxCount = max(maxCount, count); +} + +int solution(int k, vector> dungeons) { + vector visited(dungeons.size(),false); + bfs(k, 0, visited, dungeons); + return maxCount; +} From e1431c1a6fafd46d72bad80161db28dea2170630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:18:21 +0900 Subject: [PATCH 500/822] =?UTF-8?q?Create=2012904=5FA=EC=99=80B.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../12904_A\354\231\200B.cpp" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "2023/01.16/\354\235\264\354\225\204\353\246\204/12904_A\354\231\200B.cpp" diff --git "a/2023/01.16/\354\235\264\354\225\204\353\246\204/12904_A\354\231\200B.cpp" "b/2023/01.16/\354\235\264\354\225\204\353\246\204/12904_A\354\231\200B.cpp" new file mode 100644 index 0000000..6d8c019 --- /dev/null +++ "b/2023/01.16/\354\235\264\354\225\204\353\246\204/12904_A\354\231\200B.cpp" @@ -0,0 +1,31 @@ +#include +#include +#include +using namespace std; + +bool solution(string S, string T) { + if (S.size() >= T.size()) { + if (S.compare(T) == 0) return true; + return false; + } + char back = T[T.size() - 1]; + T = T.substr(0, T.size() - 1); + if (back == 'B') { + string tmp = ""; + for (int i = T.size() - 1; i >= 0; i--) { + tmp += T[i]; + } + T = tmp; + } + return solution(S, T); +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); cout.tie(NULL); + + string S, T; + cin >> S >> T; + cout << solution(S, T) << endl; + return 0; +} From 860d9e776bd3e40bb3229ce7f5922e207a7c432c Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 15 Jan 2023 21:00:54 +0900 Subject: [PATCH 501/822] ./01.09 -> ./2023/01.09 --- {01.09 => 2023/01.09}/readme.md | 0 .../pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" | 0 .../\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" | 0 .../N\354\234\274\353\241\234\355\221\234\355\230\204.java" | 0 .../\353\217\231\354\240\2041.java" | 0 .../\353\217\231\354\240\204_1.kt" | 0 .../Main 2293 \353\217\231\354\240\204 1.kt" | 0 .../PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename {01.09 => 2023/01.09}/readme.md (100%) rename "01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" => "2023/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" (100%) rename "01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" => "2023/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" (100%) rename "01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" => "2023/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" (100%) rename "01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" => "2023/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" (100%) rename "01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" => "2023/01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" (100%) rename "01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" => "2023/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" (100%) rename "01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" => "2023/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" (100%) diff --git a/01.09/readme.md b/2023/01.09/readme.md similarity index 100% rename from 01.09/readme.md rename to 2023/01.09/readme.md diff --git "a/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" "b/2023/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" similarity index 100% rename from "01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" rename to "2023/01.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_N\354\234\274\353\241\234\355\221\234\355\230\204.py" diff --git "a/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" "b/2023/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" similarity index 100% rename from "01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" rename to "2023/01.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2293_\353\217\231\354\240\2041.py" diff --git "a/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" "b/2023/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" similarity index 100% rename from "01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" rename to "2023/01.09/\354\240\225\355\230\270\354\241\260/N\354\234\274\353\241\234\355\221\234\355\230\204.java" diff --git "a/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" "b/2023/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" similarity index 100% rename from "01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" rename to "2023/01.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2041.java" diff --git "a/01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" "b/2023/01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" similarity index 100% rename from "01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" rename to "2023/01.09/\354\241\260\354\210\230\354\227\260/\353\217\231\354\240\204_1.kt" diff --git "a/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" "b/2023/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" similarity index 100% rename from "01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" rename to "2023/01.09/\354\265\234\354\260\275\354\230\201/Main 2293 \353\217\231\354\240\204 1.kt" diff --git "a/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" "b/2023/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" similarity index 100% rename from "01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" rename to "2023/01.09/\354\265\234\354\260\275\354\230\201/PRG N\354\234\274\353\241\234 \355\221\234\355\230\204.kt" From 37d1754316241eafcdcb297f1cfdade68bc59c9a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 15 Jan 2023 21:02:24 +0900 Subject: [PATCH 502/822] kihun --- ...2_\355\224\274\353\241\234\353\217\204.py" | 23 ++++++++++ ...0\261\354\244\200_12904_A\354\231\200B.py" | 46 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 "2023/01.16/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\355\224\274\353\241\234\353\217\204.py" create mode 100644 "2023/01.16/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12904_A\354\231\200B.py" diff --git "a/2023/01.16/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\355\224\274\353\241\234\353\217\204.py" "b/2023/01.16/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\355\224\274\353\241\234\353\217\204.py" new file mode 100644 index 0000000..755fd91 --- /dev/null +++ "b/2023/01.16/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\355\224\274\353\241\234\353\217\204.py" @@ -0,0 +1,23 @@ +answer = 0 +num = 0 + + +def dfs(nowPiro, depth, dungeons, visited): + global answer + if depth > answer: + answer = depth + + for i in range(num): + if nowPiro >= dungeons[i][0] and not visited[i]: + visited[i] = True + dfs(nowPiro - dungeons[i][1], depth+1, dungeons, visited) + visited[i] = False + + +def solution(k, dungeons): + global num + num = len(dungeons) + visited = [False for _ in range(num)] + dfs(k, 0, dungeons, visited) + + return answer diff --git "a/2023/01.16/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12904_A\354\231\200B.py" "b/2023/01.16/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12904_A\354\231\200B.py" new file mode 100644 index 0000000..4dbb25d --- /dev/null +++ "b/2023/01.16/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12904_A\354\231\200B.py" @@ -0,0 +1,46 @@ +import sys + +sys.stdin = open('input.txt', 'r', encoding='UTF-8') + + +S = list(input()) +T = list(input()) + +# T에서 S로 가는 경우 +# 1. A 떼기 +# 2. B 떼고 뒤집기 +answer = 0 +while T: + if T[-1] == 'A': + T.pop() + else: + T.pop() + T = T[::-1] + + if S == T: + answer = 1 + break + +print(answer) + +# 메모리 초과 +# def bfs(): +# target = len(T) +# q = deque() +# q.append(S) + +# while q: +# temp = q.popleft() +# if len(temp) == target: +# if temp == T: +# return 1 +# else: +# # A 추가하기 +# q.append(temp+'A') +# # 뒤집고 B 추기하기 +# q.append(temp[::-1]+'B') + +# return 0 + + +# print(bfs()) From c22a9156951f6aecb6c83786bc4b8c89fc517295 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Mon, 16 Jan 2023 00:01:52 +0900 Subject: [PATCH 503/822] complete --- .../Main 12904 A\354\231\200 B.kt" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "2023/01.16/\354\265\234\354\260\275\354\230\201/Main 12904 A\354\231\200 B.kt" diff --git "a/2023/01.16/\354\265\234\354\260\275\354\230\201/Main 12904 A\354\231\200 B.kt" "b/2023/01.16/\354\265\234\354\260\275\354\230\201/Main 12904 A\354\231\200 B.kt" new file mode 100644 index 0000000..c4e02e4 --- /dev/null +++ "b/2023/01.16/\354\265\234\354\260\275\354\230\201/Main 12904 A\354\231\200 B.kt" @@ -0,0 +1,52 @@ +package `문자열 부수기` + +/* + S를 T로 바꿀 수 있으면 1을 없으면 0을 출력한다. + */ + +import java.util.* +import java.io.* + +fun main() { + val path = "C:\\Users\\Samsung\\Desktop\\코틀린 알고리즘\\src\\main\\kotlin\\문자열 부수기\\res\\12904.txt" + val br = BufferedReader(File(path).bufferedReader()) + + val S = br.readLine() + val T = br.readLine() + + val sList = LinkedList() + for (i in S.indices) { + sList.add(S[i]) + } + + val tList = LinkedList() + for (i in T.indices) { + tList.add(T[i]) + } + + while (sList.size < tList.size) { + if (tList[tList.size - 1] == 'A') { + tList.removeAt(tList.size - 1) + } else if (tList[tList.size - 1] == 'B') { + tList.removeAt(tList.size - 1) + tList.reverse() + } + } + + var sStr = "" + sList.forEach { + sStr += it + } + + var tStr = "" + tList.forEach { + tStr += it + } + + + if (sStr == tStr) { + println(1) + } else { + println(0) + } +} // End of main \ No newline at end of file From e45be14d1e6fe843e08616d83085df526487d6ef Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 16 Jan 2023 02:47:58 +0900 Subject: [PATCH 504/822] =?UTF-8?q?Create=20A=EC=99=80B.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../A\354\231\200B.java" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "2023/01.16/\354\240\225\355\230\270\354\241\260/A\354\231\200B.java" diff --git "a/2023/01.16/\354\240\225\355\230\270\354\241\260/A\354\231\200B.java" "b/2023/01.16/\354\240\225\355\230\270\354\241\260/A\354\231\200B.java" new file mode 100644 index 0000000..c9e6f43 --- /dev/null +++ "b/2023/01.16/\354\240\225\355\230\270\354\241\260/A\354\231\200B.java" @@ -0,0 +1,31 @@ +package baekjoon; + +import java.util.*; +import java.io.*; +public class A와B_12904 { + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String s = br.readLine(); + String t = br.readLine(); + + int ans = 0; + + while(t.length() > s.length()) { + StringBuilder sb = new StringBuilder(); + + if(t.equals(s)) { + ans = 1; + break; + } + if(t.charAt(t.length()-1) == 'A') { + t = t.substring(0, t.length()-1); + } else if(t.charAt(t.length()-1) == 'B') { + t = t.substring(0,t.length()-1); + t = sb.append(t).reverse().toString(); + } + } + + System.out.println(ans); + } +} From 66d21fbc0d62598fdb6f0cc681c42f54a48cf0ff Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 16 Jan 2023 20:57:21 +0900 Subject: [PATCH 505/822] solve --- .../A\354\231\200 B.kt" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "2023/01.16/\354\241\260\354\210\230\354\227\260/A\354\231\200 B.kt" diff --git "a/2023/01.16/\354\241\260\354\210\230\354\227\260/A\354\231\200 B.kt" "b/2023/01.16/\354\241\260\354\210\230\354\227\260/A\354\231\200 B.kt" new file mode 100644 index 0000000..d897d9e --- /dev/null +++ "b/2023/01.16/\354\241\260\354\210\230\354\227\260/A\354\231\200 B.kt" @@ -0,0 +1,41 @@ +package com.ssafy.algorithm + +import java.io.BufferedReader +import java.io.InputStreamReader + +fun main() { + + val br = BufferedReader(InputStreamReader(System.`in`)) + + var S = br.readLine() + var T = br.readLine() + + var answer = 0 + + for (i in T.indices) { + val c = T.last() + T = T.substring(0,T.length-1) + + // c가 B인 경우에는 자른 문자열을 뒤집어준다. + if(c == 'B'){ + val sb = StringBuilder(T) + T = sb.reverse().toString() + } + + //두 문자열 비교 + if (S.length == T.length){ + if (S.equals(T)) answer = 1 + break + } + } + + println(answer) + +} + + + + + + + From e541e7d1c08befca35f14cdd8b555b4d063cb500 Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Mon, 16 Jan 2023 21:14:29 +0900 Subject: [PATCH 506/822] Create README.md --- 2023/01.16/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/01.16/README.md diff --git a/2023/01.16/README.md b/2023/01.16/README.md new file mode 100644 index 0000000..71156ea --- /dev/null +++ b/2023/01.16/README.md @@ -0,0 +1,5 @@ +# 1.16(월) 스터디 + +백준 : [A와 B](https://www.acmicpc.net/problem/12904) + +프로그래머스 : [피로도](https://school.programmers.co.kr/learn/courses/30/lessons/87946) From b48e7956bab7fc4f7780a4a692ddc8434c34abf9 Mon Sep 17 00:00:00 2001 From: Kihun SONG <87517193+sindorim5@users.noreply.github.com> Date: Mon, 16 Jan 2023 21:17:47 +0900 Subject: [PATCH 507/822] Create README.md --- 2023/01.30/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 2023/01.30/README.md diff --git a/2023/01.30/README.md b/2023/01.30/README.md new file mode 100644 index 0000000..a7ef387 --- /dev/null +++ b/2023/01.30/README.md @@ -0,0 +1,8 @@ +# 1.30(월) 스터디 + +- 백준 + - [DFS 스페셜 저지](https://www.acmicpc.net/problem/16964) + - [저울](https://www.acmicpc.net/problem/2437) + +- 프로그래머스 + - [주차 요금 계산](https://school.programmers.co.kr/learn/courses/30/lessons/92341) From 971c803ed320a0d46f8dcc3163a67d4b12098e5f Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 30 Jan 2023 18:52:11 +0900 Subject: [PATCH 508/822] kihun --- ...24\352\270\210\352\263\204\354\202\260.py" | 60 +++++++++++++++++++ ...30\354\205\234\354\240\200\354\247\200.py" | 45 ++++++++++++++ ...\244\200_2437_\354\240\200\354\232\270.py" | 47 +++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 "2023/01.30/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.py" create mode 100644 "2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16964_DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.py" create mode 100644 "2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2437_\354\240\200\354\232\270.py" diff --git "a/2023/01.30/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.py" "b/2023/01.30/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.py" new file mode 100644 index 0000000..a05f028 --- /dev/null +++ "b/2023/01.30/\354\206\241\352\270\260\355\233\210/pgm_lvl2_\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.py" @@ -0,0 +1,60 @@ +import math + +fees = [180, 5000, 10, 600] +records = ["05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"] +result = [14600, 34400, 5000] + +# fees = [1, 461, 1, 10] +# records = ["00:00 1234 IN"] +# result = [14841] + +def solution(fees, records): + answer = [] + # 누적 주차 시간을 저장하는 dictionary + times = {} + # 주차장의 들어온 차 번호와 시간을 저장하는 dictionary + park = {} + + # 기본시간, 기본요금, 단위시간, 단위요금 + basicTime, basicFee, unitTime, unitFee = fees + + for record in records: + time, carNumber, inout = record.split() + hour, min = map(int, time.split(":")) + hourToMin = hour * 60 + min + + carNumber = int(carNumber) + + if inout == "IN": + park[carNumber] = hourToMin + elif inout == "OUT": + parkingTime = hourToMin - park[carNumber] + if carNumber in times: + times[carNumber] += parkingTime + else: + times[carNumber] = parkingTime + # 출차되면 삭제 + del(park[carNumber]) + + # 주차장에 남은 차 시간 계산 + for carNumber, time in park.items(): + parkingTime = 23 * 60 + 59 - time + if carNumber in times: + times[carNumber] += parkingTime + else: + times[carNumber] = parkingTime + + # 요금 계산 + for carNumber, time in times.items(): + fee = basicFee + if time > basicTime: + time -= basicTime + fee = basicFee + math.ceil(time / unitTime) * unitFee + times[carNumber] = fee + times = sorted(times.items(), key= lambda item: item[0]) + + for time in times: + answer.append(time[1]) + return answer + +print(solution(fees, records)) diff --git "a/2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16964_DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.py" "b/2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16964_DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.py" new file mode 100644 index 0000000..e68c9e7 --- /dev/null +++ "b/2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16964_DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.py" @@ -0,0 +1,45 @@ +import sys +from collections import deque + +sys.stdin = open("01.30/input.txt", "r", encoding="UTF-8") + +n = int(input()) +graph = [[] for _ in range(n+1)] +visited = [False for _ in range(n+1)] +answer = -1 + +for _ in range(n-1): + x, y = map(int, input().split()) + graph[x].append(y) + graph[y].append(x) + +q = deque(map(int, input().split())) + +def dfs(queue): + global answer + nowNum = queue.popleft() + if not queue: + answer = 1 + print("out") + return + visited[nowNum] = True + for i in range(len(graph[nowNum])): + # queue가 없을 때 값을 꺼내다가 index 에러가 생김 + if queue: + nextNum = queue[0] + else: + continue + # 연결된 노드이고 방문하지 않았는가? + if nextNum in graph[nowNum] and not visited[nextNum]: + print("go") + dfs(queue) + if answer != 1: + answer = 0 + return + +# 시작이 1이 아니면 오답 +if q[0] != 1: + print(0) +else: + dfs(q) + print(answer) diff --git "a/2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2437_\354\240\200\354\232\270.py" "b/2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2437_\354\240\200\354\232\270.py" new file mode 100644 index 0000000..81d26e7 --- /dev/null +++ "b/2023/01.30/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2437_\354\240\200\354\232\270.py" @@ -0,0 +1,47 @@ +import sys + +sys.stdin = open("01.30/input.txt", "r", encoding="UTF-8") + +n = int(input()) +numbers = list(map(int, input().split())) +numbers.sort() + +max = 1 +for num in numbers: + if max < num: + break + max += num + +print(max) + + +# 시간 초과 +# def combination(target): +# resultSet = set() + +# def combi(idx, nowCombi): +# if len(nowCombi) == target: +# resultSet.add(sum(nowCombi)) +# return +# for i in range(idx, n): +# combi(i+1, nowCombi+[numbers[i]]) + +# combi(0, []) +# return resultSet + +# sumSet = set() +# for i in range(1, n+1): +# tempSet = combination(i) +# sumSet = sumSet | tempSet + +# sumList = list(sumSet) +# sumList.sort() + +# length = len(sumList) +# i = 0 +# while i < length-1: + # if sumList[i+1] - sumList[i] == 1: + # i += 1 + # else: + # print(sumList[i]+1) + # break From 1b3bd4cc7acfebbf29113fa0047943c5a7b8bce9 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:52:01 +0900 Subject: [PATCH 509/822] =?UTF-8?q?Create=20=EC=A0=80=EC=9A=B8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\240\200\354\232\270.java" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "2023/01.30/\355\230\270\354\241\260zi\354\241\264123/\354\240\200\354\232\270.java" diff --git "a/2023/01.30/\355\230\270\354\241\260zi\354\241\264123/\354\240\200\354\232\270.java" "b/2023/01.30/\355\230\270\354\241\260zi\354\241\264123/\354\240\200\354\232\270.java" new file mode 100644 index 0000000..8a78cb9 --- /dev/null +++ "b/2023/01.30/\355\230\270\354\241\260zi\354\241\264123/\354\240\200\354\232\270.java" @@ -0,0 +1,36 @@ +package baekjoon; + +import java.util.*; +import java.io.*; + +public class 저울_2437 { + static int n, ans; + static int[] weight; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + n = Integer.parseInt(br.readLine()); + weight = new int[n]; + + st = new StringTokenizer(br.readLine()); + for (int i=0; i Date: Mon, 30 Jan 2023 20:52:28 +0900 Subject: [PATCH 510/822] =?UTF-8?q?Create=20DFS=EC=8A=A4=ED=8E=98=EC=85=9C?= =?UTF-8?q?=EC=A0=80=EC=A7=80.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\205\234\354\240\200\354\247\200.java" | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 "2023/01.30/\355\230\270\354\241\260zi\354\241\264123/DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.java" diff --git "a/2023/01.30/\355\230\270\354\241\260zi\354\241\264123/DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.java" "b/2023/01.30/\355\230\270\354\241\260zi\354\241\264123/DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.java" new file mode 100644 index 0000000..a6db3af --- /dev/null +++ "b/2023/01.30/\355\230\270\354\241\260zi\354\241\264123/DFS\354\212\244\355\216\230\354\205\234\354\240\200\354\247\200.java" @@ -0,0 +1,76 @@ +package baekjoon; + +import java.util.*; +import java.io.*; + +public class dfs스페셜저지_16964 { + + static ArrayList> numList; + static boolean[] vis; + static int[] num; + static boolean ans; + static int N, index; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + vis = new boolean[N + 1]; + num = new int[N]; + ans = true; + index = 1; + + numList = new ArrayList<>(); + for(int i = 0 ; i <= N ; ++i) { + numList.add(new ArrayList<>()); + } + + for(int i = 0 ; i < N - 1 ; ++i) { + st = new StringTokenizer(br.readLine()); + int node = Integer.parseInt(st.nextToken()); + int value = Integer.parseInt(st.nextToken()); + + numList.get(node).add(value); + numList.get(value).add(node); + } + + st = new StringTokenizer(br.readLine()); + for(int i = 0 ; i < N ; ++i) { + num[i] = Integer.parseInt(st.nextToken()); + } + + dfs(1); + + if(ans) { + System.out.println(1); + } else { + System.out.println(0); + } + + } + + private static void dfs(int idx) { + if(vis[idx]) { + return; + } + + vis[idx] = true; + + HashSet set = new HashSet<>(); + for(int nextNum : numList.get(idx)) { + if(vis[nextNum]) continue; + set.add(nextNum); + } + + if(set.size() == 0) { + return; + } + + if(set.contains(num[index])) { + dfs(num[index++]); + } else { + ans = false; + } + } +} From 4aac9aa6bfb763a82512590f3c81bc4aa05b3c91 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 23 Feb 2023 20:43:39 +0900 Subject: [PATCH 511/822] Create 20230303 README.md --- 2023/03.03/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 2023/03.03/README.md diff --git a/2023/03.03/README.md b/2023/03.03/README.md new file mode 100644 index 0000000..32799ea --- /dev/null +++ b/2023/03.03/README.md @@ -0,0 +1,6 @@ +# 3.3(금) 스터디 + +- 프로그래머스 + - [이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628) + - [혼자 놀기의 달인](https://school.programmers.co.kr/learn/courses/30/lessons/131130) + - [N-Queen](https://school.programmers.co.kr/learn/courses/30/lessons/12952) \ No newline at end of file From 5640b41523b9ffc563977765efc2a6c5db1dd6c1 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 23 Feb 2023 21:28:28 +0900 Subject: [PATCH 512/822] =?UTF-8?q?ADD=20:=20N-Queen=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N_Queen.kt" | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 "2023/03.03/\354\241\260\354\210\230\354\227\260/N_Queen.kt" diff --git "a/2023/03.03/\354\241\260\354\210\230\354\227\260/N_Queen.kt" "b/2023/03.03/\354\241\260\354\210\230\354\227\260/N_Queen.kt" new file mode 100644 index 0000000..a7d7170 --- /dev/null +++ "b/2023/03.03/\354\241\260\354\210\230\354\227\260/N_Queen.kt" @@ -0,0 +1,134 @@ +package com.ssafy.algorithm + + + +fun main() { + val sl = Solution() + val n = 24 + println(sl.solution(n)) +} + +class Solution { + var answer = 0 + lateinit var visited: Array + fun solution(n: Int): Int { + + if (n == 1) answer = 1 + else if (n == 2 || n == 3) answer = 0 + else { + visited = Array(n) { BooleanArray(n) { false } } + nQueen(0, n) + } + + return answer + } + + fun nQueen(size: Int, n: Int) { + if (size == n) { //size를 만족하면 nQueen을 만족하므로 ++ + answer++ + return + } + + for (i in 0 until n) { + if (size == 0) { //첫번째 인덱스는 고려할 필요 없음 + visited[size][i] = true + nQueen(size + 1, n) + visited[size][i] = false + } else { //행 열 대각선 비교 + if (colCheck(size, i) && rowCheck(size, i) && crossCheck(size, i)) { + visited[size][i] = true + nQueen(size + 1, n) + visited[size][i] = false + } + } + } + } + + fun colCheck(row: Int, col: Int): Boolean { //열 체크 + var i = 1 + while (true) { //왼쪽 체크 + if (col - i < 0) break + if (col - i >= 0) { + if (visited[row][col - i]) return false + } + i++ + } + + i = 1 + while (true) { //오른쪽 체크 + if (col + i >= visited.size) break + if (col + i < visited.size) { + if (visited[row][col + i]) return false + } + i++ + } + return true + } + + fun rowCheck(row: Int, col: Int): Boolean { //행 체크 + var i = 1 + while (true) { //위쪽 체크 + if (row - i < 0) break + if (row - i >= 0) { + if (visited[row - i][col]) return false + } + i++ + } + + i = 1 + while (true) { //아래쪽 체크 + if (row + i >= visited.size) break + if (row + i < visited.size) { + if (visited[row + i][col]) return false + } + i++ + } + return true + } + + fun crossCheck(row: Int, col: Int): Boolean { + var i = 1 + while (true) { //오른쪽 아래 대각선 체크 + if (i + row >= visited.size && i + col >= visited.size) break + + if (row + i < visited.size && col + i < visited.size) { + if (visited[row + i][col + i]) return false + } + i++ + } + + i = 1 + while (true) { //왼쪽 위 대각선 체크 + if (row - i < 0 && col - i < 0) break + + if (row - i >= 0 && col - i >= 0) { + if (visited[row - i][col - i]) return false + } + i++ + } + + i = 1 + while (true) { //오른쪽 위 대각선 체크 + if (row - i < 0 && col + i >= visited.size) break + + if (row - i >= 0 && col + i < visited.size) { + if (visited[row - i][col + i]) return false + } + i++ + } + + i = 1 + while (true) { //왼쪽 아래 대각선 체크 + if (row + i >= visited.size && col - i < 0) break + + if (row + i < visited.size && col - i >= 0) { + if (visited[row + i][col - i]) return false + } + i++ + } + + return true + } +} + + From a5f13b8af98643b55b9f1be23651a49109596b89 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 23 Feb 2023 22:28:24 +0900 Subject: [PATCH 513/822] =?UTF-8?q?ADD=20:=20=ED=98=BC=EC=9E=90=20?= =?UTF-8?q?=EB=86=80=EA=B8=B0=EC=9D=98=20=EB=8B=AC=EC=9D=B8=20Kotlin=20sol?= =?UTF-8?q?ve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\230_\353\213\254\354\235\270.kt" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.kt" diff --git "a/2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.kt" "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.kt" new file mode 100644 index 0000000..ac2ba34 --- /dev/null +++ "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.kt" @@ -0,0 +1,34 @@ + +fun main(){ + val cards = intArrayOf(8,6,3,7,2,5,1,4) + Solution().solution(cards) +} + +class Solution { + fun solution(cards: IntArray): Int { + val checked = BooleanArray(cards.size) //카드 뽑기 중복 체크 배열 + val boxes = ArrayList>() + var bIndex = 0 //박스 인덱스 + + for (i in cards.indices){ + boxes.add(ArrayList()) + } + + for (i in cards.indices){ + if (!checked[i]){ + var cIndex = i //첫번째 카드 위치 + while (true){ + if (checked[cIndex]) break //이미 열려있는 상자인 경우 break + checked[cIndex] = true + boxes[bIndex].add(cards[cIndex]) + cIndex = cards[cIndex]-1 + } + bIndex++ + } + } + + boxes.sortByDescending { it.size } //길이 기준으로 내림차순 정렬 + + return boxes[0].size * boxes[1].size + } +} From a0e0a01f750fd654b89d015caf50c3ebc34cad5a Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 23 Feb 2023 22:41:23 +0900 Subject: [PATCH 514/822] =?UTF-8?q?SOLVE=20:=20=ED=98=BC=EC=9E=90=20?= =?UTF-8?q?=EB=86=80=EA=B8=B0=EC=9D=98=20=EB=8B=AC=EC=9D=B8=20Java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\235\230_\353\213\254\354\235\270.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" diff --git "a/2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" new file mode 100644 index 0000000..4bf9aef --- /dev/null +++ "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.Collections; + +public class Problem { + public static void main(String[] args) { + int[] cards = {8,6,3,7,2,5,1,4}; + new SolutionJava().solution(cards); + } +} + +class SolutionJava { + public int solution(int[] cards) { + boolean[] checked = new boolean[cards.length]; //카드 뽑기 중복 체크 배열 + ArrayList> boxes = new ArrayList<>(); //카드 상자 그룹 + int bIndex = 0; //박스 그룹 인덱스 + + for (int i = 0; i < cards.length; i++){ + boxes.add(new ArrayList<>()); + } + + for (int i = 0; i < cards.length; i++) { + if (!checked[i]){ + int cIndex = i; //뽑는 카드의 인덱스 + while (true){ + if (checked[cIndex]) break; //이미 열려있는 상자인 경우 다음 그룹으로 넘어가기 + checked[cIndex] = true; + boxes.get(bIndex).add(cards[cIndex]); + cIndex = cards[cIndex]-1; + } + bIndex++; + } + } + + Collections.sort(boxes,((o1, o2) -> o2.size() - o1.size())); //길이 기준으로 내림차순 정렬 + + return boxes.get(0).size() * boxes.get(1).size(); + } +} + + From 46380f662348fc9705338f9c9eb945ad00c2c69b Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Fri, 24 Feb 2023 10:25:27 +0900 Subject: [PATCH 515/822] =?UTF-8?q?SOLVE=20:=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\204\240\354\210\234\354\234\204.java" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204.java" diff --git "a/2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204.java" "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204.java" new file mode 100644 index 0000000..199d235 --- /dev/null +++ "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204.java" @@ -0,0 +1,48 @@ +import java.util.Collections; +import java.util.PriorityQueue; + +public class Problem { + public static void main(String[] args) { + String[] operations = {"I 16", "I -5643", "D -1", "D 1", "D 1", "I 123", "D -1"}; + new SolutionJava().solution(operations); + } +} + +class SolutionJava { + public int[] solution(String[] operations) { + int[] answer = {}; + PriorityQueue minPq = new PriorityQueue<>(); //오름차순 + PriorityQueue maxPq = new PriorityQueue<>(Collections.reverseOrder()); //내림차순 + + for (String operation : operations) { + String command = operation.split(" ")[0]; //삽입, 삭제 명령어 + int data = Integer.parseInt(operation.split(" ")[1]); + + switch (command) { + case "I": + minPq.offer(data); + maxPq.offer(data); + break; + case "D": + switch (data) { + case 1: + if (!maxPq.isEmpty()) { + minPq.remove(maxPq.peek()); //minPq에서 maxPq.peek 부분도 같이 제거해주기 + maxPq.poll(); + } + break; + case -1: + if (!minPq.isEmpty()) { + maxPq.remove(minPq.peek()); //maxPq에서 minPq.peek 부분도 같이 제거해주기 + minPq.poll(); + } + break; + } + break; + } + } + if (maxPq.isEmpty() && minPq.isEmpty()) answer = new int[]{0, 0}; //큐가 비어있으면 0,0 + else answer = new int[]{maxPq.peek(), minPq.peek()}; + return answer; + } +} From f98ed0911e9e87014b2045287ec8653b1d71af0d Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Fri, 24 Feb 2023 10:25:52 +0900 Subject: [PATCH 516/822] =?UTF-8?q?SOLVE=20:=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\354\210\234\354\234\204\355\201\220.kt" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.kt" diff --git "a/2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.kt" "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.kt" new file mode 100644 index 0000000..ef91dc1 --- /dev/null +++ "b/2023/03.03/\354\241\260\354\210\230\354\227\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.kt" @@ -0,0 +1,44 @@ +import java.util.* + +fun main() { + val operations = arrayOf("I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333") + Solution().solution(operations) +} + +class Solution { + fun solution(operations: Array): IntArray { + var answer: IntArray + val minPq = PriorityQueue() //오름차순 + val maxPq = PriorityQueue(Collections.reverseOrder()) //내림차순 + for (operation in operations) { + val command = operation.split(" ")[0] //삽입, 삭제 명령어 + val data = operation.split(" ")[1].toInt() + + when (command) { + "I" -> { + minPq.offer(data) + maxPq.offer(data) + } + "D" -> { + when (data) { + 1 -> { + if (maxPq.isNotEmpty()) { + minPq.remove(maxPq.peek()) //minPq에서 maxPq.peek 부분도 같이 제거해주기 + maxPq.poll() + } + } + -1 -> { + if (minPq.isNotEmpty()) { + maxPq.remove(minPq.peek()) //maxPq에서 minPq.peek 부분도 같이 제거해주기 + minPq.poll() + } + } + } + } + } + } + if (maxPq.isEmpty() && minPq.isEmpty()) answer = intArrayOf(0, 0) //큐가 비어있으면 0,0 + else answer = intArrayOf(maxPq.peek(), minPq.peek()) + return answer + } +} \ No newline at end of file From 9921510ce58210a33febb1373ee32a0d1714c656 Mon Sep 17 00:00:00 2001 From: RyuSw-cs Date: Mon, 27 Feb 2023 13:53:04 +0900 Subject: [PATCH 517/822] =?UTF-8?q?solve:=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\234\354\234\204\355\201\220.java" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "2023/03.03/\354\234\240\354\212\271\354\232\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" diff --git "a/2023/03.03/\354\234\240\354\212\271\354\232\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" "b/2023/03.03/\354\234\240\354\212\271\354\232\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" new file mode 100644 index 0000000..a32a338 --- /dev/null +++ "b/2023/03.03/\354\234\240\354\212\271\354\232\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" @@ -0,0 +1,54 @@ +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + +class Solution { + + public static void main(String[] args) { + Solution solution = new Solution(); + String[] arr = {"I 16", "I -5643", "D -1", "D 1", "D 1", "I 123", "D -1"}; + System.out.println(Arrays.toString(solution.solution(arr))); + } + + public int[] solution(String[] operations) { + PriorityQueue minQueue = new PriorityQueue<>(); + PriorityQueue maxQueue = new PriorityQueue<>(Comparator.reverseOrder()); + + for (String oper : operations) { + String[] input = oper.split(" "); + int num = Integer.parseInt(input[1]); + switch (input[0]) { + case "I": { + // 큐에 데이터 넣기 + maxQueue.offer(num); + minQueue.offer(num); + break; + } + case "D": { + // 큐에서 최솟값 삭제 + if (!maxQueue.isEmpty() && !minQueue.isEmpty()) { + int deleteNum; + if (num < 0) { + deleteNum = minQueue.peek(); + } + // 큐에서 최대값 삭제 + else { + deleteNum = maxQueue.peek(); + } + minQueue.remove(deleteNum); + maxQueue.remove(deleteNum); + } + break; + } + } + } + int[] answer = new int[2]; + + if(!maxQueue.isEmpty() && !minQueue.isEmpty()){ + answer[0] = maxQueue.peek(); + answer[1] = minQueue.peek(); + } + + return answer; + } +} \ No newline at end of file From 99daa16a1c38a53c1e42f9283c9756da74bd007e Mon Sep 17 00:00:00 2001 From: RyuSw-cs Date: Tue, 28 Feb 2023 09:46:58 +0900 Subject: [PATCH 518/822] =?UTF-8?q?solve:=20=ED=98=BC=EC=9E=90=20=EB=86=80?= =?UTF-8?q?=EA=B8=B0=EC=9D=98=20=EB=8B=AC=EC=9D=B8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\235\230 \353\213\254\354\235\270.java" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "2023/03.03/\354\234\240\354\212\271\354\232\260/\355\230\274\354\236\220 \353\206\200\352\270\260\354\235\230 \353\213\254\354\235\270.java" diff --git "a/2023/03.03/\354\234\240\354\212\271\354\232\260/\355\230\274\354\236\220 \353\206\200\352\270\260\354\235\230 \353\213\254\354\235\270.java" "b/2023/03.03/\354\234\240\354\212\271\354\232\260/\355\230\274\354\236\220 \353\206\200\352\270\260\354\235\230 \353\213\254\354\235\270.java" new file mode 100644 index 0000000..18d94b4 --- /dev/null +++ "b/2023/03.03/\354\234\240\354\212\271\354\232\260/\355\230\274\354\236\220 \353\206\200\352\270\260\354\235\230 \353\213\254\354\235\270.java" @@ -0,0 +1,26 @@ +import java.util.*; + +class Solution { + public int solution(int[] cards) { + // 방문처리 + boolean[] visited = new boolean[cards.length]; + ArrayList list = new ArrayList<>(); + + for (int i = 0; i < cards.length; i++) { + int pos = i; + int cnt = 0; + // 한 점에서 계속출발 + while (!visited[pos]) { + visited[pos] = true; + pos = cards[pos] - 1; + cnt++; + } + if (cnt > 0) list.add(cnt); + } + list.sort(Collections.reverseOrder()); + + // 카드를 다 뽑았으면 서로 개수를 센다. + if (list.size() > 1) return list.get(0) * list.get(1); + else return 0; + } +} \ No newline at end of file From 3ffc6989809a693a95b177f4366d1e445471a052 Mon Sep 17 00:00:00 2001 From: sindorim5 Date: Wed, 1 Mar 2023 00:08:50 +0900 Subject: [PATCH 519/822] Kihun --- .../pgm_lv2_N-Queen.py" | 23 ++++++++++++ ...60\354\235\230\353\213\254\354\235\270.py" | 37 +++++++++++++++++++ ...40\354\210\234\354\234\204\355\201\220.py" | 29 +++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 "2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_N-Queen.py" create mode 100644 "2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.py" create mode 100644 "2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" diff --git "a/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_N-Queen.py" "b/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_N-Queen.py" new file mode 100644 index 0000000..266faeb --- /dev/null +++ "b/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_N-Queen.py" @@ -0,0 +1,23 @@ +def dfs(nqueen, y, n): + count = 0 + if n == y: + return 1 + for x in range(n): + # (y, x)에 말을 둔다 + nqueen[y] = x + # 0 ~ y까지 체크 + for i in range(y): + # 세로에 있는가? + if nqueen[i] == nqueen[y]: + break + # 대각선에 있는가? + if abs(nqueen[i] - nqueen[y]) == y - i: + break + # break로 탈출하지 않으면 dfs + else: + count += dfs(nqueen, y+1, n) + return count + + +def solution(n): + return dfs([0 for _ in range(n)], 0, n) diff --git "a/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.py" "b/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.py" new file mode 100644 index 0000000..a647a36 --- /dev/null +++ "b/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.py" @@ -0,0 +1,37 @@ +def solution(cards): + answer = 0 + for card in cards: + visited = [False for _ in range(len(cards))] + count_1 = 0 + idx = card + while True: + # False면 True로, count += 1, 도착한 곳을 idx로 + if visited[idx-1] == False: + visited[idx - 1] = True + count_1 += 1 + idx = cards[idx - 1] + else: + break + # 안 뽑힌 카드들 + notSelectedCards = [cards[i] + for i in range(len(cards)) if not visited[i]] + if len(notSelectedCards) == 0: + break + count_2 = 0 + # 안 뽑힌 카드들 중 최고점을 같은 로직으로 찾아보자 + for card in notSelectedCards: + tempCount = 0 + idx = card + while True: + if visited[idx-1] == False: + visited[idx - 1] = True + tempCount += 1 + idx = cards[idx - 1] + else: + count_2 = max(count_2, tempCount) + break + answer = max(answer, count_1 * count_2) + return answer + + +solution([8, 6, 3, 7, 2, 5, 1, 4]) diff --git "a/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" "b/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" new file mode 100644 index 0000000..939ee86 --- /dev/null +++ "b/2023/03.03/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" @@ -0,0 +1,29 @@ +from collections import deque + + +def solution(operations): + answer = [] + q = deque() + for operation in operations: + action, num = operation.split() + if (action == "I"): + q.append(int(num)) + elif (action == "D"): + # if q is not empty + if q: + if (num == "1"): + q.remove(max(q)) + elif (num == "-1"): + q.remove(min(q)) + + # if q is not empty + if q: + answer = [max(q), min(q)] + else: + answer = [0, 0] + return answer + + +print(solution(["I 16", "I -5643", "D -1", "D 1", "D 1", "I 123", "D -1"])) +print(solution(["I -45", "I 653", "D 1", "I -642", + "I 45", "I 97", "D 1", "D -1", "I 333"])) From 69292d5251a5ab73e7e02f6c0cc516337e12a731 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Wed, 1 Mar 2023 11:37:27 +0900 Subject: [PATCH 520/822] complete --- ...\354\210\234\354\234\204\355\201\220.java" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" diff --git "a/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" "b/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" new file mode 100644 index 0000000..c5d386f --- /dev/null +++ "b/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" @@ -0,0 +1,53 @@ +import java.util.*; + +public class PRG_이중우선순위큐 { + static TreeMap treeMap = new TreeMap<>(); + + public static void main(String[] args) { + PRG_이중우선순위큐 s = new PRG_이중우선순위큐(); + String[] arr = {"I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333"}; + System.out.println(Arrays.toString(s.solution(arr))); + } // End of main + + public int[] solution(String[] operations) { + + StringTokenizer st; + int len = operations.length; + for (int i = 0; i < len; i++) { + st = new StringTokenizer(operations[i]); + String fun = st.nextToken(); + int num = Integer.parseInt(st.nextToken()); + + if (fun.equals("I")) { + treeMap.put(num, treeMap.getOrDefault(num, 0) + 1); + } else if(fun.equals("D") && num == 1 && !treeMap.isEmpty()) { + // 최댓값 삭제 + int maxNum = treeMap.lastKey(); + int numCount = treeMap.get(maxNum); + if(numCount == 1) { + treeMap.remove(maxNum); + } else { + treeMap.put(maxNum, numCount - 1); + } + } else if(fun.equals("D") && num == -1 && !treeMap.isEmpty()){ + // 최솟값 삭제 + int minNum = treeMap.firstKey(); + int numCount = treeMap.get(minNum); + if(numCount == 1) { + treeMap.remove(minNum); + } else { + treeMap.put(minNum, numCount - 1); + } + } + } + + int[] ans; + if(treeMap.isEmpty()) { + ans = new int[] {0, 0}; + } else { + ans = new int[] {treeMap.lastKey(), treeMap.firstKey()}; + } + + return ans; + } // End of solution +} // End of Main class From 29d6bce80f96f9cb28afdbdc9d4879f9aeffe62b Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Wed, 1 Mar 2023 11:46:49 +0900 Subject: [PATCH 521/822] complete --- .../PRG_N_Queen.java" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_N_Queen.java" diff --git "a/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_N_Queen.java" "b/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_N_Queen.java" new file mode 100644 index 0000000..49184b7 --- /dev/null +++ "b/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_N_Queen.java" @@ -0,0 +1,54 @@ +public class PRG_N_Queen { + static int[] arr; + static int N; + static int result; + + public static void main(String[] args) { + PRG_N_Queen s = new PRG_N_Queen(); + + System.out.println(s.solution( + 4 + )); + } // End of main + + public int solution(int n) { + N = n; + arr = new int[N]; + result = 0; + + DFS(0); + return result; + } // End of solution + + private static void DFS(int depth) { + if (depth == N) { + result++; + return; + } + + for (int i = 0; i < N; i++) { + arr[depth] = i; + + if(isPossibleCheck(depth)) { + DFS(depth + 1); + } + } + } // End of DFS + + // 해당 컬럼 위치에 가능한지 유망성을 체크 + private static Boolean isPossibleCheck(int colNum) { + for (int i = 0; i < colNum; i++) { + if(arr[colNum] == arr[i]) { + return false; + } + + // 대각선 체크 + // 대각선 -> 열의 값 차이와 행의 값 차이가 같을 경우 같은 대각선 상에 위치함 + if(Math.abs(arr[colNum] - arr[i]) == Math.abs(colNum - i)) { + return false; + } + } + + return true; + } // End of isPossibleCheck +} // End of Solution class From 2fb2ad366f0bdfeb24fd05c3cd7ced76284aebed Mon Sep 17 00:00:00 2001 From: RyuSw-cs Date: Thu, 2 Mar 2023 11:00:13 +0900 Subject: [PATCH 522/822] solve: N-Queen.java --- .../N-Queen.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "2023/03.03/\354\234\240\354\212\271\354\232\260/N-Queen.java" diff --git "a/2023/03.03/\354\234\240\354\212\271\354\232\260/N-Queen.java" "b/2023/03.03/\354\234\240\354\212\271\354\232\260/N-Queen.java" new file mode 100644 index 0000000..44e3634 --- /dev/null +++ "b/2023/03.03/\354\234\240\354\212\271\354\232\260/N-Queen.java" @@ -0,0 +1,49 @@ +import java.util.*; + +class Solution { + + static int size = 0; + static int answer = 0; + // index는 행, value는 열 + static int[] map; + + public static void main(String[] args) { + Solution solution = new Solution(); + System.out.println(solution.solution(4)); + } + + public int solution(int n) { + size = n; + map = new int[size]; + dfs(0); + + return answer; + } + + private void dfs(int pos) { + // 모든 행에 체스를 두었다. + if (pos == size) { + answer++; + return; + } + for (int i = 0; i < size; i++) { + // pos행, i열에 체스를 두었다. + map[pos] = i; + // 가로, 세로, 대각선검사를 통과하면 체스말을 둘 수 있음. + if (check(pos)) { + dfs(pos + 1); + } + } + } + + private boolean check(int row) { + // for문을 row 전까지 해서 그 행까지는 절대 못감 -> 자동으로 체크 + for (int i = 0; i < row; i++) { + // 열을 체크한다. 안에 가지고 있는 value가 같다면 이미 그 열에는 체스말이 있음. + if (map[row] == map[i]) return false; + // 대각선을 체크한다. 가로의 거리와 세로의 거리가 같다 -> 대각선이다. + else if (Math.abs(row - i) == Math.abs(map[row] - map[i])) return false; + } + return true; + } +} \ No newline at end of file From deb4477d5ae667ba02280fd4af0876fda367184d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 2 Mar 2023 22:35:09 +0900 Subject: [PATCH 523/822] Create N-Queen.cpp --- .../N-Queen.cpp" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "2023/03.03/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" diff --git "a/2023/03.03/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" "b/2023/03.03/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" new file mode 100644 index 0000000..18f6771 --- /dev/null +++ "b/2023/03.03/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +using namespace std; + +int answer = 0; +void bfs(int n, int x, vector> v) { + if (n == v.size()) { + answer++; + return; + } + for (int i = 0; i < n; i++) { + bool flag = true; + for (pair p : v) { + if (p.first == x || p.second == i || + abs(x - p.first) == abs(i - p.second)) { + flag = false; + break; + } + } + if (flag) { + vector> v1 = v; + v1.push_back({ x,i }); + bfs(n, x + 1, v1); + } + } +} +int solution(int n) { + bfs(n, 0, {}); + return answer; +} From 3881577cc096f701ac9dbe84b9685a7d2ed7cf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 2 Mar 2023 22:44:21 +0900 Subject: [PATCH 524/822] =?UTF-8?q?Create=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\210\234\354\234\204\355\201\220.cpp" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "2023/03.03/\354\235\264\354\225\204\353\246\204/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" diff --git "a/2023/03.03/\354\235\264\354\225\204\353\246\204/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" "b/2023/03.03/\354\235\264\354\225\204\353\246\204/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" new file mode 100644 index 0000000..7124e54 --- /dev/null +++ "b/2023/03.03/\354\235\264\354\225\204\353\246\204/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.cpp" @@ -0,0 +1,29 @@ +#include +#include +#include + +using namespace std; + +vector solution(vector operations) { + vector answer; + for (string str : operations) { + if (str[0] == 'I') { + answer.push_back(stoi(str.substr(2))); + sort(answer.begin(), answer.end()); + } + else if (str[0] == 'D') { + if (answer.size() > 0) { + if (stoi(str.substr(2)) < 0) { + answer.erase(answer.begin()); + } + else { + answer.erase(answer.begin() + (answer.size() - 1)); + } + } + } + } + if (answer.size() == 0) { + return { 0,0 }; + } + return {answer[answer.size()-1],answer[0]}; +} From 5f083264db5de4c41f741b19350fff7567fedaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Thu, 2 Mar 2023 22:59:25 +0900 Subject: [PATCH 525/822] =?UTF-8?q?Create=20=ED=98=BC=EC=9E=90=EB=86=80?= =?UTF-8?q?=EA=B8=B0=EC=9D=98=EB=8B=AC=EC=9D=B8.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\230\353\213\254\354\235\270.cpp" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "2023/03.03/\354\235\264\354\225\204\353\246\204/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.cpp" diff --git "a/2023/03.03/\354\235\264\354\225\204\353\246\204/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.cpp" "b/2023/03.03/\354\235\264\354\225\204\353\246\204/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.cpp" new file mode 100644 index 0000000..944d23e --- /dev/null +++ "b/2023/03.03/\354\235\264\354\225\204\353\246\204/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.cpp" @@ -0,0 +1,38 @@ +#include +#include +#include + +using namespace std; + +int solution(vector cards) { + int answer = 0; + for (int i = 0; i < cards.size(); i++) { + bool visit[101] = { false }; + int cnt = 0; + int n = i; + while (!visit[n]) { + visit[n] = true; + n = cards[n]-1; + cnt++; + } + for (int k = 0; k < cards.size(); k++) { + bool visit2[101]; + copy(begin(visit), end(visit), visit2); + if (!visit2[k]) { + int cnt2 = 0; + int n = k; + while (!visit2[n]) { + visit2[n] = true; + n = cards[n]-1; + cnt2++; + } + answer = max(answer, cnt * cnt2); + } + } + } + return answer; +} + +int main() { + solution({ 8,6,3,7,2,5,1,4 }); +} From 14fa9dba692cd22b815ff4fb5ff5812ba55d475b Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:50:02 +0900 Subject: [PATCH 526/822] Create N-Queen.java --- .../N-Queen.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "2023/03.03/\354\240\225\355\230\270\354\241\260/N-Queen.java" diff --git "a/2023/03.03/\354\240\225\355\230\270\354\241\260/N-Queen.java" "b/2023/03.03/\354\240\225\355\230\270\354\241\260/N-Queen.java" new file mode 100644 index 0000000..20885a6 --- /dev/null +++ "b/2023/03.03/\354\240\225\355\230\270\354\241\260/N-Queen.java" @@ -0,0 +1,49 @@ +public class NQueen { + public static void main(String[] args) { + int n = 4; + Solution so = new Solution(); + System.out.println(so.solution(n)); + } + + static class Solution { + static int answer; + static int[] map; + + public int solution(int n) { + answer = 0; + map = new int[n]; + + getResult(n, 0); + return answer; + } + + static void getResult(int n, int index) { + if (index == n) { + answer++; + return; + } + for (int i = 0; i < n; i++) { + map[index] = i; + if(checkPossibility(index)){ + getResult(n, index+1); + } + } + } + + static boolean checkPossibility(int index) { + for (int i = 0; i < index; i++) { + //가로 체크 (index를 col 번호로 지정한 순간 같은 열에는 존재할 수 없으므로 세로는 체크 안해도 됨 -> map[index] 에는 한 가지 값만 들어가므로 index 열에는 한 개의 Queen만 존재) + if (map[index] == map[i]) { + return false; + } + //대각선 체크 + + else if (Math.abs(i - index) == Math.abs(map[i] - map[index])) { + return false; + } + } + return true; + } + } + +} From d030b82a8c5643f7ee747d3bcee2082d1574e4cc Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:50:31 +0900 Subject: [PATCH 527/822] =?UTF-8?q?Create=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\234\354\234\204\355\201\220.java" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" diff --git "a/2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" "b/2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" new file mode 100644 index 0000000..d8768a4 --- /dev/null +++ "b/2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" @@ -0,0 +1,48 @@ +import java.util.Collections; +import java.util.PriorityQueue; + +public class 이중우선순위큐 { + public static void main(String[] args) { + String[] operations = {"I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333"}; + Solution so = new Solution(); + System.out.println(so.solution(operations)[0] + " , " + so.solution(operations)[1]); + } + + static class Solution { + public int[] solution(String[] operations) { + PriorityQueue minHeap = new PriorityQueue<>(); + PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder()); + + for (int i = 0; i < operations.length; i++) { + if(operations[i].charAt(0) == 'I'){ + minHeap.add(Integer.parseInt(operations[i].substring(2))); + maxHeap.add(Integer.parseInt(operations[i].substring(2))); + } else if(operations[i].charAt(0) == 'D'){ + if(maxHeap.size() > 0){ + if(operations[i].charAt(2) == '1'){ + int max = maxHeap.peek(); + maxHeap.remove(max); + minHeap.remove(max); + } else { + int min = minHeap.peek(); + maxHeap.remove(min); + minHeap.remove(min); + } + } + } + } + int[] answer = new int[2]; + + if(maxHeap.size() > 0){ + answer[0] = maxHeap.peek(); + answer[1] = minHeap.peek(); + } else { + answer[0] = 0; + answer[1] = 0; + } + + return answer; + } + } +} + From defb2b98e5d317eb1d392ffa174722860190746e Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:50:51 +0900 Subject: [PATCH 528/822] =?UTF-8?q?Create=20=ED=98=BC=EC=9E=90=EB=86=80?= =?UTF-8?q?=EA=B8=B0=EC=9D=98=EB=8B=AC=EC=9D=B8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\230\353\213\254\354\235\270.java" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" diff --git "a/2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" "b/2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" new file mode 100644 index 0000000..eeee84d --- /dev/null +++ "b/2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" @@ -0,0 +1,74 @@ +import java.util.Arrays; + +public class 혼자놀기의달인 { + static int[] cards = {8, 6, 3, 7, 2, 5, 1, 4}; + + public static void main(String[] args) { + Solution so = new Solution(); + System.out.println(so.solution(cards)); + } + + static class Solution { + static int answer, group1, group2; + static int[] vis; + public int solution(int[] cards) { + + //나올 수 있는 최댓값을 먼저 구해줌 -> 안해주는 게 시간, 메모리 효율 더 좋음 +// int max = 0; +// int[] copy = cards.clone(); +// Arrays.sort(copy); +// if (copy.length % 2 == 0) { +// max = copy[copy.length / 2 - 1] * copy[copy.length / 2 - 1]; +// } else { +// max = copy[copy.length / 2] * copy[copy.length / 2 - 1]; +// } + + answer = 0; + group1 = 1; + group2 = 1; + + Loop1: + for (int i = 0; i < cards.length; i++) { + vis = new int[cards.length]; + getResult(i, cards, 1); + if (group1 < cards.length -1) { + for (int j = 0; j < cards.length; j++) { + if (vis[j] == 0) { + int[] visCopy = vis.clone(); //방문 처리 복구시키기 위한 복사 + getResult(j, cards, 2); + vis = visCopy.clone(); + answer = Math.max(group1 * group2, answer); +// if (answer == max) { // 이미 답이 나올 수 있는 최댓값과 같으면 종료 +// break Loop1; +// } + } + } + } else if(group1 == cards.length -1) { //group1의 값이 cards.length -1 과 같으면 length 값을 넣어줌 + answer = Math.max(answer, cards.length-1); + } + } + + return answer; + } + + static void getResult(int index, int[] cards, int group) { + if (vis[index] != 0) { + int cnt = 0; + for (int i = 0; i < cards.length; i++) { + if (vis[i] == group) { + cnt++; + } + } + if (group == 1) { + group1 = cnt; + } else { + group2 = cnt; + } + return; + } + vis[index] = group; + getResult(cards[index] - 1, cards, group); + } + } + +} From d3fc2013640b8006486d6a76e3746430c2c1707e Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:51:10 +0900 Subject: [PATCH 529/822] =?UTF-8?q?Delete=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\234\354\234\204\355\201\220.java" | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 "2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" diff --git "a/2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" "b/2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" deleted file mode 100644 index d8768a4..0000000 --- "a/2023/03.03/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" +++ /dev/null @@ -1,48 +0,0 @@ -import java.util.Collections; -import java.util.PriorityQueue; - -public class 이중우선순위큐 { - public static void main(String[] args) { - String[] operations = {"I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333"}; - Solution so = new Solution(); - System.out.println(so.solution(operations)[0] + " , " + so.solution(operations)[1]); - } - - static class Solution { - public int[] solution(String[] operations) { - PriorityQueue minHeap = new PriorityQueue<>(); - PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder()); - - for (int i = 0; i < operations.length; i++) { - if(operations[i].charAt(0) == 'I'){ - minHeap.add(Integer.parseInt(operations[i].substring(2))); - maxHeap.add(Integer.parseInt(operations[i].substring(2))); - } else if(operations[i].charAt(0) == 'D'){ - if(maxHeap.size() > 0){ - if(operations[i].charAt(2) == '1'){ - int max = maxHeap.peek(); - maxHeap.remove(max); - minHeap.remove(max); - } else { - int min = minHeap.peek(); - maxHeap.remove(min); - minHeap.remove(min); - } - } - } - } - int[] answer = new int[2]; - - if(maxHeap.size() > 0){ - answer[0] = maxHeap.peek(); - answer[1] = minHeap.peek(); - } else { - answer[0] = 0; - answer[1] = 0; - } - - return answer; - } - } -} - From 1adc0b26757ded77dc1a989ba5b5a63478023941 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:51:18 +0900 Subject: [PATCH 530/822] =?UTF-8?q?Delete=20=ED=98=BC=EC=9E=90=EB=86=80?= =?UTF-8?q?=EA=B8=B0=EC=9D=98=EB=8B=AC=EC=9D=B8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\230\353\213\254\354\235\270.java" | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 "2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" diff --git "a/2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" "b/2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" deleted file mode 100644 index eeee84d..0000000 --- "a/2023/03.03/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" +++ /dev/null @@ -1,74 +0,0 @@ -import java.util.Arrays; - -public class 혼자놀기의달인 { - static int[] cards = {8, 6, 3, 7, 2, 5, 1, 4}; - - public static void main(String[] args) { - Solution so = new Solution(); - System.out.println(so.solution(cards)); - } - - static class Solution { - static int answer, group1, group2; - static int[] vis; - public int solution(int[] cards) { - - //나올 수 있는 최댓값을 먼저 구해줌 -> 안해주는 게 시간, 메모리 효율 더 좋음 -// int max = 0; -// int[] copy = cards.clone(); -// Arrays.sort(copy); -// if (copy.length % 2 == 0) { -// max = copy[copy.length / 2 - 1] * copy[copy.length / 2 - 1]; -// } else { -// max = copy[copy.length / 2] * copy[copy.length / 2 - 1]; -// } - - answer = 0; - group1 = 1; - group2 = 1; - - Loop1: - for (int i = 0; i < cards.length; i++) { - vis = new int[cards.length]; - getResult(i, cards, 1); - if (group1 < cards.length -1) { - for (int j = 0; j < cards.length; j++) { - if (vis[j] == 0) { - int[] visCopy = vis.clone(); //방문 처리 복구시키기 위한 복사 - getResult(j, cards, 2); - vis = visCopy.clone(); - answer = Math.max(group1 * group2, answer); -// if (answer == max) { // 이미 답이 나올 수 있는 최댓값과 같으면 종료 -// break Loop1; -// } - } - } - } else if(group1 == cards.length -1) { //group1의 값이 cards.length -1 과 같으면 length 값을 넣어줌 - answer = Math.max(answer, cards.length-1); - } - } - - return answer; - } - - static void getResult(int index, int[] cards, int group) { - if (vis[index] != 0) { - int cnt = 0; - for (int i = 0; i < cards.length; i++) { - if (vis[i] == group) { - cnt++; - } - } - if (group == 1) { - group1 = cnt; - } else { - group2 = cnt; - } - return; - } - vis[index] = group; - getResult(cards[index] - 1, cards, group); - } - } - -} From f340ce5b54fc8f41ca49c9a30ecae260d211c4d2 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:51:39 +0900 Subject: [PATCH 531/822] =?UTF-8?q?Create=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=ED=81=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\234\354\234\204\355\201\220.java" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "2023/03.03/\354\240\225\355\230\270\354\241\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" diff --git "a/2023/03.03/\354\240\225\355\230\270\354\241\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" "b/2023/03.03/\354\240\225\355\230\270\354\241\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" new file mode 100644 index 0000000..b3e6aad --- /dev/null +++ "b/2023/03.03/\354\240\225\355\230\270\354\241\260/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.java" @@ -0,0 +1,47 @@ +import java.util.Collections; +import java.util.PriorityQueue; + +public class 이중우선순위큐 { + public static void main(String[] args) { + String[] operations = {"I -45", "I 653", "D 1", "I -642", "I 45", "I 97", "D 1", "D -1", "I 333"}; + Solution so = new Solution(); + System.out.println(so.solution(operations)[0] + " , " + so.solution(operations)[1]); + } + + static class Solution { + public int[] solution(String[] operations) { + PriorityQueue minHeap = new PriorityQueue<>(); + PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder()); + + for (int i = 0; i < operations.length; i++) { + if(operations[i].charAt(0) == 'I'){ + minHeap.add(Integer.parseInt(operations[i].substring(2))); + maxHeap.add(Integer.parseInt(operations[i].substring(2))); + } else if(operations[i].charAt(0) == 'D'){ + if(maxHeap.size() > 0){ + if(operations[i].charAt(2) == '1'){ + int max = maxHeap.peek(); + maxHeap.remove(max); + minHeap.remove(max); + } else { + int min = minHeap.peek(); + maxHeap.remove(min); + minHeap.remove(min); + } + } + } + } + int[] answer = new int[2]; + + if(maxHeap.size() > 0){ + answer[0] = maxHeap.peek(); + answer[1] = minHeap.peek(); + } else { + answer[0] = 0; + answer[1] = 0; + } + + return answer; + } + } +} From 781d242972e8575f47a105dada5357cf53951e1b Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:51:53 +0900 Subject: [PATCH 532/822] =?UTF-8?q?Create=20=ED=98=BC=EC=9E=90=EB=86=80?= =?UTF-8?q?=EA=B8=B0=EC=9D=98=EB=8B=AC=EC=9D=B8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\230\353\213\254\354\235\270.java" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "2023/03.03/\354\240\225\355\230\270\354\241\260/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" diff --git "a/2023/03.03/\354\240\225\355\230\270\354\241\260/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" "b/2023/03.03/\354\240\225\355\230\270\354\241\260/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" new file mode 100644 index 0000000..eeee84d --- /dev/null +++ "b/2023/03.03/\354\240\225\355\230\270\354\241\260/\355\230\274\354\236\220\353\206\200\352\270\260\354\235\230\353\213\254\354\235\270.java" @@ -0,0 +1,74 @@ +import java.util.Arrays; + +public class 혼자놀기의달인 { + static int[] cards = {8, 6, 3, 7, 2, 5, 1, 4}; + + public static void main(String[] args) { + Solution so = new Solution(); + System.out.println(so.solution(cards)); + } + + static class Solution { + static int answer, group1, group2; + static int[] vis; + public int solution(int[] cards) { + + //나올 수 있는 최댓값을 먼저 구해줌 -> 안해주는 게 시간, 메모리 효율 더 좋음 +// int max = 0; +// int[] copy = cards.clone(); +// Arrays.sort(copy); +// if (copy.length % 2 == 0) { +// max = copy[copy.length / 2 - 1] * copy[copy.length / 2 - 1]; +// } else { +// max = copy[copy.length / 2] * copy[copy.length / 2 - 1]; +// } + + answer = 0; + group1 = 1; + group2 = 1; + + Loop1: + for (int i = 0; i < cards.length; i++) { + vis = new int[cards.length]; + getResult(i, cards, 1); + if (group1 < cards.length -1) { + for (int j = 0; j < cards.length; j++) { + if (vis[j] == 0) { + int[] visCopy = vis.clone(); //방문 처리 복구시키기 위한 복사 + getResult(j, cards, 2); + vis = visCopy.clone(); + answer = Math.max(group1 * group2, answer); +// if (answer == max) { // 이미 답이 나올 수 있는 최댓값과 같으면 종료 +// break Loop1; +// } + } + } + } else if(group1 == cards.length -1) { //group1의 값이 cards.length -1 과 같으면 length 값을 넣어줌 + answer = Math.max(answer, cards.length-1); + } + } + + return answer; + } + + static void getResult(int index, int[] cards, int group) { + if (vis[index] != 0) { + int cnt = 0; + for (int i = 0; i < cards.length; i++) { + if (vis[i] == group) { + cnt++; + } + } + if (group == 1) { + group1 = cnt; + } else { + group2 = cnt; + } + return; + } + vis[index] = group; + getResult(cards[index] - 1, cards, group); + } + } + +} From a3a5b1397259ef1cdf7704d6bd9b01803080ff9e Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Fri, 3 Mar 2023 20:37:48 +0900 Subject: [PATCH 533/822] complete --- ...354\235\230_\353\213\254\354\235\270.java" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" diff --git "a/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" "b/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" new file mode 100644 index 0000000..6a56dd2 --- /dev/null +++ "b/2023/03.03/\354\265\234\354\260\275\354\230\201/PRG_\355\230\274\354\236\220_\353\206\200\352\270\260\354\235\230_\353\213\254\354\235\270.java" @@ -0,0 +1,48 @@ +public class PRG_혼자_놀기의_달인 { + static boolean[] isVisited = new boolean[101]; + static int[] cards = new int[101]; + + public static void main(String[] args) { + PRG_혼자_놀기의_달인 s = new PRG_혼자_놀기의_달인(); + int[] cards = {8, 6, 3, 7, 2, 5, 1, 4}; + System.out.println(s.solution(cards)); + } // End of main + + public int solution(int[] cards) { + this.cards = cards; + + int group1 = 0; + int group2 = 0; + + int size = cards.length; + for (int i = 0; i < size; i++) { + if (!isVisited[i]) { + isVisited[i] = true; + + int count = DFS(i); + + if (count > group1) { + group2 = group1; + group1 = count; + } else if(count > group2) { + group2 = count; + } + } + } + + return group1 * group2; + } // End of solution + + private static int DFS(int index) { + int count = 1; + + int nextIdx = cards[index] - 1; + + if(isVisited[nextIdx] == false) { + isVisited[nextIdx] = true; + count = DFS(nextIdx) + 1; + } + + return count; + } // End of DFS +} // End of Main class From eece17a832f87e8436c749297bf3342fbd29fd57 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 3 Mar 2023 21:16:05 +0900 Subject: [PATCH 534/822] Create README.md --- 2023/03.06/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/03.06/README.md diff --git a/2023/03.06/README.md b/2023/03.06/README.md new file mode 100644 index 0000000..eb4ce3c --- /dev/null +++ b/2023/03.06/README.md @@ -0,0 +1,5 @@ +# 3.6(월) 스터디 + +- 프로그래머스 + - [미로 탈출 명령어](https://school.programmers.co.kr/learn/courses/30/lessons/150365) + - [1,2,3 떨어트리기](https://school.programmers.co.kr/learn/courses/30/lessons/150364) From fd33f423d768df4584a76fcb59ca81539ff50c04 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 4 Mar 2023 13:57:35 +0900 Subject: [PATCH 535/822] =?UTF-8?q?SOLVE=20:=20=EB=AF=B8=EB=A1=9C=5F?= =?UTF-8?q?=ED=83=88=EC=B6=9C=5F=EB=AA=85=EB=A0=B9=EC=96=B4.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4_\353\252\205\353\240\271\354\226\264.kt" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.kt" diff --git "a/2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.kt" "b/2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.kt" new file mode 100644 index 0000000..dd606c5 --- /dev/null +++ "b/2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.kt" @@ -0,0 +1,53 @@ +import java.awt.Point +import kotlin.math.abs +import kotlin.text.StringBuilder + +fun main() { + val n = 3 + val m = 4 + val x = 2 + val y = 3 + val r = 3 + val c = 1 + val k = 5 + println(Solution().solution(n, m, x, y, r, c, k)) +} + +class Solution { + //사전 순이므로 방향 벡터를 하 좌 우 상 순으로 세팅 + val dx = intArrayOf(0, -1, 1, 0) + val dy = intArrayOf(1, 0, 0, -1) + val move = charArrayOf('d', 'l', 'r', 'u') + val sb = StringBuilder() + var answer = "" + + fun solution(n: Int, m: Int, x: Int, y: Int, r: Int, c: Int, k: Int): String { + val distance = abs(r - x) + abs(c - y) + // E까지 거리가 k보다 작은 경우이거나 2로 나눈 나머지가 홀수인 경우에는 어차피 도달 못하니 impossible + if (k >= distance && (k - distance) % 2 == 0) dfs(Point(y - 1, x - 1), Point(c - 1, r - 1), k, 0, n, m) + return if (answer.isNotEmpty()) answer else "impossible" + } + + fun dfs(startPoint: Point, endPoint: Point, k: Int, count: Int, n: Int, m: Int) { + if (count > k || answer.isNotEmpty()) return //횟수를 초과하거나 단어를 찾으면 return + for (i in dx.indices) { //방향이동 + if (answer.isNotEmpty()) break + val x = startPoint.x + dx[i] + val y = startPoint.y + dy[i] + val d = abs(endPoint.x - x) + abs(endPoint.y - y) + // 영역 안이거나 + // 현재 위치에서 E까지 거리가 k - 이동한 횟수보다 작거나 + // k - 이동한 횟수 - 현재위치부터 E까지 거리를 2로 나눴을 때 나머지가 홀수인 경우 이동이 가능 + if (x in 0 until m && y in 0 until n && d <= k - count && (k - count - d) % 2 != 0) { + if (count + 1 == k && x == endPoint.x && y == endPoint.y) { + answer = sb.append(move[i]).toString() + return + } else { + sb.append(move[i]) + dfs(Point(x, y), endPoint, k, count + 1, n, m) + sb.deleteAt(sb.length - 1) + } + } + } + } +} \ No newline at end of file From 3569a0e64a03228d63be5e5110e1817bca68c181 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 4 Mar 2023 14:14:58 +0900 Subject: [PATCH 536/822] =?UTF-8?q?SOLVE=20:=20=EB=AF=B8=EB=A1=9C=5F?= =?UTF-8?q?=ED=83=88=EC=B6=9C=5F=EB=AA=85=EB=A0=B9=EC=96=B4.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\252\205\353\240\271\354\226\264.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.java" diff --git "a/2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.java" "b/2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.java" new file mode 100644 index 0000000..5cdcb7f --- /dev/null +++ "b/2023/03.06/\354\241\260\354\210\230\354\227\260/\353\257\270\353\241\234_\355\203\210\354\266\234_\353\252\205\353\240\271\354\226\264.java" @@ -0,0 +1,49 @@ +import java.awt.*; +import static java.lang.Math.abs; + +public class Problem { + public static void main(String[] args) { + new SolutionJava().solution(3, 4, 2, 3, 3, 1, 5); + } +} + +class SolutionJava { + //사전 순이므로 방향 벡터를 하 좌 우 상 순으로 세팅 + int[] dx = {0, -1, 1, 0}; + int[] dy = {1, 0, 0, -1}; + char[] move = {'d', 'l', 'r', 'u'}; + StringBuilder sb = new StringBuilder(); + String answer = "impossible"; + + public String solution(int n, int m, int x, int y, int r, int c, int k) { + int distance = abs(r - x) + abs(c - y); + // E까지 거리가 k보다 작은 경우이거나 2로 나눈 나머지가 홀수인 경우에는 어차피 도달 못하니 impossible + if (k >= distance && (k - distance) % 2 == 0) dfs(new Point(y - 1, x - 1), new Point(c - 1, r - 1), k, 0, n, m); + return answer; + } + + public void dfs(Point startPoint, Point endPoint, int k, int count, int n, int m) { + if (count > k || !answer.equals("impossible")) return; //횟수를 초과하거나 단어를 찾으면 return + for (int i = 0; i < dx.length; i++) { //방향이동 + if (!answer.equals("impossible")) break; + int x = startPoint.x + dx[i]; + int y = startPoint.y + dy[i]; + int d = abs(endPoint.x - x) + abs(endPoint.y - y); + // 영역 안이거나 + // 현재 위치에서 E까지 거리가 k - 이동한 횟수보다 작거나 + // k - 이동한 횟수 - 현재위치부터 E까지 거리를 2로 나눴을 때 나머지가 홀수인 경우 이동이 가능 + if (x >= 0 && x < m && y >= 0 && y < n &&d <= k - count && (k - count - d) % 2 != 0){ + if (count + 1 == k && x == endPoint.x && y == endPoint.y) { + answer = sb.append(move[i]).toString(); + return; + } else { + sb.append(move[i]); + dfs(new Point(x, y), endPoint, k, count + 1, n, m); + sb.deleteCharAt(sb.length()-1); + } + } + } + } +} + + From 3ffeb32c4bd4158fc6762dfb40fd161ee7bd9243 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sun, 5 Mar 2023 12:41:45 +0900 Subject: [PATCH 537/822] =?UTF-8?q?FAIL=20:=201,2,3,4,5=EB=B2=88=EB=A7=8C?= =?UTF-8?q?=20=EC=A0=95=EB=8B=B5=20=EB=82=98=EB=A8=B8=EC=A7=80=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=B4=88=EA=B3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\234\250\353\246\254\352\270\260.kt" | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 "2023/03.06/\354\241\260\354\210\230\354\227\260/1,2,3_\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.kt" diff --git "a/2023/03.06/\354\241\260\354\210\230\354\227\260/1,2,3_\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.kt" "b/2023/03.06/\354\241\260\354\210\230\354\227\260/1,2,3_\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.kt" new file mode 100644 index 0000000..65471d6 --- /dev/null +++ "b/2023/03.06/\354\241\260\354\210\230\354\227\260/1,2,3_\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.kt" @@ -0,0 +1,139 @@ +import kotlin.math.min + +fun main() { + val edges = arrayOf( + intArrayOf(2, 4), intArrayOf(1, 2), intArrayOf(6, 8), intArrayOf(1, 3), intArrayOf(5, 7), + intArrayOf(2, 5), intArrayOf(3, 6), intArrayOf(6, 10), intArrayOf(6, 9) +// intArrayOf(1, 2), intArrayOf(1, 3) +// intArrayOf(1,3), intArrayOf(1,2) + ) + val target = +// intArrayOf(0, 7, 3) + intArrayOf(0, 0, 0, 3, 0, 0, 5, 1, 2, 3) +// intArrayOf(0,7,1) + Solution().solution(edges, target) +} + +class Solution { + val graph = ArrayList>() + lateinit var checked: BooleanArray + lateinit var finished: BooleanArray + lateinit var temp: IntArray + var test = ArrayList() + var min = Integer.MAX_VALUE + val set = HashSet() + var answer = ArrayList() + fun solution(edges: Array, target: IntArray): IntArray { + + checked = BooleanArray(target.size + 1) + finished = BooleanArray(target.size + 1) + temp = IntArray(target.size + 1) + + for (i in 0..target.size) { + graph.add(ArrayList()) + } + + for (edge in edges) { + graph[edge[0]].add(edge[1]) + } + + for (i in 1 until target.size) { + graph[i].sort() + if (graph[i].isNotEmpty()) checked[graph[i][0]] = true //실선만 이동하기 때문에 이동 노드로 표시해주기 + } + dfs(1, target, 0, 0) + return if (answer.isEmpty()) return intArrayOf(-1) else answer.toIntArray() + } + + fun dfs(node: Int, target: IntArray, sum: Int, count: Int) { + + if (count > min) { + return + } + + if (sum == target.sum()) { + min = min(min, test.size) + if (answer.isEmpty()) answer.addAll(test) + else{ + for (i in answer.indices){ + if (answer[i] > test[i]) { + answer.clear() + answer.addAll(test) + break + } + } + } + return + } + + var currentIdx = -1 + var nextIdx = -1 + + if (graph[node].isNotEmpty()){ + run { + graph[node].forEachIndexed { i, child -> + if (checked[child] && graph[node].size > 1) { + nextIdx = if (i + 1 == graph[node].size) graph[node][0] else graph[node][i+1] + currentIdx = child + return@run + } else if (graph[node].size == 1) { + currentIdx = graph[node][0] + } + } + } + } else currentIdx = 1 + + + if (graph[node].isNotEmpty()) { + if (nextIdx != -1){ + checked[currentIdx] = false + checked[nextIdx] = true + } + dfs(currentIdx, target, sum, count) + if (nextIdx != -1){ + checked[currentIdx] = true + checked[nextIdx] = false + } + } else { + set.add(node) + for (j in 3 downTo 1) { + if (temp[node] + j < target[node - 1]) { + temp[node] += j + test.add(j) + if (nextIdx != -1){ + checked[currentIdx] = false + checked[nextIdx] = true + } + dfs(currentIdx, target, sum + j, count + 1) + if (nextIdx != -1){ + checked[currentIdx] = true + checked[nextIdx] = false + } + temp[node] -= j + test.removeAt(test.size - 1) + }else if (temp[node] + j == target[node - 1] && checkSum(node,target)){ + temp[node] += j + test.add(j) + if (nextIdx != -1){ + checked[currentIdx] = false + checked[nextIdx] = true + } + dfs(currentIdx, target, sum + j, count + 1) + if (nextIdx != -1){ + checked[currentIdx] = true + checked[nextIdx] = false + } + temp[node] -= j + test.removeAt(test.size - 1) + } + } + } + } + + fun checkSum(node: Int,target: IntArray) : Boolean{ + val index = set.indexOf(node) + val nextIdx = if (index + 1 == set.size) 0 else index+1 + if (target[set.elementAt(nextIdx)-1] - temp[set.elementAt(nextIdx)] > 3) return false + return true + } +} \ No newline at end of file From e449e070126a02fd706e18be9144e2f6919d0468 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 6 Mar 2023 12:16:27 +0900 Subject: [PATCH 538/822] kihun 230306 --- ...34\353\252\205\353\240\271\354\226\264.py" | 39 +++++++++ ...6\264_timeout_\352\263\240\354\271\250.py" | 43 ++++++++++ ...64\355\212\270\353\246\254\352\270\260.py" | 81 +++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 "2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.py" create mode 100644 "2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264_timeout_\352\263\240\354\271\250.py" create mode 100644 "2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv4_123\353\226\250\354\226\264\355\212\270\353\246\254\352\270\260.py" diff --git "a/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.py" "b/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.py" new file mode 100644 index 0000000..28e7117 --- /dev/null +++ "b/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264.py" @@ -0,0 +1,39 @@ +import sys + +sys.setrecursionlimit(10**8) + +# d l r u +# 하 좌 우 상, 알파벳 순으로 탐색 +# 탐색 성공하면 최단 거리 +# answer는 사전순으로 제일 끝에 것을 초기값으로 +dX = [1, 0, 0, -1] +dY = [0, -1, 1, 0] +letter = ['d', 'l', 'r', 'u'] +answer = "z" + + +def dfs(n, m, x, y, r, c, path, depth, k): + global answer + # k < 앞으로 가야할 거리 + 지금까지 온 거리이면 return + if k < depth + abs(x - r) + abs(y - c): + return + # 무사히 도착 + if x == r and y == c and depth == k: + answer = path + return + for i in range(4): + nX = x + dX[i] + nY = y + dY[i] + # 미로 안이고 answer보다 사전 순으로 앞이면 dfs + if 0 <= nX < n and 0 <= nY < m and path < answer: + dfs(n, m, nX, nY, r, c, path+letter[i], depth + 1, k) + + +def solution(n, m, x, y, r, c, k): + distance = abs(x - r) + abs(y - c) + if distance > k or (k - distance) % 2 == 1: + return "impossible" + + dfs(n, m, x-1, y-1, r-1, c-1, "", 0, k) + + return answer diff --git "a/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264_timeout_\352\263\240\354\271\250.py" "b/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264_timeout_\352\263\240\354\271\250.py" new file mode 100644 index 0000000..1b2419d --- /dev/null +++ "b/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\257\270\353\241\234\355\203\210\354\266\234\353\252\205\353\240\271\354\226\264_timeout_\352\263\240\354\271\250.py" @@ -0,0 +1,43 @@ +import sys + +sys.setrecursionlimit(10**8) + +# d l r u +# 하 좌 우 상, 알파벳 순으로 탐색 +# 탐색 성공하면 최단 거리 +dX = [1, 0, 0, -1] +dY = [0, -1, 1, 0] +letter = ["d", "l", "r", "u"] + + +def solution(n, m, x, y, r, c, k): + global answer + + answer = "impossible" + + distance = abs(x - r) + abs(y - c) + if distance > k or (k - distance) % 2 == 1: + return "impossible" + + def dfs(n, m, x, y, r, c, path, depth, k): + global answer, dX, dY, letter + # answer가 값이 있거나 depth가 k보다 크면 return + if answer != "impossible" or depth > k: + return + # k < 앞으로 가야할 거리 + 지금까지 온 거리이면 return + if k < depth + abs(x - r) + abs(y - c): + return + + if x == r and y == c and depth == k: + answer = path + return + + for i in range(4): + nX = x + dX[i] + nY = y + dY[i] + if (0 <= nX < n and 0 <= nY < m): + dfs(n, m, nX, nY, r, c, path + letter[i], depth + 1, k) + + dfs(n, m, x-1, y-1, r-1, c-1, "", 0, k) + + return answer diff --git "a/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv4_123\353\226\250\354\226\264\355\212\270\353\246\254\352\270\260.py" "b/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv4_123\353\226\250\354\226\264\355\212\270\353\246\254\352\270\260.py" new file mode 100644 index 0000000..5b62c79 --- /dev/null +++ "b/2023/03.06/\354\206\241\352\270\260\355\233\210/pgm_lv4_123\353\226\250\354\226\264\355\212\270\353\246\254\352\270\260.py" @@ -0,0 +1,81 @@ +# https://magentino.tistory.com/74 + +from collections import defaultdict +import sys + +sys.setrecursionlimit(10**8) + + +def solution(edges, target): + edgeDict = defaultdict(list) # [연결된 모든 노드들] + treeDict = defaultdict(list) # [부모노드, [자식노드들]] + visited = [False for _ in range(len(target))] + visited[0] = True + + for a, b in edges: + edgeDict[a-1].append(b-1) + edgeDict[b-1].append(a-1) + + def dfs(node): + childList = list() + for child in edgeDict[node]: + if visited[child]: + continue + visited[child] = True + childList.append(child) + + if not childList: + return [node] + + treeDict[node].extend([0, sorted(childList)]) + leafList = list() + for child in childList: + leafList.extend(dfs(child)) + return leafList + + def search(node): + if len(treeDict[node]) == 0: + return node + idx = treeDict[node][0] + treeDict[node][0] = (treeDict[node][0] + 1) % len(treeDict[node][1]) + return search(treeDict[node][1][idx]) + + leafList = dfs(0) + # 방문 횟수를 저장하는 dict + leafVisitedDict = {key: 0 for key in leafList} + + # 유효성 검사 + isLeafSucceed = {key: False if target[key] + > 0 else True for key in leafList} + + orderList = list() + while False in isLeafSucceed.values(): + currentNode = search(0) + print("tree", treeDict) + leafVisitedDict[currentNode] += 1 + + if leafVisitedDict[currentNode] > target[currentNode]: + return [-1] + if not isLeafSucceed[currentNode] and leafVisitedDict[currentNode] * 3 >= target[currentNode]: + isLeafSucceed[currentNode] = True + + orderList.append(currentNode) + + answer = [0 for _ in range(len(orderList))] + for leaf in leafList: + leafResult = list() + diff = target[leaf] - leafVisitedDict[leaf] + leafResult = [1]*(leafVisitedDict[leaf] - diff % 2 - + diff // 2) + [2]*(diff % 2) + [3]*(diff // 2) + + for idx, node in enumerate(orderList): + if node == leaf: + answer[idx] = leafResult.pop(0) + + return answer + + +# solution([[1, 2], [1, 3]], [0, 7, 3]) + +solution([[2, 4], [1, 2], [6, 8], [1, 3], [5, 7], [2, 5], [ + 3, 6], [6, 10], [6, 9]], [0, 0, 0, 3, 0, 0, 5, 1, 2, 3]) From cd35495ca5a29b265b412d847ca26866f25808ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 6 Mar 2023 20:47:34 +0900 Subject: [PATCH 539/822] =?UTF-8?q?Create=201,2,3=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EB=9C=A8=EB=A6=AC=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\234\250\353\246\254\352\270\260.cpp" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" diff --git "a/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" "b/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" new file mode 100644 index 0000000..059958a --- /dev/null +++ "b/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +using namespace std; +vector child[101]; +int choice[101] = { 0 }; +int counts[101] = { 0 }; +int N; + +int getChild() { + int answer = 1; + while (child[answer].size() > 0) { + int n = choice[answer]; + choice[answer]++; + if (choice[answer] == child[answer].size()) { + choice[answer] = 0; + } + answer = child[answer][n]; + } + return answer; +} + +int checkCount(vector& target) { // 1 진행필요 // 2 모두 완료 // -1 불가능 + bool flag = true; + for (int i = 1; i <= N; i++) { + if (counts[i] > target[i - 1]) { + return -1; + } + if (target[i - 1] > counts[i] * 3) { //진행필요 + flag = false; + } + } + return flag ? 2 : 1; +} + +vector solution(vector> edges, vector target) { + vector answer; + N = target.size(); + sort(edges.begin(), edges.end()); + for (int i = 0; i < edges.size(); i++) { + child[edges[i][0]].push_back(edges[i][1]); + } + int num = checkCount(target); + while (num == 1) { + counts[getChild()]++; + num = checkCount(target); + } + if (num == -1) { + return { -1 }; + } + else { //숫자 구하기 + vector numbers[101]; + int maxN = 0; + for (int i = 1; i <= N; i++) { + int num = 1; + int cnt = counts[i]; + int n = target[i - 1]; + maxN += cnt; + while (cnt > 0) { + while ((n-num+2)/3 >=cnt) { + num++; + } + numbers[i].push_back(num); + cnt--; + n -= num; + } + } + //숫자 넣기 + for (int i = 0; i < N; i++) { + choice[i] = 0; + } + int counts[101] = { 0 }; + for (int i = 0; i < maxN; i++) { + int n = getChild(); + answer.push_back(numbers[n][counts[n]]); + counts[n]++; + } + } + return answer; +} From 1b4f25813daeb5a65cb3ad60437f8da1f3a548d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Mon, 6 Mar 2023 21:00:02 +0900 Subject: [PATCH 540/822] =?UTF-8?q?Update=201,2,3=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EB=9C=A8=EB=A6=AC=EA=B8=B0.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\234\250\353\246\254\352\270\260.cpp" | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git "a/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" "b/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" index 059958a..ec4d878 100644 --- "a/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" +++ "b/2023/03.06/\354\235\264\354\225\204\353\246\204/1,2,3\353\226\250\354\226\264\353\234\250\353\246\254\352\270\260.cpp" @@ -5,11 +5,11 @@ using namespace std; vector child[101]; -int choice[101] = { 0 }; -int counts[101] = { 0 }; +int choice[101] = { 0 }; //연결되는 선 +int counts[101] = { 0 }; //각 노드별 쌓이는 개수 int N; -int getChild() { +int getChild() { //리프 노드 찾는 함수 int answer = 1; while (child[answer].size() > 0) { int n = choice[answer]; @@ -23,12 +23,12 @@ int getChild() { } int checkCount(vector& target) { // 1 진행필요 // 2 모두 완료 // -1 불가능 - bool flag = true; + bool flag = true; //최소 카드 개수 구함 for (int i = 1; i <= N; i++) { - if (counts[i] > target[i - 1]) { + if (counts[i] > target[i - 1]) { //target이 불가능 return -1; } - if (target[i - 1] > counts[i] * 3) { //진행필요 + if (target[i - 1] > counts[i] * 3) { //진행필요 - 더 많은 카드 필요 flag = false; } } @@ -38,27 +38,28 @@ int checkCount(vector& target) { // 1 진행필요 // 2 모두 완료 // -1 vector solution(vector> edges, vector target) { vector answer; N = target.size(); - sort(edges.begin(), edges.end()); + sort(edges.begin(), edges.end()); //번호 작은 순서대로 정렬 for (int i = 0; i < edges.size(); i++) { child[edges[i][0]].push_back(edges[i][1]); } + //카드의 최소 개수 구하기 int num = checkCount(target); while (num == 1) { counts[getChild()]++; num = checkCount(target); } - if (num == -1) { + if (num == -1) { //불가능한 target 거르기 return { -1 }; } else { //숫자 구하기 - vector numbers[101]; + vector numbers[101]; //각 노드별 필요한 숫자 int maxN = 0; - for (int i = 1; i <= N; i++) { - int num = 1; - int cnt = counts[i]; - int n = target[i - 1]; - maxN += cnt; - while (cnt > 0) { + for (int i = 1; i <= N; i++) { //각 노드별 필요 개수 확인 + int num = 1; //최소 카드 숫자 + int cnt = counts[i]; //필요 개수 + int n = target[i - 1]; //목표 카드 숫자 합 + maxN += cnt; //필요한 총 카드 개수 + while (cnt > 0) { //카드 숫자들 구하기 while ((n-num+2)/3 >=cnt) { num++; } From d78177aa5a54e875d2e1ee39d90e1e952d29e1ae Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 6 Mar 2023 21:31:22 +0900 Subject: [PATCH 541/822] Create README.md --- 2023/03.09/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/03.09/README.md diff --git a/2023/03.09/README.md b/2023/03.09/README.md new file mode 100644 index 0000000..40cc5ae --- /dev/null +++ b/2023/03.09/README.md @@ -0,0 +1,5 @@ +# 3.9(목) 스터디 + +- 프로그래머스 + - [표 편집](https://school.programmers.co.kr/learn/courses/30/lessons/81303) + - [호텔 방 배정](https://school.programmers.co.kr/learn/courses/30/lessons/64063) From 9577fa6ecbe2e42a5a9c9830d517c5af63e535cd Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 7 Mar 2023 22:28:15 +0900 Subject: [PATCH 542/822] =?UTF-8?q?SOLVE=20:=20=ED=98=B8=ED=85=94=5F?= =?UTF-8?q?=EB=B0=A9=5F=EB=B0=B0=EC=A0=95.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\353\260\251_\353\260\260\354\240\225.kt" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" diff --git "a/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" "b/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" new file mode 100644 index 0000000..1412cab --- /dev/null +++ "b/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" @@ -0,0 +1,25 @@ +fun main() { + Solution().solution(k = 10, room_number = longArrayOf(1,4,5,6,3,1,8)) +} + +class Solution { + val checkMap = HashMap() // <현재 찾아볼 방, 찾아볼 다음 방> + fun solution(k: Long, room_number: LongArray): LongArray { + var answer = LongArray(room_number.size) + for (i in room_number.indices) { + answer[i] = bookRoom(room_number[i]) + } + return answer + } + + fun bookRoom(roomNumber : Long) : Long{ + if (!checkMap.containsKey(roomNumber)){ //해당 방이 비어있다면 해당 방 번호로 예약 + checkMap[roomNumber] = roomNumber + 1L + return roomNumber + }else{ + val nextRoomNumber = bookRoom(checkMap[roomNumber]!!) //다음 방 찾기 재귀 호출 + checkMap[roomNumber] = nextRoomNumber + return nextRoomNumber + } + } +} \ No newline at end of file From 38ee1497cd5b62f115a5fd5a96fecf7c5f6481ad Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 7 Mar 2023 22:28:38 +0900 Subject: [PATCH 543/822] =?UTF-8?q?SOLVE=20:=20=ED=98=B8=ED=85=94=5F?= =?UTF-8?q?=EB=B0=A9=5F=EB=B0=B0=EC=A0=95.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\260\251_\353\260\260\354\240\225.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" "b/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" new file mode 100644 index 0000000..bca4a80 --- /dev/null +++ "b/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" @@ -0,0 +1,30 @@ +import java.util.HashMap; +public class Problem { + public static void main(String[] args) { + new SolutionJava().solution(3, new long[]{1, 4, 5, 6, 3, 1, 8}); + } +} + +class SolutionJava { + static HashMap checkMap = new HashMap<>(); + public long[] solution(long k, long[] room_number) { + long[] answer = new long[room_number.length]; + for (int i = 0; i < room_number.length; i++) { + answer[i] = bookRoom(room_number[i]); + } + return answer; + } + + public long bookRoom(long roomNumber){ + if (!checkMap.containsKey(roomNumber)){ //해당 방이 비어있다면 해당 방 번호로 예약 + checkMap.put(roomNumber,roomNumber+1); + return roomNumber; + }else{ + long nextRoomNumber = bookRoom(checkMap.get(roomNumber)); + checkMap.put(roomNumber, nextRoomNumber); + return nextRoomNumber; + } + } +} + + From 06a054dc2af992b95c273bc120b0d45ad3ba9f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 7 Mar 2023 23:37:14 +0900 Subject: [PATCH 544/822] =?UTF-8?q?Create=20=ED=91=9C=ED=8E=B8=EC=A7=91.cp?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\221\234\355\216\270\354\247\221.cpp" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" diff --git "a/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" "b/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" new file mode 100644 index 0000000..0ef2727 --- /dev/null +++ "b/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" @@ -0,0 +1,66 @@ +#include +#include +#include + +using namespace std; + +struct Node { + int prev; + int val; + int next; +}; + +string solution(int n, int k, vector cmd) { + string answer = ""; + vector list; //l n r + for (int i = 0; i < n; i++) { + answer.push_back('O'); + list.push_back({ i-1, i, i + 1 }); + } + int selected = k; + stack st; + for (string str : cmd) { + if (str[0] == 'U' || str[0] == 'D') { + int x = stoi(str.substr(2)); + for (int i = 0; i < x; i++) { + if (str[0] == 'U') { + selected = list[selected].prev; + } + else { + selected = list[selected].next; + } + } + } + else if (str[0] == 'C') { + int l = list[selected].prev; + int r = list[selected].next; + st.push(list[selected]); + answer[selected] = 'X'; + if (l >= 0) { + list[l].next = r; + } + if (r < n) { + list[r].prev = l; + } + if (r >= n) { + selected = l; + } + else { + selected = r; + } + } + else { + Node num = st.top(); st.pop(); + int l = num.prev; + int r = num.next; + if (l >= 0) { + list[l].next = num.val; + } + if (r < n) { + list[r].prev = num.val; + } + answer[num.val] = 'O'; + } + } + return answer; +} From 24557c5c8a12818486abbce302aa2fc2f3cb6ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Tue, 7 Mar 2023 23:39:30 +0900 Subject: [PATCH 545/822] =?UTF-8?q?Update=20=ED=91=9C=ED=8E=B8=EC=A7=91.cp?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\221\234\355\216\270\354\247\221.cpp" | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git "a/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" "b/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" index 0ef2727..6cbe081 100644 --- "a/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" +++ "b/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" @@ -18,7 +18,7 @@ string solution(int n, int k, vector cmd) { list.push_back({ i-1, i, i + 1 }); } int selected = k; - stack st; + stack st; for (string str : cmd) { if (str[0] == 'U' || str[0] == 'D') { int x = stoi(str.substr(2)); @@ -34,7 +34,7 @@ string solution(int n, int k, vector cmd) { else if (str[0] == 'C') { int l = list[selected].prev; int r = list[selected].next; - st.push(list[selected]); + st.push(selected); answer[selected] = 'X'; if (l >= 0) { list[l].next = r; @@ -50,16 +50,16 @@ string solution(int n, int k, vector cmd) { } } else { - Node num = st.top(); st.pop(); - int l = num.prev; - int r = num.next; + int num = st.top(); st.pop(); + int l = list[num].prev; + int r = list[num].next; if (l >= 0) { - list[l].next = num.val; + list[l].next = num; } if (r < n) { - list[r].prev = num.val; + list[r].prev = num; } - answer[num.val] = 'O'; + answer[num] = 'O'; } } return answer; From bc92de54c8e24dd0a560fa0d59098a61884e2029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Wed, 8 Mar 2023 21:39:24 +0900 Subject: [PATCH 546/822] =?UTF-8?q?Create=20=ED=98=B8=ED=85=94=EB=B0=A9?= =?UTF-8?q?=EB=B0=B0=EC=A0=95.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\260\251\353\260\260\354\240\225.cpp" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" diff --git "a/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" "b/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" new file mode 100644 index 0000000..501d71b --- /dev/null +++ "b/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" @@ -0,0 +1,24 @@ +#include +#include +#include + +using namespace std; + +unordered_map parent; +vector answer; + +long long getParent(long long n) { + if (parent[n] == 0ll) { + return n; + } + return parent[n] = getParent(parent[n]); +} + +vector solution(long long k, vector room_number) { + for (long long n : room_number) { + long long num = getParent(n); + answer.push_back(num); + parent[num] = num+1; + } + return answer; +} From f23a47a8b3291cf3aea3aec9fd1c2ce65cafc083 Mon Sep 17 00:00:00 2001 From: "rsw1452@naver.com" Date: Thu, 9 Mar 2023 00:01:19 +0900 Subject: [PATCH 547/822] =?UTF-8?q?solve:=20=ED=98=B8=ED=85=94=20=EB=B0=A9?= =?UTF-8?q?=20=EB=B0=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\260\251_\353\260\260\354\240\225.java" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" "b/2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" new file mode 100644 index 0000000..190dbe7 --- /dev/null +++ "b/2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" @@ -0,0 +1,43 @@ +import ssafy.Solution_tree; + +import java.util.*; +import java.io.*; + +class Solution { + + HashMap map = new HashMap<>(); + + public static void main(String[] args) { + Solution solution = new Solution(); + solution.solution(10, new long[]{1, 3, 4, 1, 3, 1}); + } + + public long[] solution(long k, long[] room_number) { + int size = room_number.length; + long[] answer = new long[size]; + + for (int i = 0; i < size; i++) { + answer[i] = find(room_number[i]); + } + + return answer; + } + + private long find(long roomNum) { + // 방이 없다면 1을 추가해서 다음 방으로 갈 수 있게 한다 + if (!map.containsKey(roomNum)) { + map.put(roomNum, roomNum + 1); + return roomNum; + } + + // 방에 이미 누가 있다. 다른 호수를 찾아본다 + long findRoom = map.get(roomNum); + long emptyRoom = find(findRoom); + + map.put(roomNum, emptyRoom); + return emptyRoom; + } +} + + + From a362dff2c9af3c45f48ec272bf23b17d3121fa65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 10 Mar 2023 08:50:35 +0900 Subject: [PATCH 548/822] Update README.md --- 2023/03.09/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/2023/03.09/README.md b/2023/03.09/README.md index 40cc5ae..b9969ea 100644 --- a/2023/03.09/README.md +++ b/2023/03.09/README.md @@ -3,3 +3,4 @@ - 프로그래머스 - [표 편집](https://school.programmers.co.kr/learn/courses/30/lessons/81303) - [호텔 방 배정](https://school.programmers.co.kr/learn/courses/30/lessons/64063) + - [시험장 나누기](https://school.programmers.co.kr/learn/courses/30/lessons/81305) From 6c48a0e3412f69d1979712d16cc1b45d893e8e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Fri, 10 Mar 2023 08:50:54 +0900 Subject: [PATCH 549/822] Update README.md --- 2023/03.09/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2023/03.09/README.md b/2023/03.09/README.md index b9969ea..d423c64 100644 --- a/2023/03.09/README.md +++ b/2023/03.09/README.md @@ -1,4 +1,4 @@ -# 3.9(목) 스터디 +# 3.13(월) 스터디 - 프로그래머스 - [표 편집](https://school.programmers.co.kr/learn/courses/30/lessons/81303) From f5c82f64edf5fd093a8e7600b70419411d60bf5f Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 12 Mar 2023 10:32:22 +0900 Subject: [PATCH 550/822] complete --- ...355\221\234_\355\216\270\354\247\221.java" | 61 +++++++++++++++++++ ...353\260\251_\353\260\260\354\240\225.java" | 37 +++++++++++ 2 files changed, 98 insertions(+) create mode 100644 "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" create mode 100644 "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" "b/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" new file mode 100644 index 0000000..d86353b --- /dev/null +++ "b/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" @@ -0,0 +1,61 @@ +import java.util.Stack; +import java.util.StringTokenizer; + +public class PRG_표_편집 { + public static void main(String[] args) { + PRG_표_편집 s = new PRG_표_편집(); + + int n = 8; + int k = 2; + String[] cmd = {"D 2", "C", "U 3", "C", "D 4", "C", "U 2", "Z", "Z"}; + System.out.println(s.solution(n, k, cmd)); + } // End of main + + public String solution(int n, int k, String[] cmd) { + StringTokenizer st; + StringBuilder sb; + + Stack backupList = new Stack<>(); + int rowMax_num = n; + int cmd_len = cmd.length; + + for (int i = 0; i < cmd_len; i++) { + st = new StringTokenizer(cmd[i]); + String order = st.nextToken(); + + if (order.equals("D") || order.equals("U")) { + int X = Integer.parseInt(st.nextToken()); + + if (order.equals("D")) { + k += X; + } else if (order.equals("U")) { + k -= X; + } + } else if (order.equals("C")) { + backupList.push(k); + rowMax_num--; + + if (k == rowMax_num) { + k--; + } + } else if (order.equals("Z")) { + if (backupList.pop() <= k) { + k++; + } + + rowMax_num++; + } + } + + sb = new StringBuilder(); + for (int i = 0; i < rowMax_num; i++) { + sb.append('O'); + } + + while (!backupList.isEmpty()) { + sb.insert(backupList.pop().intValue(), 'X'); + } + + return sb.toString(); + } // End of solution +} // End of Solution class diff --git "a/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" "b/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" new file mode 100644 index 0000000..1bc2db0 --- /dev/null +++ "b/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" @@ -0,0 +1,37 @@ +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class PRG_호텔_방_배정 { + private static Map hashMap = new HashMap<>(); + + public static void main(String[] args) { + PRG_호텔_방_배정 s = new PRG_호텔_방_배정(); + + long k = 10; + long[] room_number = {1, 3, 4, 1, 3, 1}; + System.out.println(Arrays.toString(s.solution(k, room_number))); + } // End of main + + public long[] solution(long k, long[] room_number) { + int len = room_number.length; + long[] ans = new long[len]; + + for (int i = 0; i < len; i++) { + ans[i] = unionFind(room_number[i]); + } + + return ans; + } // End of solution + + private static long unionFind(long room) { + if(hashMap.containsKey(room)) { + hashMap.put(room, unionFind(hashMap.get(room))); + } else { + hashMap.put(room, room + 1); + return room; + } + + return hashMap.get(room); + } // End of unionFind +} // End of Solution class From 4ff68a05addbfbc4cded9e0f77db3a0c1159cdb3 Mon Sep 17 00:00:00 2001 From: bigyoung8375 Date: Sun, 12 Mar 2023 11:17:42 +0900 Subject: [PATCH 551/822] complete --- ...\353\202\230\353\210\204\352\270\260.java" | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" diff --git "a/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" "b/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" new file mode 100644 index 0000000..058da57 --- /dev/null +++ "b/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" @@ -0,0 +1,152 @@ +import java.util.ArrayList; +import java.util.List; + +public class PRG_시험장_나누기 { + private static final int INF = Integer.MAX_VALUE / 4; + private static final int MAX_SECTION = 10001; + static List[] list; + static int[][] cost; + + static class Node { + int data; + int left; + int right; + + public Node(int data, int left, int right) { + this.data = data; + this.left = left; + this.right = right; + } + } // End of Node class + + public static void main(String[] args) { + PRG_시험장_나누기 s = new PRG_시험장_나누기(); + + int k = 1; + int[] num = {6, 9, 7, 5}; + int[][] links = {{-1, -1}, {-1, -1}, {-1, 0}, {2, 1}}; + System.out.println(s.solution(k, num, links)); + } // End of main + + public int solution(int k, int[] num, int[][] links) { + int size = num.length; + list = new ArrayList[size]; + for (int i = 0; i < size; i++) { + list[i] = new ArrayList<>(); + } + + int sum = 0; + boolean[] check = new boolean[size]; + for (int i = 0; i < size; i++) { + int left = links[i][0]; + int right = links[i][1]; + + if (left != -1) { + check[left] = true; + } + + if (right != -1) { + check[right] = true; + } + list[i].add(new Node(num[i], left, right)); + sum += num[i]; + } + + int root = -1; + for (int i = 0; i < size; i++) { + if (!check[i]) { + root = i; + } + } + + int left = sum / k; + int right = sum; + if (left == right) { + return right; + } + + while (left < right) { + int mid = (left + right) / 2; + cost = new int[size][2]; + traversal(root, mid); + if (cost[root][0] <= k) { + right = mid; + } else { + left = mid + 1; + } + } + + return right; + } // End of solution + + private static void traversal(int pos, int w) { + Node curNode = list[pos].get(0); + int data = curNode.data; + int left = curNode.left; + int right = curNode.right; + + if (left != -1) { + traversal(left, w); + } + + if (right != -1) { + traversal(right, w); + } + + // 리프노드 일 때 + if (left == -1 && right == -1) { + if (data <= w) { + cost[pos][0] = 1; + cost[pos][1] = data; + } else { + cost[pos][0] = MAX_SECTION; + cost[pos][1] = INF; + } + } else if (left != -1 && right != -1) { + // full 노드 일 때 + if (data + cost[left][1] + cost[right][1] <= w) { + cost[pos][0] = cost[left][0] + cost[right][0] - 1; + cost[pos][1] = data + cost[left][1] + cost[right][1]; + } else if (data + Math.min(cost[left][1], cost[right][1]) <= w) { + cost[pos][0] = cost[left][0] + cost[right][0]; + cost[pos][1] = data + Math.min(cost[left][1], cost[right][1]); + } else if (data <= w) { + cost[pos][0] = cost[left][0] + cost[right][0] + 1; + cost[pos][1] = data; + } else { + cost[pos][0] = MAX_SECTION; + cost[pos][1] = INF; + } + } else { + // 왼쪽 자식만 있는 경우 + if (right == -1) { + if (data + cost[left][1] <= w) { + cost[pos][0] = cost[left][0]; + cost[pos][1] = data + cost[left][1]; + } else if (data <= w) { + cost[pos][0] = cost[left][0] + 1; + cost[pos][1] = data; + } else { + cost[pos][0] = MAX_SECTION; + cost[pos][1] = INF; + } + } + + // 오른쪽 자식만 있는 경우 + if (left == -1) { + if (data + cost[right][1] <= w) { + cost[pos][0] = cost[right][0]; + cost[pos][1] = data + cost[right][1]; + } else if (data <= w) { + cost[pos][0] = cost[right][0] + 1; + cost[pos][1] = data; + } else { + cost[pos][0] = MAX_SECTION; + cost[pos][1] = INF; + } + } + } + + + } // End of traversal +} // End of Solution class From fbbf0e9c19d4f26514fc00b6e79a69ca5c66fb02 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 13 Mar 2023 20:11:22 +0900 Subject: [PATCH 552/822] kihun --- ...34\355\216\270\354\247\221_linked_list.py" | 60 +++++++++++++++++++ ...24\353\260\251\353\260\260\354\240\225.py" | 31 ++++++++++ ...50\354\234\250\354\213\244\355\214\250.py" | 41 +++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" create mode 100644 "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" create mode 100644 "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" diff --git "a/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" "b/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" new file mode 100644 index 0000000..886c5e4 --- /dev/null +++ "b/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" @@ -0,0 +1,60 @@ +def solution(n, k, cmd): + # 0: [-1, 2]....n-1: [n-2, n] + linked_list = {i: [i-1, i+1] for i in range(n)} + now_select = k + delete = [] + answer = ["O" for _ in range(n)] + for command in cmd: + command = command.split() + + if command[0] == "U": + # 이전 링크 n번만큼 + for _ in range(int(command[1])): + now_select = linked_list[now_select][0] + elif command[0] == "D": + # 다음 링크 n번만큼 + for _ in range(int(command[1])): + now_select = linked_list[now_select][1] + # 삭제 + elif command[0] == "C": + prev_link, next_link = linked_list[now_select] + answer[now_select] = "X" + delete.append([prev_link, now_select, next_link]) + + # 선택된 곳이 마지막이라면 이전 링크로 + if next_link == n: + now_select = linked_list[now_select][0] + else: + now_select = linked_list[now_select][1] + + # 선택된 곳이 제일 처음이라면 삭제된 다음 곳을 제일 처음으로 최신화 + if prev_link == -1: + linked_list[next_link][0] = prev_link + # 선택된 곳이 제일 마지막이라면 삭제된 이전 곳을 제일 마지막으로 최신화 + elif next_link == n: + linked_list[prev_link][1] = next_link + # 일반 삭제 + else: + linked_list[prev_link][1] = next_link + linked_list[next_link][0] = prev_link + + # 복구 + else: + prev_link, now_link, next_link = delete.pop() + answer[now_link] = "O" + + # 첫번째를 복구하면 + if prev_link == -1: + linked_list[next_link][0] = now_link + # 마지막를 복구하면 + elif next_link == n: + linked_list[prev_link][1] = now_link + # 일반 복구 + else: + linked_list[prev_link][1] = now_link + linked_list[next_link][0] = now_link + + temp = "" + for c in answer: + temp += c + return temp diff --git "a/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" "b/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" new file mode 100644 index 0000000..e069bbd --- /dev/null +++ "b/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" @@ -0,0 +1,31 @@ +import sys + +sys.setrecursionlimit(10**8) + + +def find_empty(number, rooms): + if number not in rooms: + rooms[number] = number+1 + return number + + empty = find_empty(rooms[number], rooms) + # 빈 방이 나오기 전 방문했던 number들 모두 empty + 1로 갱신 + rooms[number] = empty + 1 + return empty + + +def solution(k, room_number): + answer = [] + # 해당 value는 다음 빈 방 번호 값 + # a방을 요구 했을 때 빈 방이 아니라면 + # 남은 빈 방 중 제일 작은 값으로 점프시키는 역할 + rooms = dict() + + for number in room_number: + empty = find_empty(number, rooms) + answer.append(empty) + + return answer + + +solution(10, [1, 3, 4, 1, 3, 1]) diff --git "a/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" "b/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" new file mode 100644 index 0000000..44b7f25 --- /dev/null +++ "b/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" @@ -0,0 +1,41 @@ +from collections import deque + +# 채점 결과 +# 정확성: 78.8 +# 효율성: 0.0 + +# 1 + + +def solution(k, room_number): + rooms = [i for i in range(1, k+1)] + queue = deque(rooms) + answer = [] + + for number in room_number: + room_list = list(queue) + filtered_room = filter(lambda x: x >= number, room_list) + selected = min(filtered_room) + answer.append(selected) + queue.remove(selected) + + return answer + +# 2 + + +def solution(k, room_number): + answer = [] + + for number in room_number: + idx = number + while True: + if idx not in answer: + answer.append(idx) + break + else: + idx += 1 + return answer + + +solution(10, [1, 3, 4, 1, 3, 1]) From 50e01427f74ed30aa4b6201b8e8c3b10b23c43c7 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:38:23 +0900 Subject: [PATCH 553/822] =?UTF-8?q?Create=20=ED=91=9C=ED=8E=B8=EC=A7=91.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\221\234\355\216\270\354\247\221.java" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" diff --git "a/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" "b/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" new file mode 100644 index 0000000..edeac6d --- /dev/null +++ "b/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" @@ -0,0 +1,52 @@ +import java.util.Stack; + +public class 표편집 { + public static void main(String[] args) { + int n = 8; + int k = 2; + String[] cmd = {"D 2", "C", "U 3", "C", "D 4", "C", "U 2", "Z", "Z"}; + + Solution s = new Solution(); + System.out.println(s.solution(n, k, cmd)); + } + + static class Solution { + public String solution(int n, int k, String[] cmd) { + int curNode = k; + int lastNode = n - 1; + StringBuilder sb = new StringBuilder(); + Stack removedNode = new Stack<>(); + + for (int i = 0; i < cmd.length; i++) { + char command = cmd[i].charAt(0); + + if (command == 'U') { + curNode -= Integer.parseInt(cmd[i].substring(2)); + } else if (command == 'D') { + curNode += Integer.parseInt(cmd[i].substring(2)); + } else if (command == 'C') { + removedNode.add(curNode); + if (curNode == lastNode) { + curNode--; + } + lastNode--; + } else if (command == 'Z') { + if(removedNode.pop() <= curNode){ + curNode++; + } + lastNode++; + } + } + + for (int i = 0; i < lastNode+1; i++) { + sb.append('O'); + } + + int size = removedNode.size(); + for (int i = 0; i < size; i++) { + sb.insert(removedNode.pop().intValue(), 'X'); + } + return sb.toString(); + } + } +} From 55e08377c81570e589fb341f0685f16e5d5042d9 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:38:43 +0900 Subject: [PATCH 554/822] =?UTF-8?q?Create=20=ED=98=B8=ED=85=94=EB=B0=A9?= =?UTF-8?q?=EB=B0=B0=EC=A0=95.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\260\251\353\260\260\354\240\225.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" "b/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" new file mode 100644 index 0000000..a6323c3 --- /dev/null +++ "b/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" @@ -0,0 +1,44 @@ +import java.util.HashMap; +import java.util.Map; + +public class 호텔방배정 { + public static void main(String[] args) { + Solution so = new Solution(); + long k = 10; + long[] room_number = {1, 3, 4, 1, 3, 1}; + long[] answer = so.solution(k, room_number); + for (int i = 0; i < answer.length; i++) { + System.out.printf(answer[i] + " "); + } + } + + static class Solution { + static long[] answer; + static Map room; + + public long[] solution(long k, long[] room_number) { + answer = new long[room_number.length]; + room = new HashMap<>(); + + for (int i = 0; i < answer.length; i++) { + answer[i] = getResult(room_number[i]); + } + + return answer; + } + + static long getResult(long roomNum) { + //방을 배정할 수 있는 경우 + if (!room.containsKey(roomNum)) { + room.put(roomNum, roomNum+1); + return roomNum; + } + + //이미 방이 배정되어 있는 경우 + long nextRoom = room.get(roomNum); + long emptyRoom = getResult(nextRoom); + room.put(roomNum, emptyRoom); + return emptyRoom; + } + } +} From 7f5ffefe38de6e4a0cb1a4ae22f885d40896eb9e Mon Sep 17 00:00:00 2001 From: Lee-Areum Date: Mon, 13 Mar 2023 20:50:26 +0900 Subject: [PATCH 555/822] =?UTF-8?q?fix:=20=ED=8F=B4=EB=8D=94=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {07.21 => 2022/07.21}/0721.md | 0 {07.21 => 2022/07.21}/readme.md | 0 .../\353\260\261\354\244\200 1110.java" | 0 .../kihun.py" | 0 .../Main.java" | 0 .../jiyun.py" | 0 .../sooyun.java" | 0 ...\354\202\254\354\235\264\355\201\264.java" | 42 +- .../jiwon.java" | 0 {07.25 => 2022/07.25}/readme.md | 0 .../\353\260\261\354\244\200 1476.jva" | 0 .../\353\260\261\354\244\200 1543.java" | 0 .../\353\260\261\354\244\200 2422.java" | 0 .../\353\260\261\354\244\200 3085.java" | 0 ...40\354\247\234\352\263\204\354\202\260.py" | 0 ...70\354\204\234\352\262\200\354\203\211.py" | 0 ...34\354\234\244\354\240\225\354\235\264.py" | 0 ...34\352\260\204\354\264\210\352\263\274.py" | 0 ...54\355\203\225\352\262\214\354\236\204.py" | 0 ...354\247\234_\352\263\204\354\202\260..cpp" | 0 ...\354\204\234_\352\262\200\354\203\211.cpp" | 0 ...\353\246\254\354\225\204\354\227\220_.cpp" | 0 ...4\355\203\225\352\262\214\354\236\204.cpp" | 0 ...0\354\247\234 \352\263\204\354\202\260.py" | 0 ...354\247\234 \352\263\204\354\202\260_2.py" | 0 ...0\354\204\234 \352\262\200\354\203\211.py" | 0 ...354\204\234 \352\262\200\354\203\211_2.py" | 0 ...354\204\234 \352\262\200\354\203\211_3.py" | 0 ...54\353\250\271\353\212\224\353\215\260.py" | 0 ...4\355\203\225 \352\262\214\354\236\204.py" | 0 ...355\203\225 \352\262\214\354\236\204_2.py" | 0 ...247\234\352\263\204\354\202\260_1476.java" | 0 ...204\234\352\262\200\354\203\211_1543.java" | 0 ...203\225\352\262\214\354\236\204_3085.java" | 0 ...225\234\354\234\244\354\240\225_2422.java" | 0 ...354\247\234_\352\263\204\354\202\260.java" | 0 ...354\204\234_\352\262\200\354\203\211.java" | 0 ...\353\250\271\353\212\224\353\215\260.java" | 0 ...\354\247\234\352\263\204\354\202\260.java" | 0 ...\354\204\234\352\262\200\354\203\211.java" | 0 ...\353\250\271\353\212\224\353\215\260.java" | 0 ...\355\203\225\352\262\214\354\236\204.java" | 0 ...\354\247\234\352\263\204\354\202\260.java" | 0 ...\354\204\234\352\262\200\354\203\211.java" | 0 ...\354\234\244\354\240\225\354\235\264.java" | 0 ...\355\203\225\352\262\214\354\236\204.java" | 0 {07.28 => 2022/07.28}/readme.md | 0 .../\353\260\261\354\244\200 17086.java" | 0 .../\353\260\261\354\244\200 2502.java" | 0 ...4\352\270\260\354\203\201\354\226\2642.py" | 0 ...24\355\230\270\353\236\221\354\235\264.py" | 0 ...\352\270\260\354\203\201\354\226\2642.cpp" | 0 ..._\355\230\270\353\236\221\354\235\264.cpp" | 0 ...4\352\270\260\354\203\201\354\226\2642.py" | 0 ...24\355\230\270\353\236\221\354\235\264.py" | 0 ...52\270\260_\354\203\201\354\226\2642.java" | 0 ...\355\230\270\353\236\221\354\235\264.java" | 0 ...2\270\260_\354\203\201\354\226\264_2.java" | 156 +++---- ...\355\230\270\353\236\221\354\235\264.java" | 74 +-- ...352\270\260\354\203\201\354\226\2642.java" | 0 {08.01 => 2022/08.01}/readme.md | 0 .../\353\260\261\354\244\200 11725.java" | 0 .../\353\260\261\354\244\200 1388.java" | 0 .../\353\260\261\354\244\200 15173.java" | 0 .../\353\260\261\354\244\200 2606.java" | 0 ...00\353\252\250\354\260\276\352\270\260.py" | 0 ...24\353\213\245\354\236\245\354\213\235.py" | 0 ...04\354\231\225\354\251\260\353\246\254.py" | 0 ...24\354\235\264\353\237\254\354\212\244.py" | 0 ...4\354\212\244_\355\213\200\353\246\274.py" | 0 ...0\353\252\250\354\260\276\352\270\260.cpp" | 0 ...4\353\213\245\354\236\245\354\213\235.cpp" | 0 ...4\354\231\225\354\240\244\353\246\254.cpp" | 0 ...4\354\235\264\353\237\254\354\212\244.cpp" | 0 ...\252\250\354\260\276\352\270\260_graph.py" | 0 ...\250\354\260\276\352\270\260_graph_bad.py" | 0 ...54\260\276\352\270\260_graph_bad_logic.py" | 0 ...54\260\276\352\270\260_graph_recursive.py" | 0 ...24\353\213\245\354\236\245\354\213\235.py" | 0 ...04\354\231\225\354\251\260\353\246\254.py" | 0 ...\353\213\245\354\236\245\354\213\235.java" | 0 ...\354\235\264\353\237\254\354\212\244.java" | 0 ...\354\231\225\354\240\244\353\246\254.java" | 0 ...\353\252\250\354\260\276\352\270\260.java" | 0 ...353\252\250_\354\260\276\352\270\260.java" | 0 ...\352\260\204\354\264\210\352\263\274.java" | 0 ...\353\213\245\354\236\245\354\213\235.java" | 0 ...354\231\225_\354\251\260\353\246\254.java" | 0 ...\354\235\264\353\237\254\354\212\244.java" | 0 ...353\252\250_\354\260\276\352\270\260.java" | 108 ++--- ...353\213\245_\354\236\245\354\213\235.java" | 152 +++---- ...354\231\225_\354\251\260\353\246\254.java" | 140 +++--- ...\235\264\353\237\254\354\212\244_BFS.java" | 122 ++--- ...\235\264\353\237\254\354\212\244_DFS.java" | 90 ++-- ...3\237\254\354\212\244_Floyd_Warshall.java" | 144 +++--- ...\353\252\250\354\260\276\352\270\260.java" | 0 ...\353\213\245\354\236\245\354\213\235.java" | 0 ...\354\231\225\354\251\260\353\246\254.java" | 0 ...\354\235\264\353\237\254\354\212\244.java" | 0 .../readme.md" | 0 {08.04 => 2022/08.04}/readme.md | 0 .../\353\260\261\354\244\200 1743.java" | 0 .../\353\260\261\354\244\200 2583.java" | 0 ...74\355\224\274\355\225\230\352\270\260.py" | 0 ...55\352\265\254\355\225\230\352\270\260.py" | 0 ..._\355\224\274\355\225\230\352\270\260.cpp" | 0 ..._\352\265\254\355\225\230\352\270\260.cpp" | 0 ...74\355\224\274\355\225\230\352\270\260.py" | 0 ...5 \352\265\254\355\225\230\352\270\260.py" | 0 ...\355\224\274\355\225\230\352\270\260.java" | 0 ...\352\265\254\355\225\230\352\270\260.java" | 0 ...\224\274\355\225\230\352\270\260_BFS.java" | 170 +++---- ...\224\274\355\225\230\352\270\260_DFS.java" | 132 +++--- ...\354\210\230\354\240\225\353\263\270.java" | 0 ...\265\254\355\225\230\352\270\260_BFS.java" | 190 ++++---- ...\265\254\355\225\230\352\270\260_DFS.java" | 156 +++---- .../readme" | 0 ...\355\224\274\355\225\230\352\270\260.java" | 0 ...\352\265\254\355\225\230\352\270\260.java" | 0 {08.08 => 2022/08.08}/readme.md | 0 .../\353\260\261\354\244\2001697.java" | 0 .../\353\260\261\354\244\2002644.java" | 0 ...50\353\260\224\352\274\255\354\247\210.py" | 0 ...14\354\210\230\352\263\204\354\202\260.py" | 0 ...0\353\260\224\352\274\255\354\247\210.cpp" | 0 ...4\354\210\230\352\263\204\354\202\260.cpp" | 0 ...53\260\224\352\274\255\354\247\210_bfs.py" | 0 ...\224\352\274\255\354\247\210_recursive.py" | 0 ...\352\274\255\354\247\210_recursive_bad.py" | 0 ...14\354\210\230\352\263\204\354\202\260.py" | 0 ...\353\260\224\352\274\255\354\247\210.java" | 0 ...\354\210\230\352\263\204\354\202\260.java" | 0 ...3\260\224\352\274\255\354\247\210_DP.java" | 102 ++--- ...\210\230\352\263\204\354\202\260_DFS.java" | 106 ++--- .../README.md" | 0 ...\353\260\224\352\274\255\354\247\210.java" | 0 ...\354\210\230\352\263\204\354\202\260.java" | 0 .../readme.md" | 0 {08.11 => 2022/08.11}/readme.md | 0 .../\353\260\261\354\244\200 2468.java" | 0 .../\353\260\261\354\244\20016953.java" | 0 .../\353\260\261\354\244\200_16953_AB.py" | 0 ...10\354\240\204\354\230\201\354\227\255.py" | 0 .../16953_AtoB.cpp" | 0 ...0\354\240\204\354\230\201\354\227\255.cpp" | 0 .../[BOJ_16953]A_B.py" | 0 ...10\354\240\204\354\230\201\354\227\255.py" | 0 .../16953_A_B.java" | 0 ...\354\240\204\354\230\201\354\227\255.java" | 0 .../Main_16953_AtoB_BFS.java" | 138 +++--- ...\353\260\230\352\265\254\355\230\204.java" | 94 ++-- ...\354\240\204\354\230\201\354\227\255.java" | 148 +++--- .../16953_AtoB.java" | 0 ...\354\240\204\354\230\201\354\227\255.java" | 0 .../readme.md" | 0 {08.15 => 2022/08.15}/readme.md | 0 .../\353\260\261\354\244\20016637.java" | 0 .../\353\260\261\354\244\20017070.java" | 0 ...24\352\260\200\355\225\230\352\270\260.py" | 0 ...4\354\230\256\352\270\260\352\270\2601.py" | 0 ...54\353\224\224\355\216\234\354\212\244.py" | 0 ...4\352\260\200\355\225\230\352\270\260.cpp" | 0 ..._\354\230\256\352\270\260\352\270\260.cpp" | 0 ..._\353\224\224\355\216\234\354\212\244.cpp" | 0 ... \354\230\256\352\270\260\352\270\2601.py" | 0 ...54\353\224\224\355\216\234\354\212\244.py" | 0 ...4\204\355\230\270\354\266\224\352\260\200" | 0 ...4\204\354\230\256\352\270\260\352\270\260" | 0 ...354\230\256\352\270\260\352\270\2601.java" | 0 ...\353\224\224\355\216\234\354\212\244.java" | 0 ...354\235\200_\353\262\214\354\240\220.java" | 132 +++--- ...\352\260\200\355\225\230\352\270\260.java" | 108 ++--- ...\353\224\224\355\216\234\354\212\244.java" | 84 ++-- ...\354\230\256\352\270\260\352\270\260.java" | 0 {08.18 => 2022/08.18}/readme.md | 0 ...64\353\266\231\354\235\264\352\270\260.py" | 0 ...1_\354\225\274\352\265\254\352\263\265.py" | 0 ..._\354\203\211\354\242\205\354\235\264.cpp" | 0 ..._\354\225\274\352\265\254\352\263\265.cpp" | 0 .../README.md" | 0 ...1]\354\225\274\352\265\254\352\263\265.py" | 0 ...34\352\260\204\354\264\210\352\263\274.py" | 0 ...5\264\353\266\231\354\235\264\352\270\260" | 0 .../\354\225\274\352\265\254\352\263\265" | 0 ...\353\266\231\354\235\264\352\270\260.java" | 0 ...\353\266\231\354\235\264\352\270\260.java" | 0 {08.22 => 2022/08.22}/readme.md | 0 .../\353\260\261\354\244\20017406.java" | 0 ...4\353\217\214\353\246\254\352\270\2604.py" | 0 ...60\355\224\204\353\246\254\355\204\260.py" | 0 ...\353\217\214\353\246\254\352\270\2604.cpp" | 0 ...353\217\214\353\246\254\352\270\2604.java" | 0 {08.25 => 2022/08.25}/readme.md | 0 .../\353\260\261\354\244\200 14502.java" | 0 .../\353\260\261\354\244\20014501.java" | 0 .../\353\260\261\354\244\20014889.java" | 0 ...244\200_14501_\355\207\264\354\202\254.py" | 0 ...2_\354\227\260\352\265\254\354\206\214.py" | 0 ...70\354\231\200\353\247\201\355\201\254.py" | 0 ...354\231\200\353\247\201\355\201\254DFS.py" | 0 .../14501_\355\207\264\354\202\254.cpp" | 0 ..._\354\227\260\352\265\254\354\206\214.cpp" | 0 ...\354\231\200 \353\247\201\355\201\254.cpp" | 0 .../[14501]\355\207\264\354\202\254.py" | 0 ...0\354\231\200 \353\247\201\355\201\254.py" | 0 ...354\231\200\353\247\201\355\201\254_14889" | 0 ...354\227\260\352\265\254\354\206\214_14502" | 0 .../\355\207\264\354\202\254_14501" | 0 .../14501_\355\207\264\354\202\254.java" | 0 ...\354\227\260\352\265\254\354\206\214.java" | 0 ...354\231\200 \353\247\201\355\201\254.java" | 0 .../Main_14501_\355\207\264\354\202\254.java" | 72 +-- ...\354\227\260\352\265\254\354\206\214.java" | 262 +++++------ ...\354\231\200\353\247\201\355\201\254.java" | 152 +++---- {08.28 => 2022/08.28}/readme.md | 0 ...0\353\246\254\354\236\241\352\270\260.cpp" | 0 .../\355\227\214\355\204\260.cpp" | 0 .../\355\227\214\355\204\260.java" | 0 .../Shuffle-O-Matic.java" | 0 ...\353\246\254\354\236\241\352\270\260.java" | 0 .../\355\227\214\355\204\260.java" | 0 .../Main_15172_\355\227\214\355\204\260.java" | 340 +++++++------- .../1\353\262\210.cpp" | 0 .../2\353\262\210.cpp" | 0 .../1\353\262\210.java" | 0 ...0\354\274\200\354\235\264\354\212\244.txt" | 0 {09.05 => 2022/09.05}/readme.md | 0 ...00\355\212\270\354\271\264\355\216\230.py" | 0 ...45\353\262\224\352\262\200\352\261\260.py" | 0 ...74\353\262\224\352\262\200\352\261\260.py" | 0 ...353\262\224 \352\262\200\352\261\260.java" | 0 ...353\262\224_\352\262\200\352\261\260.java" | 300 ++++++------ ...355\212\270_\354\271\264\355\216\230.java" | 188 ++++---- ...\353\262\224\352\262\200\352\261\260.java" | 0 {09.12 => 2022/09.12}/Readme.md | 0 .../swea2117.java" | 0 ...\352\277\200\354\261\204\354\267\250.java" | 0 ...\355\230\270\355\225\204\353\246\204.java" | 0 ...64\355\230\270\355\225\204\353\246\204.py" | 0 ...14\352\277\200\354\261\204\354\267\250.py" | 0 ...24\354\204\234\353\271\204\354\212\244.py" | 0 ...35\353\254\274\352\262\251\353\246\254.py" | 0 ...4\352\277\200 \354\261\204\354\267\250.py" | 0 ...5 \354\204\234\353\271\204\354\212\244.py" | 0 ...\353\254\274\352\262\251\353\246\254.java" | 0 ...\352\277\200\354\261\204\354\267\250.java" | 0 ...\355\230\270\355\225\204\353\246\204.java" | 0 ...\354\204\234\353\271\204\354\212\244.java" | 0 .../README.md" | 0 ...0\353\212\224 \355\212\270\353\237\255.kt" | 0 ...00\354\202\254\355\225\230\352\270\260.kt" | 0 .../\354\234\204\354\236\245.kt" | 0 ...355\230\270_\355\225\204\353\246\204.java" | 258 +++++------ ...\352\277\200\354\261\204\354\267\250.java" | 256 +++++------ ...\354\204\234\353\271\204\354\212\244.java" | 232 +++++----- ...353\254\274_\352\262\251\353\246\254.java" | 316 ++++++------- ...\354\204\234\353\271\204\354\212\244.java" | 0 {09.15 => 2022/09.15}/Readme.md | 0 ...35\354\202\254\354\213\234\352\260\204.py" | 0 ...11\354\240\225\353\271\204\354\206\214.py" | 0 ...35\354\202\254\354\213\234\352\260\204.py" | 0 ...1 \354\240\225\353\271\204\354\206\214.py" | 0 ...\354\202\254\354\213\234\352\260\204.java" | 0 ...\354\202\254\354\213\234\352\260\204.java" | 374 +++++++-------- .../readme.md" | 0 ... \353\247\214\353\223\244\352\270\260.cpp" | 0 ... \353\214\200\354\247\204\355\221\234.cpp" | 0 ...4 \353\247\214\353\223\244\352\270\260.kt" | 0 .../README.md" | 0 ...4 \353\247\214\353\223\244\352\270\260.kt" | 0 ...0\353\246\254 \353\233\260\352\270\260.kt" | 0 ...1 \353\214\200\354\247\204\355\221\234.kt" | 0 ...30\353\263\265\355\225\230\352\270\260.kt" | 0 ...4\354\235\230 \352\263\261\354\205\210.kt" | 0 ...\354\202\254\354\213\234\352\260\204.java" | 0 {09.19 => 2022/09.19}/Readme.md | 0 .../swea4012.java" | 0 .../swea4013.java" | 0 ...2_\354\232\224\353\246\254\354\202\254.py" | 0 ...64\355\225\234\354\236\220\354\204\235.py" | 0 ...0]\354\232\224\353\246\254\354\202\254.py" | 0 ...4\355\225\234 \354\236\220\354\204\235.py" | 0 ...\354\232\224\353\246\254\354\202\254.java" | 0 ...\355\225\234\354\236\220\354\204\235.java" | 0 ...\354\232\224\353\246\254\354\202\254.java" | 148 +++--- .../readme.md" | 0 .../N-Queen.cpp" | 0 ... \352\265\254\355\225\230\352\270\260.cpp" | 0 ...4\354\240\204\355\225\230\352\270\260.cpp" | 0 ...\354\235\264\354\235\230 \355\203\221.cpp" | 0 .../N-Queen.kt" | 0 ...0 \352\265\254\355\225\230\352\270\260.kt" | 0 ...4 \354\236\220\353\245\264\352\270\260.kt" | 0 ...14\354\240\204\355\225\230\352\270\260.kt" | 0 ...0\354\235\264\354\235\230 \355\203\221.kt" | 0 ...\354\232\224\353\246\254\354\202\254.java" | 0 ...\355\225\234\354\236\220\354\204\235.java" | 0 {09.22 => 2022/09.22}/readme.md | 0 ...\353\263\274\352\262\214\354\236\204.java" | 0 ...00\353\263\274\352\262\214\354\236\204.py" | 0 ...54\353\240\210\354\235\264\354\205\230.py" | 0 ...0\353\263\274 \352\262\214\354\236\204.py" | 0 ...\353\240\210\354\235\264\354\205\230.java" | 0 ...\353\263\274\352\262\214\354\236\204.java" | 0 ...353\263\274_\352\262\214\354\236\204.java" | 410 ++++++++--------- .../readme.md" | 0 ...5\354\235\270\355\225\230\352\270\260.cpp" | 0 ...0\354\261\204\355\214\205\353\260\251.cpp" | 0 ...4\352\270\210\352\263\204\354\202\260.cpp" | 0 ...25\354\235\270\355\225\230\352\270\260.kt" | 0 ...10\354\261\204\355\214\205\353\260\251.kt" | 0 ...4\352\270\210 \352\263\204\354\202\260.kt" | 0 {09.26 => 2022/09.26}/readme.md | 0 ...\353\217\214\352\271\250\352\270\260.java" | 0 ...70\355\217\254\353\260\260\354\226\221.py" | 0 ...75\353\217\214\352\271\250\352\270\260.py" | 0 ...75\353\217\214\352\271\250\352\270\260.py" | 0 .../readme.md" | 0 ...\353\245\270 \353\271\204\355\212\270.cpp" | 0 ...4\354\210\230\354\260\276\352\270\260.cpp" | 0 ...\354\210\230 \354\204\270\352\270\260.cpp" | 0 ...4\353\245\270 \353\271\204\355\212\270.kt" | 0 ...4\354\210\230 \354\260\276\352\270\260.kt" | 0 ...4\354\210\230 \354\204\270\352\270\260.kt" | 0 {10.03 => 2022/10.03}/readme.md | 0 ...04\353\260\200\353\262\210\355\230\270.py" | 0 ...04\352\270\260\354\203\201\354\226\264.py" | 0 ...10\353\223\261\355\225\231\352\265\220.py" | 0 .../README.md" | 0 ...04\353\260\200\353\262\210\355\230\270.py" | 0 ...04\352\270\260\354\203\201\354\226\264.py" | 0 ...352\270\260_\354\203\201\354\226\264.java" | 266 +++++------ ...\353\260\200\353\262\210\355\230\270.java" | 136 +++--- .../readme.md" | 0 ...1\353\213\254\355\214\275\354\235\264.cpp" | 0 ...0\353\247\214\353\223\244\352\270\260.cpp" | 0 ...1 \353\213\254\355\214\275\354\235\264.kt" | 0 ...0 \353\247\214\353\223\244\352\270\260.kt" | 0 ...\353\223\261\355\225\231\352\265\220.java" | 0 {10.06 => 2022/10.06}/readme.md | 0 ...74\354\247\200\354\225\210\353\205\225.py" | 0 ...\354\247\200_\354\225\210\353\205\225.cpp" | 0 ...4\354\247\200 \354\225\210\353\205\225.py" | 0 ...354\247\200\354\225\210\353\205\225~.java" | 0 ...\354\247\200 \354\225\210\353\205\225!.kt" | 0 {10.27 => 2022/10.27}/readme.md | 0 ...1\352\270\260_\352\262\214\354\236\204.py" | 0 ...\260\261\354\244\200_3190_\353\261\200.py" | 0 .../3190_\353\261\200.cpp" | 0 ...\352\270\260 \352\262\214\354\236\204.cpp" | 0 .../[BOJ_3190]\353\261\200.py" | 0 ...1\352\270\260 \352\262\214\354\236\204.py" | 0 .../\353\261\200.java" | 0 .../\353\261\200_dfs.java" | 0 ...\355\230\225\353\275\221\352\270\260.java" | 0 .../\353\261\200.kt" | 0 ...1\352\270\260 \352\262\214\354\236\204.kt" | 0 {10.31 => 2022/10.31}/readme.md | 0 .../bj1026.java" | 0 ...\353\246\254\353\233\260\352\270\260.java" | 0 ...00\353\246\254\353\233\260\352\270\260.py" | 66 +-- ...\244\200_1026_\353\263\264\353\254\274.py" | 36 +- .../1026_\353\263\264\353\254\274.cpp" | 0 ...0\353\246\254\353\233\260\352\270\260.cpp" | 0 ...00\353\246\254\353\233\260\352\270\260.py" | 0 .../\353\263\264\353\254\274.py" | 0 ...0\353\246\254 \353\233\260\352\270\260.kt" | 0 .../\353\263\264\353\254\274.kt" | 0 .../Main_1026_\353\263\264\353\254\274.java" | 0 ...\353\246\254\353\233\260\352\270\260.java" | 0 .../\353\263\264\353\254\274.java" | 0 {11.03 => 2022/11.03}/readme.md | 0 .../BJ14499.java" | 0 ...\353\266\200\353\266\204\355\225\251.java" | 0 ...1\354\235\230_\352\260\234\354\210\230.py" | 0 ...04\352\265\264\353\246\254\352\270\260.py" | 0 ..._\352\265\264\353\246\254\352\270\260.cpp" | 0 ...1\352\265\254\355\225\230\352\270\260.cpp" | 0 ...\354\235\230\352\260\234\354\210\230.java" | 0 ...\352\265\264\353\246\254\352\270\260.java" | 0 ...1\354\235\230 \352\260\234\354\210\230.kt" | 0 ...4 \352\265\264\353\246\254\352\270\260.kt" | 0 ...\352\265\264\353\246\254\352\270\260.java" | 200 ++++---- ...354\235\230 \352\260\234\354\210\230.java" | 0 ...\352\265\264\353\246\254\352\270\260.java" | 0 {11.07 => 2022/11.07}/readme.md | 0 .../pgm_lv2_\353\260\260\353\213\254.py" | 0 ...30\352\263\244\354\273\244\353\270\214.py" | 0 ...0\352\263\244\354\273\244\353\270\214.cpp" | 0 .../\353\260\260\353\213\254.cpp" | 0 ...\352\263\244\354\273\244\353\270\214.java" | 0 .../\353\260\260\353\213\254.java" | 0 ...0\352\263\244 \354\273\244\353\270\214.kt" | 0 .../\353\260\260\353\213\254.kt" | 0 .../Main_PRG_\353\260\260\353\213\254.java" | 208 ++++----- ...352\263\244_\354\273\244\353\270\214.java" | 0 {11.10 => 2022/11.10}/readme.md | 0 ...4_\354\202\254\352\260\201\355\230\225.py" | 0 ...64\352\263\274\354\227\260\354\202\260.py" | 0 ...\352\263\274_\354\227\260\354\202\260.cpp" | 0 ... \354\202\254\352\260\201\355\230\225.cpp" | 0 ...54\202\254\352\260\201\355\230\225_gcd.py" | 0 ...34\352\260\204\354\264\210\352\263\274.py" | 0 ...\354\202\254\352\260\201\355\230\225.java" | 0 ...\352\263\274\354\227\260\354\202\260.java" | 0 ...4 \354\202\254\352\260\201\355\230\225.kt" | 0 ...4\352\263\274 \354\227\260\354\202\260.kt" | 0 ...352\263\274_\354\227\260\354\202\260.java" | 430 +++++++++--------- ...\354\202\254\352\260\201\355\230\225.java" | 0 {11.14 => 2022/11.14}/readme.md | 0 ...0\353\212\224_\355\212\270\353\237\255.py" | 0 ...53\260\261\354\244\200_11559_Puyo_Puyo.py" | 0 ...4\354\232\224\353\277\214\354\232\224.cpp" | 0 ...0\353\212\224\355\212\270\353\237\255.cpp" | 0 ...\353\212\224\355\212\270\353\237\255.java" | 0 ...\354\232\224\353\277\214\354\232\224.java" | 0 .../Puyo Puyo.kt" | 0 ...0\353\212\224 \355\212\270\353\237\255.kt" | 0 .../Main_11559_Puyo_Puyo.java" | 324 ++++++------- ...353\212\224_\355\212\270\353\237\255.java" | 0 {11.17 => 2022/11.17}/readme.md | 0 ...1_\353\213\254\355\214\275\354\235\264.py" | 0 ..._\354\227\260\352\265\254\354\206\2143.py" | 0 ...1\353\213\254\355\214\275\354\235\264.cpp" | 0 ...1 \353\213\254\355\214\275\354\235\264.kt" | 0 ...\354\227\260\352\265\254\354\206\214 3.kt" | 0 ...54\227\260\352\265\254\354\206\214_3.java" | 0 {12.29 => 2022/12.29}/readme.md | 0 ...14\354\240\204\355\225\230\352\270\260.py" | 0 ...\244\200_1068_\355\212\270\353\246\254.py" | 0 .../1068_\355\212\270\353\246\254.cpp" | 0 ...4\354\240\204\355\225\230\352\270\260.cpp" | 0 .../1068_\355\212\270\353\246\254.kt" | 0 ...14\354\240\204\355\225\230\352\270\260.kt" | 0 .../Main 1068 \355\212\270\353\246\254.kt" | 0 ...14\354\240\204\355\225\230\352\270\260.kt" | 0 ...\354\240\204\355\225\230\352\270\260.java" | 0 .../\355\212\270\353\246\254.java" | 0 2023/{03.09 => 03.13}/README.md | 0 ...34\355\216\270\354\247\221_linked_list.py" | 0 ...24\353\260\251\353\260\260\354\240\225.py" | 0 ...50\354\234\250\354\213\244\355\214\250.py" | 0 ...353\260\251_\353\260\260\354\240\225.java" | 0 .../\355\221\234\355\216\270\354\247\221.cpp" | 0 ...4\353\260\251\353\260\260\354\240\225.cpp" | 0 ...\355\221\234\355\216\270\354\247\221.java" | 0 ...\353\260\251\353\260\260\354\240\225.java" | 0 ...353\260\251_\353\260\260\354\240\225.java" | 0 ..._\353\260\251_\353\260\260\354\240\225.kt" | 0 ...\353\202\230\353\210\204\352\270\260.java" | 0 ...355\221\234_\355\216\270\354\247\221.java" | 0 ...353\260\251_\353\260\260\354\240\225.java" | 0 452 files changed, 3781 insertions(+), 3781 deletions(-) rename {07.21 => 2022/07.21}/0721.md (100%) rename {07.21 => 2022/07.21}/readme.md (100%) rename "07.21/\352\266\214\354\243\274\355\230\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/\353\260\261\354\244\200 1110.java" => "2022/07.21/\352\266\214\354\243\274\355\230\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/\353\260\261\354\244\200 1110.java" (100%) rename "07.21/\354\206\241\352\270\260\355\233\210/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/kihun.py" => "2022/07.21/\354\206\241\352\270\260\355\233\210/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/kihun.py" (100%) rename "07.21/\354\235\264\354\225\204\353\246\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main.java" => "2022/07.21/\354\235\264\354\225\204\353\246\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main.java" (100%) rename "07.21/\354\235\264\354\247\200\354\234\244/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiyun.py" => "2022/07.21/\354\235\264\354\247\200\354\234\244/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiyun.py" (100%) rename "07.21/\354\241\260\354\210\230\354\227\260/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/sooyun.java" => "2022/07.21/\354\241\260\354\210\230\354\227\260/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/sooyun.java" (100%) rename "07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" => "2022/07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" (96%) rename "07.21/\355\231\251\354\247\200\354\233\220/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiwon.java" => "2022/07.21/\355\231\251\354\247\200\354\233\220/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiwon.java" (100%) rename {07.25 => 2022/07.25}/readme.md (100%) rename "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" => "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" (100%) rename "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" => "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" (100%) rename "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" => "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" (100%) rename "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" => "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" (100%) rename "07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" => "2022/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" (100%) rename "07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" => "2022/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" (100%) rename "07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" => "2022/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" (100%) rename "07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" => "2022/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" (100%) rename "07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" => "2022/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" (100%) rename "07.25/\354\235\264\354\225\204\353\246\204/1476_\353\202\240\354\247\234_\352\263\204\354\202\260..cpp" => "2022/07.25/\354\235\264\354\225\204\353\246\204/1476_\353\202\240\354\247\234_\352\263\204\354\202\260..cpp" (100%) rename "07.25/\354\235\264\354\225\204\353\246\204/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.cpp" => "2022/07.25/\354\235\264\354\225\204\353\246\204/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.cpp" (100%) rename "07.25/\354\235\264\354\225\204\353\246\204/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_.cpp" => "2022/07.25/\354\235\264\354\225\204\353\246\204/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_.cpp" (100%) rename "07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" => "2022/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" (100%) rename "07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" => "2022/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" (100%) rename "07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" => "2022/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" (100%) rename "07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" => "2022/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" (100%) rename "07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" => "2022/07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" (100%) rename "07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" => "2022/07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" (100%) rename "07.25/\354\241\260\354\210\230\354\227\260/1476_\353\202\240\354\247\234_\352\263\204\354\202\260.java" => "2022/07.25/\354\241\260\354\210\230\354\227\260/1476_\353\202\240\354\247\234_\352\263\204\354\202\260.java" (100%) rename "07.25/\354\241\260\354\210\230\354\227\260/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.java" => "2022/07.25/\354\241\260\354\210\230\354\227\260/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.java" (100%) rename "07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" => "2022/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" (100%) rename "07.25/\354\265\234\354\260\275\354\230\201/Main_1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" => "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" (100%) rename "07.25/\354\265\234\354\260\275\354\230\201/Main_1543_\353\254\270\354\204\234\352\262\200\354\203\211.java" => "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_1543_\353\254\270\354\204\234\352\262\200\354\203\211.java" (100%) rename "07.25/\354\265\234\354\260\275\354\230\201/Main_2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" => "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" (100%) rename "07.25/\354\265\234\354\260\275\354\230\201/Main_3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" => "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" (100%) rename "07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" => "2022/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" (100%) rename "07.25/\355\231\251\354\247\200\354\233\220/1476_\353\254\270\354\204\234\352\262\200\354\203\211.java" => "2022/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\254\270\354\204\234\352\262\200\354\203\211.java" (100%) rename "07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" => "2022/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" (100%) rename "07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" => "2022/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" (100%) rename {07.28 => 2022/07.28}/readme.md (100%) rename "07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" => "2022/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" (100%) rename "07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" => "2022/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" (100%) rename "07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" => "2022/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" (100%) rename "07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" => "2022/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" (100%) rename "07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" => "2022/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" (100%) rename "07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" => "2022/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" (100%) rename "07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" => "2022/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" (100%) rename "07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" => "2022/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" (100%) rename "07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" => "2022/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" (100%) rename "07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" => "2022/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" (100%) rename "07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" => "2022/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" (96%) rename "07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" => "2022/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" (96%) rename "07.28/\355\231\251\354\247\200\354\233\220/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.java" => "2022/07.28/\355\231\251\354\247\200\354\233\220/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.java" (100%) rename {08.01 => 2022/08.01}/readme.md (100%) rename "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 11725.java" => "2022/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 11725.java" (100%) rename "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1388.java" => "2022/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1388.java" (100%) rename "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 15173.java" => "2022/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 15173.java" (100%) rename "08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2606.java" => "2022/08.01/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2606.java" (100%) rename "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.py" => "2022/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.py" (100%) rename "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1388_\353\260\224\353\213\245\354\236\245\354\213\235.py" => "2022/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1388_\353\260\224\353\213\245\354\236\245\354\213\235.py" (100%) rename "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" => "2022/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" (100%) rename "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" => "2022/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244.py" (100%) rename "08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244_\355\213\200\353\246\274.py" => "2022/08.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2606_\353\260\224\354\235\264\353\237\254\354\212\244_\355\213\200\353\246\274.py" (100%) rename "08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" => "2022/08.01/\354\235\264\354\225\204\353\246\204/11725_\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250\354\260\276\352\270\260.cpp" (100%) rename "08.01/\354\235\264\354\225\204\353\246\204/1388_\353\260\224\353\213\245\354\236\245\354\213\235.cpp" => "2022/08.01/\354\235\264\354\225\204\353\246\204/1388_\353\260\224\353\213\245\354\236\245\354\213\235.cpp" (100%) rename "08.01/\354\235\264\354\225\204\353\246\204/16173_\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.cpp" => "2022/08.01/\354\235\264\354\225\204\353\246\204/16173_\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.cpp" (100%) rename "08.01/\354\235\264\354\225\204\353\246\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244.cpp" => "2022/08.01/\354\235\264\354\225\204\353\246\204/2606_\353\260\224\354\235\264\353\237\254\354\212\244.cpp" (100%) rename "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph.py" => "2022/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph.py" (100%) rename "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad.py" => "2022/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad.py" (100%) rename "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad_logic.py" => "2022/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_bad_logic.py" (100%) rename "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_recursive.py" => "2022/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_11725]\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260_graph_recursive.py" (100%) rename "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_1388]\353\260\224\353\213\245\354\236\245\354\213\235.py" => "2022/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_1388]\353\260\224\353\213\245\354\236\245\354\213\235.py" (100%) rename "08.01/\354\235\264\354\247\200\354\234\244/[BOJ_16173]\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" => "2022/08.01/\354\235\264\354\247\200\354\234\244/[BOJ_16173]\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.py" (100%) rename "08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\353\213\245\354\236\245\354\213\235.java" => "2022/08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\353\213\245\354\236\245\354\213\235.java" (100%) rename "08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\354\235\264\353\237\254\354\212\244.java" => "2022/08.01/\354\240\225\355\230\270\354\241\260/\353\260\224\354\235\264\353\237\254\354\212\244.java" (100%) rename "08.01/\354\240\225\355\230\270\354\241\260/\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.java" => "2022/08.01/\354\240\225\355\230\270\354\241\260/\354\240\220\355\224\204\354\231\225\354\240\244\353\246\254.java" (100%) rename "08.01/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\353\266\200\353\252\250\354\260\276\352\270\260.java" => "2022/08.01/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\353\266\200\353\252\250\354\260\276\352\270\260.java" (100%) rename "08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" => "2022/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" (100%) rename "08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" => "2022/08.01/\354\241\260\354\210\230\354\227\260/11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260_\354\213\234\352\260\204\354\264\210\352\263\274.java" (100%) rename "08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" => "2022/08.01/\354\241\260\354\210\230\354\227\260/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" (100%) rename "08.01/\354\241\260\354\210\230\354\227\260/16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" => "2022/08.01/\354\241\260\354\210\230\354\227\260/16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" (100%) rename "08.01/\354\241\260\354\210\230\354\227\260/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" => "2022/08.01/\354\241\260\354\210\230\354\227\260/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" (100%) rename "08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" => "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_11725_\355\212\270\353\246\254\354\235\230_\353\266\200\353\252\250_\354\260\276\352\270\260.java" (96%) rename "08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" => "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" (96%) rename "08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" => "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" (95%) rename "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.java" => "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_BFS.java" (96%) rename "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" => "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_DFS.java" (96%) rename "08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd_Warshall.java" => "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_2606_\353\260\224\354\235\264\353\237\254\354\212\244_Floyd_Warshall.java" (95%) rename "08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" => "2022/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" (100%) rename "08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" => "2022/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" (100%) rename "08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" => "2022/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" (100%) rename "08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" => "2022/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" (100%) rename "08.01/\355\231\251\354\247\200\354\233\220/readme.md" => "2022/08.01/\355\231\251\354\247\200\354\233\220/readme.md" (100%) rename {08.04 => 2022/08.04}/readme.md (100%) rename "08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" => "2022/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" (100%) rename "08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" => "2022/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" (100%) rename "08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" => "2022/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" (100%) rename "08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" => "2022/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" (100%) rename "08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" => "2022/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" (100%) rename "08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" => "2022/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" (100%) rename "08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" => "2022/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" (100%) rename "08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" => "2022/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" (100%) rename "08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" => "2022/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" (100%) rename "08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" => "2022/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" (100%) rename "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" => "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" (95%) rename "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" => "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" (96%) rename "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" => "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" (100%) rename "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" => "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" (96%) rename "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" => "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" (96%) rename "08.04/\354\265\234\354\260\275\354\230\201/readme" => "2022/08.04/\354\265\234\354\260\275\354\230\201/readme" (100%) rename "08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" => "2022/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" (100%) rename "08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" => "2022/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" (100%) rename {08.08 => 2022/08.08}/readme.md (100%) rename "08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" => "2022/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" (100%) rename "08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" => "2022/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" (100%) rename "08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" => "2022/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" (100%) rename "08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" => "2022/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" (100%) rename "08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" => "2022/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" (100%) rename "08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" => "2022/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" (100%) rename "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" => "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" (100%) rename "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" => "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" (100%) rename "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" => "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" (100%) rename "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" => "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" (100%) rename "08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" => "2022/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" (100%) rename "08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" => "2022/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" (100%) rename "08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" => "2022/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" (96%) rename "08.08/\354\265\234\354\260\275\354\230\201/Main_2644_\354\264\214\354\210\230\352\263\204\354\202\260_DFS.java" => "2022/08.08/\354\265\234\354\260\275\354\230\201/Main_2644_\354\264\214\354\210\230\352\263\204\354\202\260_DFS.java" (96%) rename "08.08/\354\265\234\354\260\275\354\230\201/README.md" => "2022/08.08/\354\265\234\354\260\275\354\230\201/README.md" (100%) rename "08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" => "2022/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" (100%) rename "08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" => "2022/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" (100%) rename "08.08/\355\231\251\354\247\200\354\233\220/readme.md" => "2022/08.08/\355\231\251\354\247\200\354\233\220/readme.md" (100%) rename {08.11 => 2022/08.11}/readme.md (100%) rename "08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" => "2022/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" (100%) rename "08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" => "2022/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" (100%) rename "08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" => "2022/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" (100%) rename "08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" => "2022/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" (100%) rename "08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" => "2022/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" (100%) rename "08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" => "2022/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" (100%) rename "08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" => "2022/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" (100%) rename "08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" => "2022/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" (100%) rename "08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" => "2022/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" (100%) rename "08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" => "2022/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" (100%) rename "08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" => "2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" (95%) rename "08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" => "2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" (95%) rename "08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" => "2022/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" (96%) rename "08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" => "2022/08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" (100%) rename "08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" => "2022/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" (100%) rename "08.11/\355\231\251\354\247\200\354\233\220/readme.md" => "2022/08.11/\355\231\251\354\247\200\354\233\220/readme.md" (100%) rename {08.15 => 2022/08.15}/readme.md (100%) rename "08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" => "2022/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" (100%) rename "08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" => "2022/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" (100%) rename "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" => "2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" (100%) rename "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" => "2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" (100%) rename "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" => "2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" (100%) rename "08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" => "2022/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" (100%) rename "08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" => "2022/08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" (100%) rename "08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" => "2022/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" (100%) rename "08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" => "2022/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" (100%) rename "08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" => "2022/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" (100%) rename "08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" => "2022/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" (100%) rename "08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" => "2022/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" (100%) rename "08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" => "2022/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" (100%) rename "08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" => "2022/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" (100%) rename "08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" => "2022/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" (97%) rename "08.15/\354\265\234\354\260\275\354\230\201/Main_16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.java" => "2022/08.15/\354\265\234\354\260\275\354\230\201/Main_16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.java" (96%) rename "08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" => "2022/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" (97%) rename "08.15/\355\231\251\354\247\200\354\233\220/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260.java" => "2022/08.15/\355\231\251\354\247\200\354\233\220/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260.java" (100%) rename {08.18 => 2022/08.18}/readme.md (100%) rename "08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17136_\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260.py" => "2022/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17136_\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260.py" (100%) rename "08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265.py" => "2022/08.18/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17281_\354\225\274\352\265\254\352\263\265.py" (100%) rename "08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" => "2022/08.18/\354\235\264\354\225\204\353\246\204/17136_\354\203\211\354\242\205\354\235\264.cpp" (100%) rename "08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" => "2022/08.18/\354\235\264\354\225\204\353\246\204/17281_\354\225\274\352\265\254\352\263\265.cpp" (100%) rename "08.18/\354\235\264\354\247\200\354\234\244/README.md" => "2022/08.18/\354\235\264\354\247\200\354\234\244/README.md" (100%) rename "08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265.py" => "2022/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265.py" (100%) rename "08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265_\354\213\234\352\260\204\354\264\210\352\263\274.py" => "2022/08.18/\354\235\264\354\247\200\354\234\244/[BOJ_17281]\354\225\274\352\265\254\352\263\265_\354\213\234\352\260\204\354\264\210\352\263\274.py" (100%) rename "08.18/\354\240\225\355\230\270\354\241\260/\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260" => "2022/08.18/\354\240\225\355\230\270\354\241\260/\354\203\211\354\242\205\354\235\264\353\266\231\354\235\264\352\270\260" (100%) rename "08.18/\354\240\225\355\230\270\354\241\260/\354\225\274\352\265\254\352\263\265" => "2022/08.18/\354\240\225\355\230\270\354\241\260/\354\225\274\352\265\254\352\263\265" (100%) rename "08.18/\354\241\260\354\210\230\354\227\260/17136_\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" => "2022/08.18/\354\241\260\354\210\230\354\227\260/17136_\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" (100%) rename "08.18/\355\231\251\354\247\200\354\233\220/\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" => "2022/08.18/\355\231\251\354\247\200\354\233\220/\354\203\211\354\242\205\354\235\264_\353\266\231\354\235\264\352\270\260.java" (100%) rename {08.22 => 2022/08.22}/readme.md (100%) rename "08.22/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017406.java" => "2022/08.22/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017406.java" (100%) rename "08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.py" => "2022/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.py" (100%) rename "08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3954_Brain_fk\354\235\270\355\204\260\355\224\204\353\246\254\355\204\260.py" => "2022/08.22/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3954_Brain_fk\354\235\270\355\204\260\355\224\204\353\246\254\355\204\260.py" (100%) rename "08.22/\354\235\264\354\225\204\353\246\204/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.cpp" => "2022/08.22/\354\235\264\354\225\204\353\246\204/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.cpp" (100%) rename "08.22/\354\241\260\354\210\230\354\227\260/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.java" => "2022/08.22/\354\241\260\354\210\230\354\227\260/17406_\353\260\260\354\227\264\353\217\214\353\246\254\352\270\2604.java" (100%) rename {08.25 => 2022/08.25}/readme.md (100%) rename "08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 14502.java" => "2022/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 14502.java" (100%) rename "08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014501.java" => "2022/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014501.java" (100%) rename "08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014889.java" => "2022/08.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20014889.java" (100%) rename "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14501_\355\207\264\354\202\254.py" => "2022/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14501_\355\207\264\354\202\254.py" (100%) rename "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14502_\354\227\260\352\265\254\354\206\214.py" => "2022/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14502_\354\227\260\352\265\254\354\206\214.py" (100%) rename "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.py" => "2022/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.py" (100%) rename "08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254DFS.py" => "2022/08.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254DFS.py" (100%) rename "08.25/\354\235\264\354\225\204\353\246\204/14501_\355\207\264\354\202\254.cpp" => "2022/08.25/\354\235\264\354\225\204\353\246\204/14501_\355\207\264\354\202\254.cpp" (100%) rename "08.25/\354\235\264\354\225\204\353\246\204/14502_\354\227\260\352\265\254\354\206\214.cpp" => "2022/08.25/\354\235\264\354\225\204\353\246\204/14502_\354\227\260\352\265\254\354\206\214.cpp" (100%) rename "08.25/\354\235\264\354\225\204\353\246\204/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.cpp" => "2022/08.25/\354\235\264\354\225\204\353\246\204/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.cpp" (100%) rename "08.25/\354\235\264\354\247\200\354\234\244/[14501]\355\207\264\354\202\254.py" => "2022/08.25/\354\235\264\354\247\200\354\234\244/[14501]\355\207\264\354\202\254.py" (100%) rename "08.25/\354\235\264\354\247\200\354\234\244/[14889]\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.py" => "2022/08.25/\354\235\264\354\247\200\354\234\244/[14889]\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.py" (100%) rename "08.25/\354\240\225\355\230\270\354\241\260/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" => "2022/08.25/\354\240\225\355\230\270\354\241\260/\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254_14889" (100%) rename "08.25/\354\240\225\355\230\270\354\241\260/\354\227\260\352\265\254\354\206\214_14502" => "2022/08.25/\354\240\225\355\230\270\354\241\260/\354\227\260\352\265\254\354\206\214_14502" (100%) rename "08.25/\354\240\225\355\230\270\354\241\260/\355\207\264\354\202\254_14501" => "2022/08.25/\354\240\225\355\230\270\354\241\260/\355\207\264\354\202\254_14501" (100%) rename "08.25/\354\241\260\354\210\230\354\227\260/14501_\355\207\264\354\202\254.java" => "2022/08.25/\354\241\260\354\210\230\354\227\260/14501_\355\207\264\354\202\254.java" (100%) rename "08.25/\354\241\260\354\210\230\354\227\260/14502_\354\227\260\352\265\254\354\206\214.java" => "2022/08.25/\354\241\260\354\210\230\354\227\260/14502_\354\227\260\352\265\254\354\206\214.java" (100%) rename "08.25/\354\241\260\354\210\230\354\227\260/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.java" => "2022/08.25/\354\241\260\354\210\230\354\227\260/14889_\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254.java" (100%) rename "08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" => "2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14501_\355\207\264\354\202\254.java" (97%) rename "08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" => "2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" (95%) rename "08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" => "2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" (96%) rename {08.28 => 2022/08.28}/readme.md (100%) rename "08.28/\354\235\264\354\225\204\353\246\204/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.cpp" => "2022/08.28/\354\235\264\354\225\204\353\246\204/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.cpp" (100%) rename "08.28/\354\235\264\354\225\204\353\246\204/\355\227\214\355\204\260.cpp" => "2022/08.28/\354\235\264\354\225\204\353\246\204/\355\227\214\355\204\260.cpp" (100%) rename "08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" => "2022/08.28/\354\240\225\355\230\270\354\241\260/\355\227\214\355\204\260.java" (100%) rename "08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" => "2022/08.28/\354\241\260\354\210\230\354\227\260/Shuffle-O-Matic.java" (100%) rename "08.28/\354\241\260\354\210\230\354\227\260/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.java" => "2022/08.28/\354\241\260\354\210\230\354\227\260/\353\202\232\354\213\234\355\204\260 \354\236\220\353\246\254\354\236\241\352\270\260.java" (100%) rename "08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" => "2022/08.28/\354\241\260\354\210\230\354\227\260/\355\227\214\355\204\260.java" (100%) rename "08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" => "2022/08.28/\354\265\234\354\260\275\354\230\201/Main_15172_\355\227\214\355\204\260.java" (97%) rename "09.01/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" => "2022/09.01/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" (100%) rename "09.01/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" => "2022/09.01/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" (100%) rename "09.01/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" => "2022/09.01/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" (100%) rename "09.01/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" => "2022/09.01/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" (100%) rename {09.05 => 2022/09.05}/readme.md (100%) rename "09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" => "2022/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" (100%) rename "09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" => "2022/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" (100%) rename "09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" => "2022/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" (100%) rename "09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" => "2022/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" (100%) rename "09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" => "2022/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" (97%) rename "09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" => "2022/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" (97%) rename "09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" => "2022/09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" (100%) rename {09.12 => 2022/09.12}/Readme.md (100%) rename "09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" => "2022/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" (100%) rename "09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" => "2022/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" (100%) rename "09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" => "2022/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" (100%) rename "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" => "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" (100%) rename "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" => "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" (100%) rename "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" => "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" (100%) rename "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" => "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" (100%) rename "09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" => "2022/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" (100%) rename "09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" => "2022/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" (100%) rename "09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" => "2022/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" (100%) rename "09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" => "2022/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" (100%) rename "09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" => "2022/09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" (100%) rename "09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" => "2022/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" (100%) rename "09.12/\354\241\260\354\210\230\354\227\260/README.md" => "2022/09.12/\354\241\260\354\210\230\354\227\260/README.md" (100%) rename "09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" => "2022/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" (100%) rename "09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" => "2022/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" (100%) rename "09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" => "2022/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" (100%) rename "09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" => "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" (96%) rename "09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" => "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" (97%) rename "09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" => "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" (97%) rename "09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" => "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" (97%) rename "09.12/\355\231\251\354\247\200\354\233\220/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" => "2022/09.12/\355\231\251\354\247\200\354\233\220/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" (100%) rename {09.15 => 2022/09.15}/Readme.md (100%) rename "09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" => "2022/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" (100%) rename "09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" => "2022/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" (100%) rename "09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" => "2022/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" (100%) rename "09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\260\250\353\237\211 \354\240\225\353\271\204\354\206\214.py" => "2022/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\260\250\353\237\211 \354\240\225\353\271\204\354\206\214.py" (100%) rename "09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" => "2022/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" (100%) rename "09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" => "2022/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" (97%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" (100%) rename "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" => "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" (100%) rename "09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" => "2022/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" (100%) rename {09.19 => 2022/09.19}/Readme.md (100%) rename "09.19/\352\266\214\354\243\274\355\230\204/swea4012.java" => "2022/09.19/\352\266\214\354\243\274\355\230\204/swea4012.java" (100%) rename "09.19/\352\266\214\354\243\274\355\230\204/swea4013.java" => "2022/09.19/\352\266\214\354\243\274\355\230\204/swea4013.java" (100%) rename "09.19/\354\206\241\352\270\260\355\233\210/SWEA_4012_\354\232\224\353\246\254\354\202\254.py" => "2022/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4012_\354\232\224\353\246\254\354\202\254.py" (100%) rename "09.19/\354\206\241\352\270\260\355\233\210/SWEA_4013_\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.py" => "2022/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4013_\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.py" (100%) rename "09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230 SW \354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\232\224\353\246\254\354\202\254.py" => "2022/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230 SW \354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\232\224\353\246\254\354\202\254.py" (100%) rename "09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\212\271\354\235\264\355\225\234 \354\236\220\354\204\235.py" => "2022/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\212\271\354\235\264\355\225\234 \354\236\220\354\204\235.py" (100%) rename "09.19/\354\240\225\355\230\270\354\241\260/\354\232\224\353\246\254\354\202\254.java" => "2022/09.19/\354\240\225\355\230\270\354\241\260/\354\232\224\353\246\254\354\202\254.java" (100%) rename "09.19/\354\240\225\355\230\270\354\241\260/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" => "2022/09.19/\354\240\225\355\230\270\354\241\260/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" (100%) rename "09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" => "2022/09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" (96%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230\352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.cpp" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230\352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.cpp" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.cpp" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.cpp" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/N-Queen.kt" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/N-Queen.kt" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230 \352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.kt" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230 \352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.kt" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/n^2 \353\260\260\354\227\264 \354\236\220\353\245\264\352\270\260.kt" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/n^2 \353\260\260\354\227\264 \354\236\220\353\245\264\352\270\260.kt" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" (100%) rename "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.kt" => "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.kt" (100%) rename "09.19/\355\231\251\354\247\200\354\233\220/\354\232\224\353\246\254\354\202\254.java" => "2022/09.19/\355\231\251\354\247\200\354\233\220/\354\232\224\353\246\254\354\202\254.java" (100%) rename "09.19/\355\231\251\354\247\200\354\233\220/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" => "2022/09.19/\355\231\251\354\247\200\354\233\220/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" (100%) rename {09.22 => 2022/09.22}/readme.md (100%) rename "09.22/\352\266\214\354\243\274\355\230\204/\355\225\200\353\263\274\352\262\214\354\236\204.java" => "2022/09.22/\352\266\214\354\243\274\355\230\204/\355\225\200\353\263\274\352\262\214\354\236\204.java" (100%) rename "09.22/\354\206\241\352\270\260\355\233\210/SWEA_5650_\355\225\200\353\263\274\352\262\214\354\236\204.py" => "2022/09.22/\354\206\241\352\270\260\355\233\210/SWEA_5650_\355\225\200\353\263\274\352\262\214\354\236\204.py" (100%) rename "09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\233\220\354\236\220 \354\206\214\353\251\270 \354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.py" => "2022/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\233\220\354\236\220 \354\206\214\353\251\270 \354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.py" (100%) rename "09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\225\200\353\263\274 \352\262\214\354\236\204.py" => "2022/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\225\200\353\263\274 \352\262\214\354\236\204.py" (100%) rename "09.22/\354\240\225\355\230\270\354\241\260/\354\233\220\354\236\220\354\206\214\353\251\270\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.java" => "2022/09.22/\354\240\225\355\230\270\354\241\260/\354\233\220\354\236\220\354\206\214\353\251\270\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.java" (100%) rename "09.22/\354\240\225\355\230\270\354\241\260/\355\225\200\353\263\274\352\262\214\354\236\204.java" => "2022/09.22/\354\240\225\355\230\270\354\241\260/\355\225\200\353\263\274\352\262\214\354\236\204.java" (100%) rename "09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" => "2022/09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" (97%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" (100%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.cpp" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.cpp" (100%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" (100%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.cpp" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.cpp" (100%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.kt" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.kt" (100%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.kt" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.kt" (100%) rename "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.kt" => "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.kt" (100%) rename {09.26 => 2022/09.26}/readme.md (100%) rename "09.26/\352\266\214\354\243\274\355\230\204/\353\262\275\353\217\214\352\271\250\352\270\260.java" => "2022/09.26/\352\266\214\354\243\274\355\230\204/\353\262\275\353\217\214\352\271\250\352\270\260.java" (100%) rename "09.26/\354\206\241\352\270\260\355\233\210/SWEA_5653_\354\244\204\352\270\260\354\204\270\355\217\254\353\260\260\354\226\221.py" => "2022/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5653_\354\244\204\352\270\260\354\204\270\355\217\254\353\260\260\354\226\221.py" (100%) rename "09.26/\354\206\241\352\270\260\355\233\210/SWEA_5656_\353\262\275\353\217\214\352\271\250\352\270\260.py" => "2022/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5656_\353\262\275\353\217\214\352\271\250\352\270\260.py" (100%) rename "09.26/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\275\353\217\214\352\271\250\352\270\260.py" => "2022/09.26/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\275\353\217\214\352\271\250\352\270\260.py" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/2\352\260\234\354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.cpp" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/2\352\260\234\354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.cpp" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\206\214\354\210\230\354\260\276\352\270\260.cpp" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\206\214\354\210\230\354\260\276\352\270\260.cpp" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\277\274\353\223\234\354\225\225\354\266\225\355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.cpp" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\277\274\353\223\234\354\225\225\354\266\225\355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.cpp" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/2\352\260\234 \354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.kt" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/2\352\260\234 \354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.kt" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\206\214\354\210\230 \354\260\276\352\270\260.kt" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\206\214\354\210\230 \354\260\276\352\270\260.kt" (100%) rename "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\277\274\353\223\234\354\225\225\354\266\225 \355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.kt" => "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\277\274\353\223\234\354\225\225\354\266\225 \355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.kt" (100%) rename {10.03 => 2022/10.03}/readme.md (100%) rename "10.03/\354\206\241\352\270\260\355\233\210/SWEA_5658_\353\263\264\353\254\274\354\203\201\354\236\220\353\271\204\353\260\200\353\262\210\355\230\270.py" => "2022/10.03/\354\206\241\352\270\260\355\233\210/SWEA_5658_\353\263\264\353\254\274\354\203\201\354\236\220\353\271\204\353\260\200\353\262\210\355\230\270.py" (100%) rename "10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264.py" => "2022/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264.py" (100%) rename "10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_21608_\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.py" => "2022/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_21608_\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.py" (100%) rename "10.03/\354\235\264\354\247\200\354\234\244/README.md" => "2022/10.03/\354\235\264\354\247\200\354\234\244/README.md" (100%) rename "10.03/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\263\264\353\254\274\354\203\201\354\236\220 \353\271\204\353\260\200\353\262\210\355\230\270.py" => "2022/10.03/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\263\264\353\254\274\354\203\201\354\236\220 \353\271\204\353\260\200\353\262\210\355\230\270.py" (100%) rename "10.03/\354\235\264\354\247\200\354\234\244/\354\225\204\352\270\260\354\203\201\354\226\264.py" => "2022/10.03/\354\235\264\354\247\200\354\234\244/\354\225\204\352\270\260\354\203\201\354\226\264.py" (100%) rename "10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" => "2022/10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" (97%) rename "10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" => "2022/10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" (97%) rename "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" => "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" (100%) rename "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" => "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" (100%) rename "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" => "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" (100%) rename "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" => "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" (100%) rename "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260.kt" => "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260.kt" (100%) rename "10.03/\355\231\251\354\247\200\354\233\220/\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.java" => "2022/10.03/\355\231\251\354\247\200\354\233\220/\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.java" (100%) rename {10.06 => 2022/10.06}/readme.md (100%) rename "10.06/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225.py" => "2022/10.06/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225.py" (100%) rename "10.06/\354\235\264\354\225\204\353\246\204/17144_\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225.cpp" => "2022/10.06/\354\235\264\354\225\204\353\246\204/17144_\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225.cpp" (100%) rename "10.06/\354\235\264\354\247\200\354\234\244/\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225.py" => "2022/10.06/\354\235\264\354\247\200\354\234\244/\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225.py" (100%) rename "10.06/\354\240\225\355\230\270\354\241\260/\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225~.java" => "2022/10.06/\354\240\225\355\230\270\354\241\260/\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225~.java" (100%) rename "10.06/\354\241\260\354\210\230\354\227\260/17144_\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.kt" => "2022/10.06/\354\241\260\354\210\230\354\227\260/17144_\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.kt" (100%) rename {10.27 => 2022/10.27}/readme.md (100%) rename "10.27/\354\206\241\352\270\260\355\233\210/pgm_lv1_\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204.py" => "2022/10.27/\354\206\241\352\270\260\355\233\210/pgm_lv1_\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204.py" (100%) rename "10.27/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3190_\353\261\200.py" => "2022/10.27/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3190_\353\261\200.py" (100%) rename "10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" => "2022/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" (100%) rename "10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" => "2022/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" (100%) rename "10.27/\354\235\264\354\247\200\354\234\244/[BOJ_3190]\353\261\200.py" => "2022/10.27/\354\235\264\354\247\200\354\234\244/[BOJ_3190]\353\261\200.py" (100%) rename "10.27/\354\235\264\354\247\200\354\234\244/[Programmers_ver1]\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.py" => "2022/10.27/\354\235\264\354\247\200\354\234\244/[Programmers_ver1]\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.py" (100%) rename "10.27/\354\240\225\355\230\270\354\241\260/\353\261\200.java" => "2022/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200.java" (100%) rename "10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" => "2022/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" (100%) rename "10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" => "2022/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" (100%) rename "10.27/\354\241\260\354\210\230\354\227\260/\353\261\200.kt" => "2022/10.27/\354\241\260\354\210\230\354\227\260/\353\261\200.kt" (100%) rename "10.27/\354\241\260\354\210\230\354\227\260/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.kt" => "2022/10.27/\354\241\260\354\210\230\354\227\260/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.kt" (100%) rename {10.31 => 2022/10.31}/readme.md (100%) rename "10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" => "2022/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" (100%) rename "10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" => "2022/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" (100%) rename "10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" => "2022/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" (94%) rename "10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" => "2022/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" (94%) rename "10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" => "2022/10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" (100%) rename "10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" => "2022/10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" (100%) rename "10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" => "2022/10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" (100%) rename "10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" => "2022/10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" (100%) rename "10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" => "2022/10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" (100%) rename "10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" => "2022/10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" (100%) rename "10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" => "2022/10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" (100%) rename "10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" => "2022/10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" (100%) rename "10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" => "2022/10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" (100%) rename {11.03 => 2022/11.03}/readme.md (100%) rename "11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" => "2022/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" (100%) rename "11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" => "2022/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" (100%) rename "11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" => "2022/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" (100%) rename "11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" => "2022/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" (100%) rename "11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" => "2022/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" (100%) rename "11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" => "2022/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" (100%) rename "11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" => "2022/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" (100%) rename "11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" => "2022/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" (100%) rename "11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" => "2022/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" (100%) rename "11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" => "2022/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" (100%) rename "11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" => "2022/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" (97%) rename "11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" => "2022/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" (100%) rename "11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" => "2022/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" (100%) rename {11.07 => 2022/11.07}/readme.md (100%) rename "11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" => "2022/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" (100%) rename "11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" => "2022/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" (100%) rename "11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" => "2022/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" (100%) rename "11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" => "2022/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" (100%) rename "11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" => "2022/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" (100%) rename "11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" => "2022/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" (100%) rename "11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" => "2022/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" (100%) rename "11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" => "2022/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" (100%) rename "11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" => "2022/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" (96%) rename "11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" => "2022/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" (100%) rename {11.10 => 2022/11.10}/readme.md (100%) rename "11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" => "2022/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" (100%) rename "11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" => "2022/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" (100%) rename "11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" => "2022/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" (100%) rename "11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" => "2022/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" (100%) rename "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" => "2022/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" (100%) rename "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" => "2022/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" (100%) rename "11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" => "2022/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" (100%) rename "11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" => "2022/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" (100%) rename "11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" => "2022/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" (100%) rename "11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" => "2022/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" (100%) rename "11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" => "2022/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" (96%) rename "11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" => "2022/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" (100%) rename {11.14 => 2022/11.14}/readme.md (100%) rename "11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" => "2022/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" (100%) rename "11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" => "2022/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" (100%) rename "11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" => "2022/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" (100%) rename "11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" => "2022/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" (100%) rename "11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" => "2022/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" (100%) rename "11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" => "2022/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" (100%) rename "11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" => "2022/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" (100%) rename "11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" => "2022/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" (100%) rename "11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" => "2022/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" (97%) rename "11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" => "2022/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" (100%) rename {11.17 => 2022/11.17}/readme.md (100%) rename "11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" => "2022/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" (100%) rename "11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" => "2022/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" (100%) rename "11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" => "2022/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" (100%) rename "11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" => "2022/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" (100%) rename "11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" => "2022/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" (100%) rename "11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" => "2022/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" (100%) rename {12.29 => 2022/12.29}/readme.md (100%) rename "12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" => "2022/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" (100%) rename "12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" => "2022/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" (100%) rename "12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" => "2022/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" (100%) rename "12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" => "2022/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" (100%) rename "12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" => "2022/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" (100%) rename "12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" => "2022/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" (100%) rename "12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" => "2022/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" (100%) rename "12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" => "2022/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" (100%) rename "12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" => "2022/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" (100%) rename "12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" => "2022/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" (100%) rename 2023/{03.09 => 03.13}/README.md (100%) rename "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" => "2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" (100%) rename "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" => "2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" (100%) rename "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" => "2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" (100%) rename "2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" => "2023/03.13/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" (100%) rename "2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" => "2023/03.13/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" (100%) rename "2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" => "2023/03.13/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" (100%) rename "2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" => "2023/03.13/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" (100%) rename "2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" => "2023/03.13/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" (100%) rename "2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" => "2023/03.13/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" (100%) rename "2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" => "2023/03.13/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" (100%) rename "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" => "2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" (100%) rename "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" => "2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" (100%) rename "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" => "2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" (100%) diff --git a/07.21/0721.md b/2022/07.21/0721.md similarity index 100% rename from 07.21/0721.md rename to 2022/07.21/0721.md diff --git a/07.21/readme.md b/2022/07.21/readme.md similarity index 100% rename from 07.21/readme.md rename to 2022/07.21/readme.md diff --git "a/07.21/\352\266\214\354\243\274\355\230\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/\353\260\261\354\244\200 1110.java" "b/2022/07.21/\352\266\214\354\243\274\355\230\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/\353\260\261\354\244\200 1110.java" similarity index 100% rename from "07.21/\352\266\214\354\243\274\355\230\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/\353\260\261\354\244\200 1110.java" rename to "2022/07.21/\352\266\214\354\243\274\355\230\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/\353\260\261\354\244\200 1110.java" diff --git "a/07.21/\354\206\241\352\270\260\355\233\210/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/kihun.py" "b/2022/07.21/\354\206\241\352\270\260\355\233\210/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/kihun.py" similarity index 100% rename from "07.21/\354\206\241\352\270\260\355\233\210/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/kihun.py" rename to "2022/07.21/\354\206\241\352\270\260\355\233\210/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/kihun.py" diff --git "a/07.21/\354\235\264\354\225\204\353\246\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main.java" "b/2022/07.21/\354\235\264\354\225\204\353\246\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main.java" similarity index 100% rename from "07.21/\354\235\264\354\225\204\353\246\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main.java" rename to "2022/07.21/\354\235\264\354\225\204\353\246\204/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main.java" diff --git "a/07.21/\354\235\264\354\247\200\354\234\244/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiyun.py" "b/2022/07.21/\354\235\264\354\247\200\354\234\244/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiyun.py" similarity index 100% rename from "07.21/\354\235\264\354\247\200\354\234\244/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiyun.py" rename to "2022/07.21/\354\235\264\354\247\200\354\234\244/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiyun.py" diff --git "a/07.21/\354\241\260\354\210\230\354\227\260/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/sooyun.java" "b/2022/07.21/\354\241\260\354\210\230\354\227\260/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/sooyun.java" similarity index 100% rename from "07.21/\354\241\260\354\210\230\354\227\260/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/sooyun.java" rename to "2022/07.21/\354\241\260\354\210\230\354\227\260/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/sooyun.java" diff --git "a/07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" "b/2022/07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" similarity index 96% rename from "07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" rename to "2022/07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" index a3a4b2e..01f404c 100644 --- "a/07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" +++ "b/2022/07.21/\354\265\234\354\260\275\354\230\201/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/Main_1110_\353\215\224\355\225\230\352\270\260\354\202\254\354\235\264\355\201\264.java" @@ -1,22 +1,22 @@ -import java.io.*; - -public class Main_1110_더하기사이클 { - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/1110.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int num = Integer.parseInt(br.readLine()); - int temp = num; - - int result = 0; - for (;;) { - int firstNum = temp / 10; - int secondNum = temp % 10; - - temp = secondNum * 10 + (firstNum + secondNum) % 10; - result++; - if(num == temp) break; - } - - System.out.print(result); - } // End of main +import java.io.*; + +public class Main_1110_더하기사이클 { + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1110.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int num = Integer.parseInt(br.readLine()); + int temp = num; + + int result = 0; + for (;;) { + int firstNum = temp / 10; + int secondNum = temp % 10; + + temp = secondNum * 10 + (firstNum + secondNum) % 10; + result++; + if(num == temp) break; + } + + System.out.print(result); + } // End of main } // End of Main class \ No newline at end of file diff --git "a/07.21/\355\231\251\354\247\200\354\233\220/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiwon.java" "b/2022/07.21/\355\231\251\354\247\200\354\233\220/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiwon.java" similarity index 100% rename from "07.21/\355\231\251\354\247\200\354\233\220/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiwon.java" rename to "2022/07.21/\355\231\251\354\247\200\354\233\220/1110_\353\215\224\355\225\230\352\270\260_\354\202\254\354\235\264\355\201\264/jiwon.java" diff --git a/07.25/readme.md b/2022/07.25/readme.md similarity index 100% rename from 07.25/readme.md rename to 2022/07.25/readme.md diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" "b/2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" similarity index 100% rename from "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" rename to "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1476.jva" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" "b/2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" similarity index 100% rename from "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" rename to "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1543.java" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" "b/2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" similarity index 100% rename from "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" rename to "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2422.java" diff --git "a/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" "b/2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" similarity index 100% rename from "07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" rename to "2022/07.25/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 3085.java" diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" "b/2022/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" similarity index 100% rename from "07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" rename to "2022/07.25/\354\206\241\352\270\260\355\233\210/1476_\353\202\240\354\247\234\352\263\204\354\202\260.py" diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" "b/2022/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" similarity index 100% rename from "07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" rename to "2022/07.25/\354\206\241\352\270\260\355\233\210/1543_\353\254\270\354\204\234\352\262\200\354\203\211.py" diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" "b/2022/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" similarity index 100% rename from "07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" rename to "2022/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264.py" diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" "b/2022/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" similarity index 100% rename from "07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" rename to "2022/07.25/\354\206\241\352\270\260\355\233\210/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\213\234\352\260\204\354\264\210\352\263\274.py" diff --git "a/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" "b/2022/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" similarity index 100% rename from "07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" rename to "2022/07.25/\354\206\241\352\270\260\355\233\210/3085_\354\202\254\355\203\225\352\262\214\354\236\204.py" diff --git "a/07.25/\354\235\264\354\225\204\353\246\204/1476_\353\202\240\354\247\234_\352\263\204\354\202\260..cpp" "b/2022/07.25/\354\235\264\354\225\204\353\246\204/1476_\353\202\240\354\247\234_\352\263\204\354\202\260..cpp" similarity index 100% rename from "07.25/\354\235\264\354\225\204\353\246\204/1476_\353\202\240\354\247\234_\352\263\204\354\202\260..cpp" rename to "2022/07.25/\354\235\264\354\225\204\353\246\204/1476_\353\202\240\354\247\234_\352\263\204\354\202\260..cpp" diff --git "a/07.25/\354\235\264\354\225\204\353\246\204/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.cpp" "b/2022/07.25/\354\235\264\354\225\204\353\246\204/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.cpp" similarity index 100% rename from "07.25/\354\235\264\354\225\204\353\246\204/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.cpp" rename to "2022/07.25/\354\235\264\354\225\204\353\246\204/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.cpp" diff --git "a/07.25/\354\235\264\354\225\204\353\246\204/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_.cpp" "b/2022/07.25/\354\235\264\354\225\204\353\246\204/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_.cpp" similarity index 100% rename from "07.25/\354\235\264\354\225\204\353\246\204/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_.cpp" rename to "2022/07.25/\354\235\264\354\225\204\353\246\204/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_.cpp" diff --git "a/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" "b/2022/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" similarity index 100% rename from "07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" rename to "2022/07.25/\354\235\264\354\225\204\353\246\204/3085_\354\202\254\355\203\225\352\262\214\354\236\204.cpp" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[1476]\353\202\240\354\247\234 \352\263\204\354\202\260_2.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_2.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[1543]\353\254\270\354\204\234 \352\262\200\354\203\211_3.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[2422]\355\225\234\354\234\244\354\240\225\354\235\264 \354\235\264\355\203\210\353\246\254\354\227\220 \352\260\200\354\204\234 \354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204 \354\202\254\353\250\271\353\212\224\353\215\260.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204.py" diff --git "a/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" "b/2022/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" similarity index 100% rename from "07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" rename to "2022/07.25/\354\235\264\354\247\200\354\234\244/[3085]\354\202\254\355\203\225 \352\262\214\354\236\204_2.py" diff --git "a/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" "b/2022/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" similarity index 100% rename from "07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" rename to "2022/07.25/\354\240\225\355\230\270\354\241\260/\353\202\240\354\247\234\352\263\204\354\202\260_1476.java" diff --git "a/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" "b/2022/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" similarity index 100% rename from "07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" rename to "2022/07.25/\354\240\225\355\230\270\354\241\260/\353\254\270\354\204\234\352\262\200\354\203\211_1543.java" diff --git "a/07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" "b/2022/07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" similarity index 100% rename from "07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" rename to "2022/07.25/\354\240\225\355\230\270\354\241\260/\354\202\254\355\203\225\352\262\214\354\236\204_3085.java" diff --git "a/07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" "b/2022/07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" similarity index 100% rename from "07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" rename to "2022/07.25/\354\240\225\355\230\270\354\241\260/\355\225\234\354\234\244\354\240\225_2422.java" diff --git "a/07.25/\354\241\260\354\210\230\354\227\260/1476_\353\202\240\354\247\234_\352\263\204\354\202\260.java" "b/2022/07.25/\354\241\260\354\210\230\354\227\260/1476_\353\202\240\354\247\234_\352\263\204\354\202\260.java" similarity index 100% rename from "07.25/\354\241\260\354\210\230\354\227\260/1476_\353\202\240\354\247\234_\352\263\204\354\202\260.java" rename to "2022/07.25/\354\241\260\354\210\230\354\227\260/1476_\353\202\240\354\247\234_\352\263\204\354\202\260.java" diff --git "a/07.25/\354\241\260\354\210\230\354\227\260/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.java" "b/2022/07.25/\354\241\260\354\210\230\354\227\260/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.java" similarity index 100% rename from "07.25/\354\241\260\354\210\230\354\227\260/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.java" rename to "2022/07.25/\354\241\260\354\210\230\354\227\260/1543_\353\254\270\354\204\234_\352\262\200\354\203\211.java" diff --git "a/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" "b/2022/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" similarity index 100% rename from "07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" rename to "2022/07.25/\354\241\260\354\210\230\354\227\260/2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" diff --git "a/07.25/\354\265\234\354\260\275\354\230\201/Main_1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" "b/2022/07.25/\354\265\234\354\260\275\354\230\201/Main_1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" similarity index 100% rename from "07.25/\354\265\234\354\260\275\354\230\201/Main_1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" rename to "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" diff --git "a/07.25/\354\265\234\354\260\275\354\230\201/Main_1543_\353\254\270\354\204\234\352\262\200\354\203\211.java" "b/2022/07.25/\354\265\234\354\260\275\354\230\201/Main_1543_\353\254\270\354\204\234\352\262\200\354\203\211.java" similarity index 100% rename from "07.25/\354\265\234\354\260\275\354\230\201/Main_1543_\353\254\270\354\204\234\352\262\200\354\203\211.java" rename to "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_1543_\353\254\270\354\204\234\352\262\200\354\203\211.java" diff --git "a/07.25/\354\265\234\354\260\275\354\230\201/Main_2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" "b/2022/07.25/\354\265\234\354\260\275\354\230\201/Main_2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" similarity index 100% rename from "07.25/\354\265\234\354\260\275\354\230\201/Main_2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" rename to "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_2422_\355\225\234\354\234\244\354\240\225\354\235\264_\354\235\264\355\203\210\353\246\254\354\225\204\354\227\220_\352\260\200\354\204\234_\354\225\204\354\235\264\354\212\244\355\201\254\353\246\274\354\235\204_\354\202\254\353\250\271\353\212\224\353\215\260.java" diff --git "a/07.25/\354\265\234\354\260\275\354\230\201/Main_3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" "b/2022/07.25/\354\265\234\354\260\275\354\230\201/Main_3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" similarity index 100% rename from "07.25/\354\265\234\354\260\275\354\230\201/Main_3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" rename to "2022/07.25/\354\265\234\354\260\275\354\230\201/Main_3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" "b/2022/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" similarity index 100% rename from "07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" rename to "2022/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\202\240\354\247\234\352\263\204\354\202\260.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\254\270\354\204\234\352\262\200\354\203\211.java" "b/2022/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\254\270\354\204\234\352\262\200\354\203\211.java" similarity index 100% rename from "07.25/\355\231\251\354\247\200\354\233\220/1476_\353\254\270\354\204\234\352\262\200\354\203\211.java" rename to "2022/07.25/\355\231\251\354\247\200\354\233\220/1476_\353\254\270\354\204\234\352\262\200\354\203\211.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" "b/2022/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" similarity index 100% rename from "07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" rename to "2022/07.25/\355\231\251\354\247\200\354\233\220/2422_\355\225\234\354\234\244\354\240\225\354\235\264.java" diff --git "a/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" "b/2022/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" similarity index 100% rename from "07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" rename to "2022/07.25/\355\231\251\354\247\200\354\233\220/3085_\354\202\254\355\203\225\352\262\214\354\236\204.java" diff --git a/07.28/readme.md b/2022/07.28/readme.md similarity index 100% rename from 07.28/readme.md rename to 2022/07.28/readme.md diff --git "a/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" "b/2022/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" similarity index 100% rename from "07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" rename to "2022/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 17086.java" diff --git "a/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" "b/2022/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" similarity index 100% rename from "07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" rename to "2022/07.28/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2502.java" diff --git "a/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" "b/2022/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" similarity index 100% rename from "07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" rename to "2022/07.28/\354\206\241\352\270\260\355\233\210/17086_\354\225\204\352\270\260\354\203\201\354\226\2642.py" diff --git "a/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" "b/2022/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" similarity index 100% rename from "07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" rename to "2022/07.28/\354\206\241\352\270\260\355\233\210/2502_\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" diff --git "a/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" "b/2022/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" similarity index 100% rename from "07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" rename to "2022/07.28/\354\235\264\354\225\204\353\246\204/1706_\354\225\204\352\270\260\354\203\201\354\226\2642.cpp" diff --git "a/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" "b/2022/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" similarity index 100% rename from "07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" rename to "2022/07.28/\354\235\264\354\225\204\353\246\204/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.cpp" diff --git "a/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" "b/2022/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" similarity index 100% rename from "07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" rename to "2022/07.28/\354\235\264\354\247\200\354\234\244/[17086]\354\225\204\352\270\260\354\203\201\354\226\2642.py" diff --git "a/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" "b/2022/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" similarity index 100% rename from "07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" rename to "2022/07.28/\354\235\264\354\247\200\354\234\244/[2502]\353\226\241\353\250\271\353\212\224\355\230\270\353\236\221\354\235\264.py" diff --git "a/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" "b/2022/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" similarity index 100% rename from "07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" rename to "2022/07.28/\354\241\260\354\210\230\354\227\260/17086_\354\225\204\352\270\260_\354\203\201\354\226\2642.java" diff --git "a/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" "b/2022/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" similarity index 100% rename from "07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" rename to "2022/07.28/\354\241\260\354\210\230\354\227\260/2502_\353\226\241\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" diff --git "a/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" "b/2022/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" similarity index 96% rename from "07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" rename to "2022/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" index 95aaa42..1693c40 100644 --- "a/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" +++ "b/2022/07.28/\354\265\234\354\260\275\354\230\201/Main_17086_\354\225\204\352\270\260_\354\203\201\354\226\264_2.java" @@ -1,79 +1,79 @@ -import java.util.*; -import java.io.*; - -public class Main_17086_아기_상어_2 { - static int arr[][]; - static int dirX[] = {0, 0, -1, 1, -1, 1, 1, -1}; // 상 하 좌 우 - static int dirY[] = {-1, 1, 0, 0, -1, -1, 1, 1}; - static int N, M; - static int nowX, nowY; - static int max = -1; - - public static class Node { - int x; - int y; - int dist; - - public Node(int x, int y, int dist) { - this.x = x; - this.y = y; - this.dist = dist; - } - } // End of Node class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/17086.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - StringTokenizer st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); - arr = new int[N][M]; - - for(int i=0; i que = new LinkedList<>(); - que.offer(new Node(x, y, 0)); - boolean visit[][] = new boolean[N][M]; - visit[x][y] = true; - - while( !que.isEmpty() ) { - Node node = que.poll(); - - for(int i=0; i<8; i++) { - nowX = dirX[i] + node.x; - nowY = dirY[i] + node.y; - - if(!range_check() || visit[nowX][nowY]) continue; - if(arr[nowX][nowY] == 1) { - max = Math.max(max, node.dist + 1); - return; - } - - visit[nowX][nowY] = true; - que.offer(new Node(nowX, nowY, node.dist + 1)); - } - } - } // End of BFS - - private static boolean range_check() { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; - } // End of range_check +import java.util.*; +import java.io.*; + +public class Main_17086_아기_상어_2 { + static int arr[][]; + static int dirX[] = {0, 0, -1, 1, -1, 1, 1, -1}; // 상 하 좌 우 + static int dirY[] = {-1, 1, 0, 0, -1, -1, 1, 1}; + static int N, M; + static int nowX, nowY; + static int max = -1; + + public static class Node { + int x; + int y; + int dist; + + public Node(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/17086.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new int[N][M]; + + for(int i=0; i que = new LinkedList<>(); + que.offer(new Node(x, y, 0)); + boolean visit[][] = new boolean[N][M]; + visit[x][y] = true; + + while( !que.isEmpty() ) { + Node node = que.poll(); + + for(int i=0; i<8; i++) { + nowX = dirX[i] + node.x; + nowY = dirY[i] + node.y; + + if(!range_check() || visit[nowX][nowY]) continue; + if(arr[nowX][nowY] == 1) { + max = Math.max(max, node.dist + 1); + return; + } + + visit[nowX][nowY] = true; + que.offer(new Node(nowX, nowY, node.dist + 1)); + } + } + } // End of BFS + + private static boolean range_check() { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check } // End of Main class \ No newline at end of file diff --git "a/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" "b/2022/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" similarity index 96% rename from "07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" rename to "2022/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" index 07b7faf..6f57311 100644 --- "a/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" +++ "b/2022/07.28/\354\265\234\354\260\275\354\230\201/Main_2502_\353\226\241_\353\250\271\353\212\224_\355\230\270\353\236\221\354\235\264.java" @@ -1,38 +1,38 @@ -import java.util.*; -import java.io.*; - -public class Main_2502_떡_먹는_호랑이 { - static int memo[]; - static int D; static int K; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2502.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - D = Integer.parseInt(st.nextToken()); - K = Integer.parseInt(st.nextToken()); - memo = new int[D]; // 넘어논 날 만큼 배열 생성 - memo[D - 1] = K; // 배열 떡의 마지막 부분은 마지막 날 호랑이에게 준 떡의 개수 - DP(1); - } // End of main - - private static void DP(int ans) { - memo[0] = ans; - - for (int i=ans; i> list = new ArrayList<>(); - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/11725.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - N = Integer.parseInt(br.readLine()); - node = new int[N+1]; - for(int i=0; i()); - - for(int i=0; i que = new LinkedList<>(); - que.offer(1); - - while(!que.isEmpty()) { - int nodeNum = que.poll(); - - for(int num : list.get(nodeNum)) { - if(node[num] == 0) { - node[num] = nodeNum; - que.offer(num); - } - } - - } - - } // End of BFS +import java.util.*; +import java.io.*; + +// 뒤가 1이면, 앞자리 x값을 1을 넣음 +// 만약 y자리가 0이 아니라면 x자리에 y값이 들어감 + +public class Main_11725_트리의_부모_찾기 { + static int N; + static int node[]; + static List> list = new ArrayList<>(); + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/11725.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + node = new int[N+1]; + for(int i=0; i()); + + for(int i=0; i que = new LinkedList<>(); + que.offer(1); + + while(!que.isEmpty()) { + int nodeNum = que.poll(); + + for(int num : list.get(nodeNum)) { + if(node[num] == 0) { + node[num] = nodeNum; + que.offer(num); + } + } + + } + + } // End of BFS } // End of Main class \ No newline at end of file diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" "b/2022/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" similarity index 96% rename from "08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" rename to "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" index 0828949..c2eb45d 100644 --- "a/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" +++ "b/2022/08.01/\354\265\234\354\260\275\354\230\201/Main_1388_\353\260\224\353\213\245_\354\236\245\354\213\235.java" @@ -1,77 +1,77 @@ -import java.util.*; -import java.io.*; - -// 기훈이의 방 바닥을 장식하는데 필요한 나무 판자의 개수를 출력하는 프로그램을 작성하시오. - -// -는 인접, 같은 행 , |는 인접 같은 열 - -public class Main_1388_바닥_장식 { - static int N; - static int M; - static char arr[][]; - static boolean visit[][]; - static int nowX; static int nowY; - static int dirX[] = {0, 0, -1, 1}; - static int dirY[] = {-1, 1, 0, 0}; - - static int result = 0; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/1388.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - StringTokenizer st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); - - arr = new char[N][M]; - visit = new boolean[N][M]; - for (int i = 0; i < N; i++) { - String temp = br.readLine(); - for (int j = 0; j < M; j++) { - arr[i][j] = temp.charAt(j); - } - } - - int result = 0; - // 가로 모양 타일 탐색 - for (int i = 0; i < N; i++) { - for (int j = 0; j < M; j++) { - if(!visit[i][j] && arr[i][j] == '-') { - DFS(i, j, 0, 2, '-'); - result++; - } - } - } - - - // 세로 - for (int i = 0; i < M; i++) { - for (int j = 0; j < N; j++) { - if(!visit[j][i] && arr[j][i] == '|') { - DFS(j, i, 2, 4, '|'); - result++; - } - } - } - - System.out.println(result); - } // End of main - - private static void DFS(int x, int y, int idxStart, int idxEnd, char ch) { - visit[x][y] = true; - - for(int i=idxStart; i= 0 && nowX < N && nowY >= 0 && nowY < M; - } // End of range_check +import java.util.*; +import java.io.*; + +// 기훈이의 방 바닥을 장식하는데 필요한 나무 판자의 개수를 출력하는 프로그램을 작성하시오. + +// -는 인접, 같은 행 , |는 인접 같은 열 + +public class Main_1388_바닥_장식 { + static int N; + static int M; + static char arr[][]; + static boolean visit[][]; + static int nowX; static int nowY; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + + static int result = 0; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1388.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + arr = new char[N][M]; + visit = new boolean[N][M]; + for (int i = 0; i < N; i++) { + String temp = br.readLine(); + for (int j = 0; j < M; j++) { + arr[i][j] = temp.charAt(j); + } + } + + int result = 0; + // 가로 모양 타일 탐색 + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if(!visit[i][j] && arr[i][j] == '-') { + DFS(i, j, 0, 2, '-'); + result++; + } + } + } + + + // 세로 + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + if(!visit[j][i] && arr[j][i] == '|') { + DFS(j, i, 2, 4, '|'); + result++; + } + } + } + + System.out.println(result); + } // End of main + + private static void DFS(int x, int y, int idxStart, int idxEnd, char ch) { + visit[x][y] = true; + + for(int i=idxStart; i= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check } // End of Main class \ No newline at end of file diff --git "a/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" "b/2022/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" similarity index 95% rename from "08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" rename to "2022/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" index 5e7ec59..6f63e72 100644 --- "a/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" +++ "b/2022/08.01/\354\265\234\354\260\275\354\230\201/Main_16173_\354\240\220\355\224\204\354\231\225_\354\251\260\353\246\254.java" @@ -1,71 +1,71 @@ -import java.util.*; -import java.io.*; - -public class Main_16173_점프왕_쩰리 { - static int N; - static int nowX; static int nowY; - static int arr[][]; - static int dirX[] = {1, 0}; // 하 우 - static int dirY[] = {0, 1}; - - private static class Node { - int x; - int y; - - public Node(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Node class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/16173.txt")); - BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); - - N = Integer.parseInt(br.readLine()); - arr = new int[N][N]; - - for(int i=0; i que = new LinkedList<>(); - boolean visit[][] = new boolean[N][N]; - visit[x][y] = true; - que.offer(new Node(x, y)); - - while(!que.isEmpty()) { - Node node = que.poll(); - - for(int i=0; i<2; i++) { - nowX = node.x + (dirX[i] * arr[node.x][node.y]); - nowY = node.y + (dirY[i] * arr[node.x][node.y]); - - if(range_check() && !visit[nowX][nowY]) { - if(arr[nowX][nowY] == -1) return true; - - visit[nowX][nowY] = true; - que.offer(new Node(nowX, nowY)); - } - } - } - - return false; - } // End of BFS - - private static boolean range_check() { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY que = new LinkedList<>(); + boolean visit[][] = new boolean[N][N]; + visit[x][y] = true; + que.offer(new Node(x, y)); + + while(!que.isEmpty()) { + Node node = que.poll(); + + for(int i=0; i<2; i++) { + nowX = node.x + (dirX[i] * arr[node.x][node.y]); + nowY = node.y + (dirY[i] * arr[node.x][node.y]); + + if(range_check() && !visit[nowX][nowY]) { + if(arr[nowX][nowY] == -1) return true; + + visit[nowX][nowY] = true; + que.offer(new Node(nowX, nowY)); + } + } + } + + return false; + } // End of BFS + + private static boolean range_check() { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY que = new LinkedList<>(); - que.offer(1); - visit[1] = true; - - while( !que.isEmpty() ) { - int node = que.poll(); - - for(int i=1; i que = new LinkedList<>(); + que.offer(1); + visit[1] = true; + + while( !que.isEmpty() ) { + int node = que.poll(); + + for(int i=1; i 0) { - st = new StringTokenizer(br.readLine()); - int x = Integer.parseInt(st.nextToken()); - int y = Integer.parseInt(st.nextToken()); - - // 무방향 그래프 특성. - arr[x][y] = 1; - arr[y][x] = 1; - } - - // floyd_warshall (완전탐색) - // 각 노드에서 갈 수 있는 곳을 모두 탐색. - floyd(); - - int count = 0; - boolean node[] = new boolean[N+1]; - for(int i=1; i<=N; i++) { - - // 이미 등록된 노드는 탐색할 필요없음 - if(node[i] == true) { - continue; - } - - // 방문 가능한 노드는 바로 true처리. - for(int j=1; j<=N; j++) { - if(arr[i][j] == 1 && node[j] == false) { - node[j] = true; - } - } - - count ++; - } - - System.out.println(count); - - } // End of main - - static void floyd() { - - for(int k=0; k<=N; k++) { - for(int i=0; i<=N; i++) { - for(int j=0; j<=N; j++) { - - if(arr[i][k] == 1 && arr[k][j] == 1) { - arr[i][j] = 1; - } - } - } - } - - } // End of floyd - +import java.util.*; +import java.io.*; + +public class Main_2606_바이러스_Floyd_Warshall { + static int arr[][]; + static int N; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_11724.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = null; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 정점의 개수 + int M = Integer.parseInt(st.nextToken()); // 간선의 개수 + + // 무방향 그래프 + // 노드의 개수만큼 배열 생성. + arr = new int[N+1][N+1]; + + while(M --> 0) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + // 무방향 그래프 특성. + arr[x][y] = 1; + arr[y][x] = 1; + } + + // floyd_warshall (완전탐색) + // 각 노드에서 갈 수 있는 곳을 모두 탐색. + floyd(); + + int count = 0; + boolean node[] = new boolean[N+1]; + for(int i=1; i<=N; i++) { + + // 이미 등록된 노드는 탐색할 필요없음 + if(node[i] == true) { + continue; + } + + // 방문 가능한 노드는 바로 true처리. + for(int j=1; j<=N; j++) { + if(arr[i][j] == 1 && node[j] == false) { + node[j] = true; + } + } + + count ++; + } + + System.out.println(count); + + } // End of main + + static void floyd() { + + for(int k=0; k<=N; k++) { + for(int i=0; i<=N; i++) { + for(int j=0; j<=N; j++) { + + if(arr[i][k] == 1 && arr[k][j] == 1) { + arr[i][j] = 1; + } + } + } + } + + } // End of floyd + } // End of class \ No newline at end of file diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" "b/2022/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" similarity index 100% rename from "08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" rename to "2022/08.01/\355\231\251\354\247\200\354\233\220/11725_\355\212\270\353\246\254\354\235\230\353\266\200\353\252\250\354\260\276\352\270\260.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" "b/2022/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" similarity index 100% rename from "08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" rename to "2022/08.01/\355\231\251\354\247\200\354\233\220/1388_\353\260\224\353\213\245\354\236\245\354\213\235.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" "b/2022/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" similarity index 100% rename from "08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" rename to "2022/08.01/\355\231\251\354\247\200\354\233\220/16173_\354\240\220\355\224\204\354\231\225\354\251\260\353\246\254.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" "b/2022/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" similarity index 100% rename from "08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" rename to "2022/08.01/\355\231\251\354\247\200\354\233\220/2606_\353\260\224\354\235\264\353\237\254\354\212\244.java" diff --git "a/08.01/\355\231\251\354\247\200\354\233\220/readme.md" "b/2022/08.01/\355\231\251\354\247\200\354\233\220/readme.md" similarity index 100% rename from "08.01/\355\231\251\354\247\200\354\233\220/readme.md" rename to "2022/08.01/\355\231\251\354\247\200\354\233\220/readme.md" diff --git a/08.04/readme.md b/2022/08.04/readme.md similarity index 100% rename from 08.04/readme.md rename to 2022/08.04/readme.md diff --git "a/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" "b/2022/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" similarity index 100% rename from "08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" rename to "2022/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 1743.java" diff --git "a/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" "b/2022/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" similarity index 100% rename from "08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" rename to "2022/08.04/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2583.java" diff --git "a/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" "b/2022/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" similarity index 100% rename from "08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" rename to "2022/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" diff --git "a/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" "b/2022/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" similarity index 100% rename from "08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" rename to "2022/08.04/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.py" diff --git "a/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" "b/2022/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" similarity index 100% rename from "08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" rename to "2022/08.04/\354\235\264\354\225\204\353\246\204/1743_\354\235\214\354\213\235\353\254\274_\355\224\274\355\225\230\352\270\260.cpp" diff --git "a/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" "b/2022/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" similarity index 100% rename from "08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" rename to "2022/08.04/\354\235\264\354\225\204\353\246\204/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.cpp" diff --git "a/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" "b/2022/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" similarity index 100% rename from "08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" rename to "2022/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_1743]\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.py" diff --git "a/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" "b/2022/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" similarity index 100% rename from "08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" rename to "2022/08.04/\354\235\264\354\247\200\354\234\244/[BOJ_2583]\354\230\201\354\227\255 \352\265\254\355\225\230\352\270\260.py" diff --git "a/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" "b/2022/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" similarity index 100% rename from "08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" rename to "2022/08.04/\354\241\260\354\210\230\354\227\260/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" diff --git "a/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" "b/2022/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" similarity index 100% rename from "08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" rename to "2022/08.04/\354\241\260\354\210\230\354\227\260/2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260.java" diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" similarity index 95% rename from "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" rename to "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" index de4689e..322e1f5 100644 --- "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" +++ "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_BFS.java" @@ -1,86 +1,86 @@ -import java.util.*; -import java.io.*; - -public class Main_1743_음식물피하기_BFS { - static boolean visit[][]; - static int map[][]; - static int dirX[] = {0, 0, -1, 1}; - static int dirY[] = {-1, 1, 0, 0}; - static Queue que = new LinkedList<>(); - - static int N, M; - static int nowX, nowY; - static int x, y; - static int count; - - static class Node { - int x; - int y; - - public Node(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Node class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_1743.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - N = Integer.parseInt(st.nextToken()) + 1; - M = Integer.parseInt(st.nextToken()) + 1; - int K = Integer.parseInt(st.nextToken()); - - map = new int[N][M]; - visit = new boolean[N][M]; - for(int i=0; i 0) { - BFS(j, i); - max = Math.max(max, count); - } - - } - } - - System.out.println(max); - } // End of main - - static void BFS(int x, int y) { - que.offer(new Node(x, y)); - visit[y][x] = true; - // 자기 자신 포함 - count = 1; - - while( !que.isEmpty() ) { - Node node = que.poll(); - - for(int i=0; i<4; i++) { - nowY = node.y + dirY[i]; - nowX = node.x + dirX[i]; - - if(range_check() && visit[nowY][nowX] == false && map[nowY][nowX] == 1) { - que.offer(new Node(nowX, nowY)); - visit[nowY][nowX] = true; - count ++; - } - } - - } - } // End of BFS - - static boolean range_check() { - return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); - } // End of range_check +import java.util.*; +import java.io.*; + +public class Main_1743_음식물피하기_BFS { + static boolean visit[][]; + static int map[][]; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + static Queue que = new LinkedList<>(); + + static int N, M; + static int nowX, nowY; + static int x, y; + static int count; + + static class Node { + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_1743.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()) + 1; + M = Integer.parseInt(st.nextToken()) + 1; + int K = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + visit = new boolean[N][M]; + for(int i=0; i 0) { + BFS(j, i); + max = Math.max(max, count); + } + + } + } + + System.out.println(max); + } // End of main + + static void BFS(int x, int y) { + que.offer(new Node(x, y)); + visit[y][x] = true; + // 자기 자신 포함 + count = 1; + + while( !que.isEmpty() ) { + Node node = que.poll(); + + for(int i=0; i<4; i++) { + nowY = node.y + dirY[i]; + nowX = node.x + dirX[i]; + + if(range_check() && visit[nowY][nowX] == false && map[nowY][nowX] == 1) { + que.offer(new Node(nowX, nowY)); + visit[nowY][nowX] = true; + count ++; + } + } + + } + } // End of BFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); + } // End of range_check } // End of Main class \ No newline at end of file diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" similarity index 96% rename from "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" rename to "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" index 57a1d10..ae358d2 100644 --- "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" +++ "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_DFS.java" @@ -1,67 +1,67 @@ -import java.util.*; -import java.io.*; - -public class Main_1743_음식물피하기_DFS { - static boolean visit[][]; - static int map[][]; - static int dirX[] = {0, 0, -1, 1}; - static int dirY[] = {-1, 1, 0, 0}; - - static int N, M; - static int nowX, nowY; - static int x, y; - static int count = 1; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_1743.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - N = Integer.parseInt(st.nextToken()) + 1; - M = Integer.parseInt(st.nextToken()) + 1; - int K = Integer.parseInt(st.nextToken()); - - map = new int[N][M]; - visit = new boolean[N][M]; - for(int i=0; i 0) { - DFS(j, i); - max = Math.max(max, count); - } - } - } - - System.out.println(max); - } // End of main - - static void DFS(int x, int y) { - visit[y][x] = true; - count++; - - for(int i=0; i<4; i++) { - nowX = x + dirX[i]; - nowY = y + dirY[i]; - - if(range_check() && visit[nowY][nowX] == false && map[nowY][nowX] > 0) { - DFS(nowX, nowY); - } - } - } // End of DFS - - static boolean range_check() { - return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); - } // End of range_check +import java.util.*; +import java.io.*; + +public class Main_1743_음식물피하기_DFS { + static boolean visit[][]; + static int map[][]; + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int x, y; + static int count = 1; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_1743.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()) + 1; + M = Integer.parseInt(st.nextToken()) + 1; + int K = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + visit = new boolean[N][M]; + for(int i=0; i 0) { + DFS(j, i); + max = Math.max(max, count); + } + } + } + + System.out.println(max); + } // End of main + + static void DFS(int x, int y) { + visit[y][x] = true; + count++; + + for(int i=0; i<4; i++) { + nowX = x + dirX[i]; + nowY = y + dirY[i]; + + if(range_check() && visit[nowY][nowX] == false && map[nowY][nowX] > 0) { + DFS(nowX, nowY); + } + } + } // End of DFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < M && nowY < N); + } // End of range_check } // End of Main class \ No newline at end of file diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" similarity index 100% rename from "08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" rename to "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260_\353\266\200\353\266\204\355\203\220\354\203\211_\354\210\230\354\240\225\353\263\270.java" diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" similarity index 96% rename from "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" rename to "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" index 14f8e6f..37b5ef6 100644 --- "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" +++ "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_BFS.java" @@ -1,96 +1,96 @@ -import java.util.*; -import java.io.*; - -public class Main_2583_영역_구하기_BFS { - static int arr[][]; - static boolean visit[][]; - static List resultList = new ArrayList<>(); - static int dirX[] = {0, 0, -1, 1}; - static int dirY[] = {1, -1, 0, 0}; - - static int N, M; - static int nowX, nowY; - static int areaCount = 0; - - static class Node{ - int x; - int y; - - public Node(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Node class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2583.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st = new StringTokenizer(br.readLine()); - - M = Integer.parseInt(st.nextToken()); - N = Integer.parseInt(st.nextToken()); - int K = Integer.parseInt(st.nextToken()); - - arr = new int[N][M]; - visit = new boolean[N][M]; - - while(K-->0) { - st = new StringTokenizer(br.readLine()); - int x1 = Integer.parseInt(st.nextToken()); - int y1 = Integer.parseInt(st.nextToken()); - int x2 = Integer.parseInt(st.nextToken()); - int y2 = Integer.parseInt(st.nextToken()); - - for(int i=x1; i que = new LinkedList<>(); - visit[x][y] = true; - que.offer(new Node(x,y)); - - while(!que.isEmpty()) { - Node node = que.poll(); - - for(int i=0; i<4; i++) { - nowX = dirX[i] + node.x; - nowY = dirY[i] + node.y; - - if(range_check() && !visit[nowX][nowY] && arr[nowX][nowY] == 0) { - que.offer(new Node(nowX, nowY)); - visit[nowX][nowY] = true; - areaCount++; - } - } - } - } // End of BFS - - private static boolean range_check() { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; - } // End of range_check +import java.util.*; +import java.io.*; + +public class Main_2583_영역_구하기_BFS { + static int arr[][]; + static boolean visit[][]; + static List resultList = new ArrayList<>(); + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {1, -1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int areaCount = 0; + + static class Node{ + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2583.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + arr = new int[N][M]; + visit = new boolean[N][M]; + + while(K-->0) { + st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for(int i=x1; i que = new LinkedList<>(); + visit[x][y] = true; + que.offer(new Node(x,y)); + + while(!que.isEmpty()) { + Node node = que.poll(); + + for(int i=0; i<4; i++) { + nowX = dirX[i] + node.x; + nowY = dirY[i] + node.y; + + if(range_check() && !visit[nowX][nowY] && arr[nowX][nowY] == 0) { + que.offer(new Node(nowX, nowY)); + visit[nowX][nowY] = true; + areaCount++; + } + } + } + } // End of BFS + + private static boolean range_check() { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check } // End of Main class \ No newline at end of file diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" similarity index 96% rename from "08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" rename to "2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" index 5fce386..0e91ecf 100644 --- "a/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" +++ "b/2022/08.04/\354\265\234\354\260\275\354\230\201/Main_2583_\354\230\201\354\227\255_\352\265\254\355\225\230\352\270\260_DFS.java" @@ -1,79 +1,79 @@ -import java.util.*; -import java.io.*; - -public class Main_2583_영역_구하기_DFS { - static int arr[][]; - static boolean visit[][]; - static List resultList = new ArrayList<>(); - static int dirX[] = {0, 0, -1, 1}; - static int dirY[] = {1, -1, 0, 0}; - - static int N, M; - static int nowX, nowY; - static int areaCount = 0; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2583.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st = new StringTokenizer(br.readLine()); - - M = Integer.parseInt(st.nextToken()); - N = Integer.parseInt(st.nextToken()); - int K = Integer.parseInt(st.nextToken()); - - arr = new int[N][M]; - visit = new boolean[N][M]; - - while(K-->0) { - st = new StringTokenizer(br.readLine()); - int x1 = Integer.parseInt(st.nextToken()); - int y1 = Integer.parseInt(st.nextToken()); - int x2 = Integer.parseInt(st.nextToken()); - int y2 = Integer.parseInt(st.nextToken()); - - for(int i=x1; i= 0 && nowX < N && nowY >= 0 && nowY < M; - } // End of range_check +import java.util.*; +import java.io.*; + +public class Main_2583_영역_구하기_DFS { + static int arr[][]; + static boolean visit[][]; + static List resultList = new ArrayList<>(); + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {1, -1, 0, 0}; + + static int N, M; + static int nowX, nowY; + static int areaCount = 0; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2583.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + arr = new int[N][M]; + visit = new boolean[N][M]; + + while(K-->0) { + st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for(int i=x1; i= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of range_check } // End of Main class \ No newline at end of file diff --git "a/08.04/\354\265\234\354\260\275\354\230\201/readme" "b/2022/08.04/\354\265\234\354\260\275\354\230\201/readme" similarity index 100% rename from "08.04/\354\265\234\354\260\275\354\230\201/readme" rename to "2022/08.04/\354\265\234\354\260\275\354\230\201/readme" diff --git "a/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" "b/2022/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" similarity index 100% rename from "08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" rename to "2022/08.04/\355\231\251\354\247\200\354\233\220/1743_\354\235\214\354\213\235\353\254\274\355\224\274\355\225\230\352\270\260.java" diff --git "a/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" "b/2022/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" similarity index 100% rename from "08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" rename to "2022/08.04/\355\231\251\354\247\200\354\233\220/2583_\354\230\201\354\227\255\352\265\254\355\225\230\352\270\260.java" diff --git a/08.08/readme.md b/2022/08.08/readme.md similarity index 100% rename from 08.08/readme.md rename to 2022/08.08/readme.md diff --git "a/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" "b/2022/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" similarity index 100% rename from "08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" rename to "2022/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2001697.java" diff --git "a/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" "b/2022/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" similarity index 100% rename from "08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" rename to "2022/08.08/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\2002644.java" diff --git "a/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" "b/2022/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" similarity index 100% rename from "08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" rename to "2022/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1697_\354\210\250\353\260\224\352\274\255\354\247\210.py" diff --git "a/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/2022/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" similarity index 100% rename from "08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" rename to "2022/08.08/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2644_\354\264\214\354\210\230\352\263\204\354\202\260.py" diff --git "a/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" "b/2022/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" similarity index 100% rename from "08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" rename to "2022/08.08/\354\235\264\354\225\204\353\246\204/1697_\354\210\250\353\260\224\352\274\255\354\247\210.cpp" diff --git "a/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" "b/2022/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" similarity index 100% rename from "08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" rename to "2022/08.08/\354\235\264\354\225\204\353\246\204/2664_\354\264\214\354\210\230\352\263\204\354\202\260.cpp" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" "b/2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" similarity index 100% rename from "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" rename to "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_bfs.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" "b/2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" similarity index 100% rename from "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" rename to "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" "b/2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" similarity index 100% rename from "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" rename to "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_1967]\354\210\250\353\260\224\352\274\255\354\247\210_recursive_bad.py" diff --git "a/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" similarity index 100% rename from "08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" rename to "2022/08.08/\354\235\264\354\247\200\354\234\244/[BOJ_2644]\354\264\214\354\210\230\352\263\204\354\202\260.py" diff --git "a/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" "b/2022/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" similarity index 100% rename from "08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" rename to "2022/08.08/\354\241\260\354\210\230\354\227\260/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" diff --git "a/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" "b/2022/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" similarity index 100% rename from "08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" rename to "2022/08.08/\354\241\260\354\210\230\354\227\260/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" "b/2022/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" similarity index 96% rename from "08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" rename to "2022/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" index 33e42d5..70fa4ed 100644 --- "a/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" +++ "b/2022/08.08/\354\265\234\354\260\275\354\230\201/Main_1697_\354\210\250\353\260\224\352\274\255\354\247\210_DP.java" @@ -1,52 +1,52 @@ -import java.io.*; -import java.util.*; - -// https://www.acmicpc.net/problem/1697 -// 목표 : 수빈이가 동생을 찾는 가장 빠른 시간을 출력한다. - -// 숨바꼭질2랑 범위가 달라서 체크해야됨 -// 숨바꼭질2은 테스트케이스 중에 10만이 없는데 - -// 숨바꼭질1에서는 테스트 케이스 중에 next_location 범위가 10만 인 경우가 있기 때문에 -// 신경써야됨. - -public class Main_1697_숨바꼭질_DP { - static int distance[] = new int[100001]; // 전체 거리 - static int N, K; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_1697.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - N = Integer.parseInt(st.nextToken()); // 수빈이 위치 - K = Integer.parseInt(st.nextToken()); // 동생 위치 - - if(N >= K) { - System.out.println(N-K); - return; - } - - for(int i=0; i= K) { + System.out.println(N-K); + return; + } + + for(int i=0; i> list; - static int node[]; - static boolean visit[]; - static int N; - static int a, b; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2644.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - N = Integer.parseInt(br.readLine()); - list = new ArrayList<>(); - for(int i=0; i<=N; i++) { - list.add(new ArrayList<>()); - } - node = new int[N+1]; - visit = new boolean[N+1]; - - StringTokenizer st = new StringTokenizer(br.readLine()); - a = Integer.parseInt(st.nextToken()); - b = Integer.parseInt(st.nextToken()); - - int M = Integer.parseInt(br.readLine()); - while(M-->0) { - st = new StringTokenizer(br.readLine()); - int x = Integer.parseInt(st.nextToken()); - int y = Integer.parseInt(st.nextToken()); - - list.get(y).add(x); - list.get(x).add(y); - } - - DFS(a); - if(node[b] == 0) System.out.println(-1); - else System.out.println(node[b]); - } // End of main - - private static void DFS(int num) { - visit[num] = true; - - for(int nodeNum : list.get(num)) { - - if(!visit[nodeNum]) { - node[nodeNum] = node[num] + 1; - DFS(nodeNum); - } - } - - } // End of DFS +import java.util.*; +import java.io.*; + +public class Main_2644_촌수계산_DFS { + static List> list; + static int node[]; + static boolean visit[]; + static int N; + static int a, b; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2644.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + list = new ArrayList<>(); + for(int i=0; i<=N; i++) { + list.add(new ArrayList<>()); + } + node = new int[N+1]; + visit = new boolean[N+1]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + a = Integer.parseInt(st.nextToken()); + b = Integer.parseInt(st.nextToken()); + + int M = Integer.parseInt(br.readLine()); + while(M-->0) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + list.get(y).add(x); + list.get(x).add(y); + } + + DFS(a); + if(node[b] == 0) System.out.println(-1); + else System.out.println(node[b]); + } // End of main + + private static void DFS(int num) { + visit[num] = true; + + for(int nodeNum : list.get(num)) { + + if(!visit[nodeNum]) { + node[nodeNum] = node[num] + 1; + DFS(nodeNum); + } + } + + } // End of DFS } // End of Main class \ No newline at end of file diff --git "a/08.08/\354\265\234\354\260\275\354\230\201/README.md" "b/2022/08.08/\354\265\234\354\260\275\354\230\201/README.md" similarity index 100% rename from "08.08/\354\265\234\354\260\275\354\230\201/README.md" rename to "2022/08.08/\354\265\234\354\260\275\354\230\201/README.md" diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" "b/2022/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" similarity index 100% rename from "08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" rename to "2022/08.08/\355\231\251\354\247\200\354\233\220/1697_\354\210\250\353\260\224\352\274\255\354\247\210.java" diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" "b/2022/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" similarity index 100% rename from "08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" rename to "2022/08.08/\355\231\251\354\247\200\354\233\220/2644_\354\264\214\354\210\230\352\263\204\354\202\260.java" diff --git "a/08.08/\355\231\251\354\247\200\354\233\220/readme.md" "b/2022/08.08/\355\231\251\354\247\200\354\233\220/readme.md" similarity index 100% rename from "08.08/\355\231\251\354\247\200\354\233\220/readme.md" rename to "2022/08.08/\355\231\251\354\247\200\354\233\220/readme.md" diff --git a/08.11/readme.md b/2022/08.11/readme.md similarity index 100% rename from 08.11/readme.md rename to 2022/08.11/readme.md diff --git "a/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" "b/2022/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" similarity index 100% rename from "08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" rename to "2022/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\200 2468.java" diff --git "a/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" "b/2022/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" similarity index 100% rename from "08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" rename to "2022/08.11/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016953.java" diff --git "a/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" "b/2022/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" similarity index 100% rename from "08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" rename to "2022/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16953_AB.py" diff --git "a/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" "b/2022/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" similarity index 100% rename from "08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" rename to "2022/08.11/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2468_\354\225\210\354\240\204\354\230\201\354\227\255.py" diff --git "a/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" "b/2022/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" similarity index 100% rename from "08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" rename to "2022/08.11/\354\235\264\354\225\204\353\246\204/16953_AtoB.cpp" diff --git "a/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" "b/2022/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" similarity index 100% rename from "08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" rename to "2022/08.11/\354\235\264\354\225\204\353\246\204/2468_\354\225\210\354\240\204\354\230\201\354\227\255.cpp" diff --git "a/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" "b/2022/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" similarity index 100% rename from "08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" rename to "2022/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_16953]A_B.py" diff --git "a/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" "b/2022/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" similarity index 100% rename from "08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" rename to "2022/08.11/\354\235\264\354\247\200\354\234\244/[BOJ_2468]\354\225\210\354\240\204\354\230\201\354\227\255.py" diff --git "a/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" "b/2022/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" similarity index 100% rename from "08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" rename to "2022/08.11/\354\241\260\354\210\230\354\227\260/16953_A_B.java" diff --git "a/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" "b/2022/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" similarity index 100% rename from "08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" rename to "2022/08.11/\354\241\260\354\210\230\354\227\260/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" diff --git "a/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" "b/2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" similarity index 95% rename from "08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" rename to "2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" index 086d17b..4e684ca 100644 --- "a/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" +++ "b/2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_BFS.java" @@ -1,69 +1,69 @@ -import java.util.*; -import java.io.*; - -// https://www.acmicpc.net/problem/16953 - -/* - * - 뒤에서부터 거꾸로 접근한다. -B의 일의 자리가 1이면 (B % 10 = 1) 일의 자리를 없앤다. (B /= 10) -그렇지 않고, B가 2로 나뉜다면 (B % 2 = 0) 2로 나누어준다. (B /= 2) -둘 다 못한다면, B는 절대로 A가 될 수 없다. -A가 B로 나아가는 수단은 위 두 가지 밖에 없기 때문이다. - */ - -public class Main_16953_AtoB_BFS { - static Queue que = new LinkedList<>(); - - static long A, B; - static int count = 1; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_16953.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - A = Long.parseLong(st.nextToken()); - B = Long.parseLong(st.nextToken()); - - BFS(); - System.out.println(count); - } - - static void BFS() { - que.offer(B); - - while( !que.isEmpty() ) { - long num = que.poll(); - String str = Long.toString(num); - - // 탈출 조건 - if(num == A) { - return; - } - else if(num < A) { - count = -1; - return; - } - - if(num % 2 == 0) { - num /= 2; - que.offer(num); - count ++; - } - else if(str.charAt(str.length() -1) == '1') { - num = Long.parseLong( str.substring(0, str.length() - 1) ); - que.offer(num); - count ++; - } - else { - count = -1; - return; - } - - - - } - - } // End of BFS - -} // End of class +import java.util.*; +import java.io.*; + +// https://www.acmicpc.net/problem/16953 + +/* + * - 뒤에서부터 거꾸로 접근한다. +B의 일의 자리가 1이면 (B % 10 = 1) 일의 자리를 없앤다. (B /= 10) +그렇지 않고, B가 2로 나뉜다면 (B % 2 = 0) 2로 나누어준다. (B /= 2) +둘 다 못한다면, B는 절대로 A가 될 수 없다. +A가 B로 나아가는 수단은 위 두 가지 밖에 없기 때문이다. + */ + +public class Main_16953_AtoB_BFS { + static Queue que = new LinkedList<>(); + + static long A, B; + static int count = 1; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_16953.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + A = Long.parseLong(st.nextToken()); + B = Long.parseLong(st.nextToken()); + + BFS(); + System.out.println(count); + } + + static void BFS() { + que.offer(B); + + while( !que.isEmpty() ) { + long num = que.poll(); + String str = Long.toString(num); + + // 탈출 조건 + if(num == A) { + return; + } + else if(num < A) { + count = -1; + return; + } + + if(num % 2 == 0) { + num /= 2; + que.offer(num); + count ++; + } + else if(str.charAt(str.length() -1) == '1') { + num = Long.parseLong( str.substring(0, str.length() - 1) ); + que.offer(num); + count ++; + } + else { + count = -1; + return; + } + + + + } + + } // End of BFS + +} // End of class diff --git "a/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" "b/2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" similarity index 95% rename from "08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" rename to "2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" index 18bdae0..c7aad79 100644 --- "a/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" +++ "b/2022/08.11/\354\265\234\354\260\275\354\230\201/Main_16953_AtoB_\354\235\274\353\260\230\352\265\254\355\230\204.java" @@ -1,47 +1,47 @@ -import java.util.*; -import java.io.*; - -// https://www.acmicpc.net/problem/16953 - -public class Main_16953_AtoB_일반구현 { - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_16953.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - long A = Long.parseLong(st.nextToken()); - long B = Long.parseLong(st.nextToken()); - int count = 1; - - // B가 A보다 크면 계속 반복 - while(B != A) { - String str = Long.toString(B); - - // B가 짝수 일때 - if(B % 2 == 0) { - B /= 2; - } - else if(str.charAt(str.length() -1) == '1') { - B = Long.parseLong( str.substring(0, str.length() - 1) ); - } - // 홀수일 경우 -1 출력 - else { - count = -1; - break; - } - - - // 탈출 조건 - // 반복하면서 B가 계속 작아지면서, A보다 작아질 경우, 틀린것으로 판단 - // -1을 출력 - if(B < A) { - count = -1; - break; - } - - count ++; - } - - System.out.println(count); - } -} +import java.util.*; +import java.io.*; + +// https://www.acmicpc.net/problem/16953 + +public class Main_16953_AtoB_일반구현 { + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_16953.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + long A = Long.parseLong(st.nextToken()); + long B = Long.parseLong(st.nextToken()); + int count = 1; + + // B가 A보다 크면 계속 반복 + while(B != A) { + String str = Long.toString(B); + + // B가 짝수 일때 + if(B % 2 == 0) { + B /= 2; + } + else if(str.charAt(str.length() -1) == '1') { + B = Long.parseLong( str.substring(0, str.length() - 1) ); + } + // 홀수일 경우 -1 출력 + else { + count = -1; + break; + } + + + // 탈출 조건 + // 반복하면서 B가 계속 작아지면서, A보다 작아질 경우, 틀린것으로 판단 + // -1을 출력 + if(B < A) { + count = -1; + break; + } + + count ++; + } + + System.out.println(count); + } +} diff --git "a/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" "b/2022/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" similarity index 96% rename from "08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" rename to "2022/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" index 748f324..94d7520 100644 --- "a/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" +++ "b/2022/08.11/\354\265\234\354\260\275\354\230\201/Main_2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" @@ -1,75 +1,75 @@ -import java.util.*; -import java.io.*; - -public class Main_2468_안전영역 { - static List list = new ArrayList<>(); - static int dirX[] = {0, 0, -1, 1}; // 상 하 좌 우 - static int dirY[] = {-1, 1, 0, 0}; // 상 하 좌 우 - static boolean visit[][]; - static int arr[][]; - - static int N, nowX, nowY; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_2468.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st; - - N = Integer.parseInt(br.readLine()); - - arr = new int[N][N]; - for(int i=0; i= num) { - DFS(i, j, num); - safeArea++; - } - } - } - - max = Math.max(max, safeArea); - } - - System.out.println(max); - } // End of main - - static void DFS(int x, int y, int num) { - visit[x][y] = true; - - for(int i=0; i<4; i++) { - nowX = x + dirX[i]; - nowY = y + dirY[i]; - - if(range_check() && visit[nowX][nowY] == false && arr[nowX][nowY] >= num) { - DFS(nowX, nowY, num); - } - } - - } // End of DFS - - static boolean range_check() { - return (nowX >= 0 && nowY >= 0 && nowX < N && nowY < N); - } // End range_check - +import java.util.*; +import java.io.*; + +public class Main_2468_안전영역 { + static List list = new ArrayList<>(); + static int dirX[] = {0, 0, -1, 1}; // 상 하 좌 우 + static int dirY[] = {-1, 1, 0, 0}; // 상 하 좌 우 + static boolean visit[][]; + static int arr[][]; + + static int N, nowX, nowY; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_2468.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + + arr = new int[N][N]; + for(int i=0; i= num) { + DFS(i, j, num); + safeArea++; + } + } + } + + max = Math.max(max, safeArea); + } + + System.out.println(max); + } // End of main + + static void DFS(int x, int y, int num) { + visit[x][y] = true; + + for(int i=0; i<4; i++) { + nowX = x + dirX[i]; + nowY = y + dirY[i]; + + if(range_check() && visit[nowX][nowY] == false && arr[nowX][nowY] >= num) { + DFS(nowX, nowY, num); + } + } + + } // End of DFS + + static boolean range_check() { + return (nowX >= 0 && nowY >= 0 && nowX < N && nowY < N); + } // End range_check + } // End of Main class \ No newline at end of file diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" "b/2022/08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" similarity index 100% rename from "08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" rename to "2022/08.11/\355\231\251\354\247\200\354\233\220/16953_AtoB.java" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" "b/2022/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" similarity index 100% rename from "08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" rename to "2022/08.11/\355\231\251\354\247\200\354\233\220/2468_\354\225\210\354\240\204\354\230\201\354\227\255.java" diff --git "a/08.11/\355\231\251\354\247\200\354\233\220/readme.md" "b/2022/08.11/\355\231\251\354\247\200\354\233\220/readme.md" similarity index 100% rename from "08.11/\355\231\251\354\247\200\354\233\220/readme.md" rename to "2022/08.11/\355\231\251\354\247\200\354\233\220/readme.md" diff --git a/08.15/readme.md b/2022/08.15/readme.md similarity index 100% rename from 08.15/readme.md rename to 2022/08.15/readme.md diff --git "a/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" "b/2022/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" similarity index 100% rename from "08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" rename to "2022/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20016637.java" diff --git "a/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" "b/2022/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" similarity index 100% rename from "08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" rename to "2022/08.15/\352\266\214\354\243\274\355\230\204/\353\260\261\354\244\20017070.java" diff --git "a/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" "b/2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" similarity index 100% rename from "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" rename to "2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16637_\352\264\204\355\230\270\354\266\224\352\260\200\355\225\230\352\270\260.py" diff --git "a/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" "b/2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" similarity index 100% rename from "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" rename to "2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17070_\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\2601.py" diff --git "a/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" "b/2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" similarity index 100% rename from "08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" rename to "2022/08.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" diff --git "a/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" "b/2022/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" similarity index 100% rename from "08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" rename to "2022/08.15/\354\235\264\354\225\204\353\246\204/16637_\352\264\204\355\230\270_\354\266\224\352\260\200\355\225\230\352\270\260.cpp" diff --git "a/08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" "b/2022/08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" similarity index 100% rename from "08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" rename to "2022/08.15/\354\235\264\354\225\204\353\246\204/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\260.cpp" diff --git "a/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" "b/2022/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" similarity index 100% rename from "08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" rename to "2022/08.15/\354\235\264\354\225\204\353\246\204/17135_\354\272\220\354\212\254_\353\224\224\355\216\234\354\212\244.cpp" diff --git "a/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" "b/2022/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" similarity index 100% rename from "08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" rename to "2022/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17070]\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\2601.py" diff --git "a/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" "b/2022/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" similarity index 100% rename from "08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" rename to "2022/08.15/\354\235\264\354\247\200\354\234\244/[BOJ_17135]\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.py" diff --git "a/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" "b/2022/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" similarity index 100% rename from "08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" rename to "2022/08.15/\354\240\225\355\230\270\354\241\260/\352\264\204\355\230\270\354\266\224\352\260\200" diff --git "a/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" "b/2022/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" similarity index 100% rename from "08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" rename to "2022/08.15/\354\240\225\355\230\270\354\241\260/\355\214\214\354\235\264\355\224\204\354\230\256\352\270\260\352\270\260" diff --git "a/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" "b/2022/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" similarity index 100% rename from "08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" rename to "2022/08.15/\354\241\260\354\210\230\354\227\260/17070_\355\214\214\354\235\264\355\224\204_\354\230\256\352\270\260\352\270\2601.java" diff --git "a/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" "b/2022/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" similarity index 100% rename from "08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" rename to "2022/08.15/\354\241\260\354\210\230\354\227\260/17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" diff --git "a/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" "b/2022/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" similarity index 97% rename from "08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" rename to "2022/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" index dda5acf..b5f53f2 100644 --- "a/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" +++ "b/2022/08.15/\354\265\234\354\260\275\354\230\201/Main_16498_\354\236\221\354\235\200_\353\262\214\354\240\220.java" @@ -1,67 +1,67 @@ -import java.util.*; -import java.io.*; - -public class Main_16498_작은_벌점 { - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/16498.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int minPenaltyScore = (int) (2 * Math.pow(10, 9)); - - int cardHavingCount[] = new int[3]; - StringTokenizer st = new StringTokenizer(br.readLine()); - int a = Integer.parseInt(st.nextToken()); - int b = Integer.parseInt(st.nextToken()); - int c = Integer.parseInt(st.nextToken()); - HashSet aSet = new HashSet<>(); - HashSet bSet = new HashSet<>(); - HashSet cSet = new HashSet<>(); - - cardHavingCount[0] = a; - cardHavingCount[1] = b; - cardHavingCount[2] = c; - int total = a + b + c; - int allCardArr[] = new int[total]; - - st = new StringTokenizer(br.readLine()); - for(int i=0; i aSet = new HashSet<>(); + HashSet bSet = new HashSet<>(); + HashSet cSet = new HashSet<>(); + + cardHavingCount[0] = a; + cardHavingCount[1] = b; + cardHavingCount[2] = c; + int total = a + b + c; + int allCardArr[] = new int[total]; + + st = new StringTokenizer(br.readLine()); + for(int i=0; i numList; - static List opList; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/16637.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - int N = Integer.parseInt(br.readLine()); - numList = new ArrayList<>(); - opList = new ArrayList<>(); - - String str = br.readLine(); - for (int i = 0; i < N; i++) { - char ch = str.charAt(i); - - if (ch == '*' || ch == '+' || ch == '-') { - opList.add(ch); - } else { - numList.add(Character.getNumericValue(ch)); - } - } - - DFS(0, numList.get(0)); - System.out.println(result); - } // End of main - - private static int calc(int num1, int num2, char oper) { - if (oper == '*') { - return num1 * num2; - } else if (oper == '+') { - return num1 + num2; - } else { - return num1 - num2; - } - } // End of calc - - private static void DFS(int depth, int total) { - if (depth == opList.size()) { - result = Math.max(result, total); - return; - } - - DFS(depth + 1, calc(total, numList.get(depth + 1), opList.get(depth))); - - if(depth + 2 <= opList.size()) { - DFS(depth + 2, calc(total, calc(numList.get(depth + 1), numList.get(depth + 2), opList.get(depth + 1)), opList.get(depth) )); - } - - } // End of DFS +import java.util.*; +import java.io.*; + +public class Main_16637_괄호_추가하기 { + static int result = Integer.MIN_VALUE; + static List numList; + static List opList; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/16637.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + numList = new ArrayList<>(); + opList = new ArrayList<>(); + + String str = br.readLine(); + for (int i = 0; i < N; i++) { + char ch = str.charAt(i); + + if (ch == '*' || ch == '+' || ch == '-') { + opList.add(ch); + } else { + numList.add(Character.getNumericValue(ch)); + } + } + + DFS(0, numList.get(0)); + System.out.println(result); + } // End of main + + private static int calc(int num1, int num2, char oper) { + if (oper == '*') { + return num1 * num2; + } else if (oper == '+') { + return num1 + num2; + } else { + return num1 - num2; + } + } // End of calc + + private static void DFS(int depth, int total) { + if (depth == opList.size()) { + result = Math.max(result, total); + return; + } + + DFS(depth + 1, calc(total, numList.get(depth + 1), opList.get(depth))); + + if(depth + 2 <= opList.size()) { + DFS(depth + 2, calc(total, calc(numList.get(depth + 1), numList.get(depth + 2), opList.get(depth + 1)), opList.get(depth) )); + } + + } // End of DFS } // End of Main class \ No newline at end of file diff --git "a/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" "b/2022/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" similarity index 97% rename from "08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" rename to "2022/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" index 4f45401..66a39d7 100644 --- "a/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" +++ "b/2022/08.15/\354\265\234\354\260\275\354\230\201/Main_17135_\354\272\220\354\212\254\353\224\224\355\216\234\354\212\244.java" @@ -1,43 +1,43 @@ -import java.util.*; -import java.io.*; - -// 성을 적에게서 지키기 위해 궁수 3명을 배치하려고 한다. -// 궁수의 공격이 끝나면, 적이 이동한다. 적은 아래로 한 칸 이동하며, -// 성이 있는 칸으로 이동한 경우에는 게임에서 제외된다. 모든 적이 격자판에서 제외되면 게임이 끝난다. -public class Main_17135_캐슬디펜스 { - static int N, M, D; - static int arr[][]; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/17135.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - StringTokenizer st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); - D = Integer.parseInt(st.nextToken()); // 궁수의 공격 거리 제한 - - arr = new int[N][M]; - for(int i=0; i N) { - return; - } - - quit(day + 1, totalPrice); // depth는 날짜를 의미하는데, 해당 날짜에 상담을 하지 않고, 넘기는 경우의 수 - quit(day + arr[day][0], totalPrice + arr[day][1]); // 해당 날짜에 상담을 진행하는 경우의 수 - } // End of DP +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/14501 +public class Main_14501_퇴사 { + static int[][] arr; + static int N; + static int result = -1; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/14501.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + arr = new int[N][2]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + arr[i][0] = Integer.parseInt(st.nextToken()); + arr[i][1] = Integer.parseInt(st.nextToken()); + } + + quit(0, 0); + System.out.println(result); + } // End of main + + private static void quit(int day, int totalPrice) { + if (day == N) { + result = Math.max(result, totalPrice); + return; + } else if (day > N) { + return; + } + + quit(day + 1, totalPrice); // depth는 날짜를 의미하는데, 해당 날짜에 상담을 하지 않고, 넘기는 경우의 수 + quit(day + arr[day][0], totalPrice + arr[day][1]); // 해당 날짜에 상담을 진행하는 경우의 수 + } // End of DP } // End of Main class \ No newline at end of file diff --git "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" "b/2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" similarity index 95% rename from "08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" rename to "2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" index 6a092ab..9dd71fd 100644 --- "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" +++ "b/2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14502_\354\227\260\352\265\254\354\206\214.java" @@ -1,132 +1,132 @@ -import java.util.*; -import java.io.*; - -// 문제 : https://www.acmicpc.net/problem/14502 -// 목표 : 0은 빈칸, 1은 벽, 2는 바이러스가 있는 곳. -// 벽이 없으면 바이러스는 모든 빈칸으로 펴저나갈 수 있다. - -public class Main_14502_연구소 { - static int dirX[] = {0, 0, -1, 1}; - static int dirY[] = {-1, 1, 0, 0}; - static int arr[][]; - - static int result = Integer.MIN_VALUE / 16; - static int nowX, nowY, N, M; - - static class Node { - int x; - int y; - - public Node(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Node - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_14502.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - N = Integer.parseInt(st.nextToken()); // 가로 - M = Integer.parseInt(st.nextToken());// 세로 - - arr = new int[N][M]; - - // 연구소와 똑같은 지도 배열 생성. - for(int i=0; i que = new LinkedList<>(); - - //벽을 만들어놓은 배열을 그대로 지도로 카피 - for(int i=0; i= 0 && nowX < N && nowY >= 0 && nowY < M); - } // End of Range_check - +import java.util.*; +import java.io.*; + +// 문제 : https://www.acmicpc.net/problem/14502 +// 목표 : 0은 빈칸, 1은 벽, 2는 바이러스가 있는 곳. +// 벽이 없으면 바이러스는 모든 빈칸으로 펴저나갈 수 있다. + +public class Main_14502_연구소 { + static int dirX[] = {0, 0, -1, 1}; + static int dirY[] = {-1, 1, 0, 0}; + static int arr[][]; + + static int result = Integer.MIN_VALUE / 16; + static int nowX, nowY, N, M; + + static class Node { + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Node + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_14502.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 가로 + M = Integer.parseInt(st.nextToken());// 세로 + + arr = new int[N][M]; + + // 연구소와 똑같은 지도 배열 생성. + for(int i=0; i que = new LinkedList<>(); + + //벽을 만들어놓은 배열을 그대로 지도로 카피 + for(int i=0; i= 0 && nowX < N && nowY >= 0 && nowY < M); + } // End of Range_check + } // End of class \ No newline at end of file diff --git "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" "b/2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" similarity index 96% rename from "08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" rename to "2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" index 0102b02..2687ac5 100644 --- "a/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" +++ "b/2022/08.25/\354\265\234\354\260\275\354\230\201/Main_14889_\354\212\244\355\203\200\355\212\270\354\231\200\353\247\201\355\201\254.java" @@ -1,77 +1,77 @@ -import java.util.*; -import java.io.*; - -public class Main_14889_스타트와링크 { - static int arr[][]; - static boolean visit[]; - static int N; - - static int result = Integer.MAX_VALUE; // 최소값 결과 값 - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/input_bj_14889.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - N = Integer.parseInt(br.readLine()); - arr = new int[N][N]; - visit = new boolean[N]; - - for(int i=0; i allList; // 전체 몬스터와 고객들이 들어갈 리스트 - static int totalCount; // 총 몬스터와 고객의 수 - - static boolean[] isVisited; // 방문 여부 배열 - static boolean[] monsterisVisited; // 몬스터 처치 여부 배열 - static int result; // 최종 결과 값 - - static class Coordinates { - int x; - int y; - int dist; - - public Coordinates(int x, int y, int dist) { - this.x = x; - this.y = y; - this.dist = dist; - } - } // End of Coordinates class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/15172.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - - int TC = Integer.parseInt(br.readLine()); - for (int t = 1; t <= TC; t++) { - sb.append('#').append(t).append(' '); - - N = Integer.parseInt(br.readLine()); - init(); // 변수들 초기화 - int clientCount = 0; // 고객의 수를 확인할 변수 - - for (int i = 0; i < N; i++) { - StringTokenizer st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - tempMap[i][j] = map[i][j]; - - if (map[i][j] > 0) { - clientCount = Math.max(clientCount, map[i][j]); - allList.add(map[i][j]); - } else if (map[i][j] < 0) { - allList.add(map[i][j]); - } - } - } - - Collections.sort(allList); - totalCount = allList.size(); - - isVisited = new boolean[totalCount]; - monsterisVisited = new boolean[clientCount]; // 몬스터 방문여부를 체크할 배열 - orderArr = new int[totalCount]; // 방문 순서 경우의 수를 담을 배열 고객의 수의 2배 값으로 배열 크기 할당. - DFS(0, totalCount); // 경우의 수 만들기 - - sb.append(result).append('\n'); - } // End of for(TC) - - bw.write(sb.toString()); - bw.close(); - } // End of main - - // 첫번쨰 해결해야할 과제는 올바른 방문 순서를 만들어서 모든 경우의 수를 만들기 - // 배열의 0번째는 무조건 몬스터가 들어와야 하고, 고객을 방문할 때는 해당 몬스터를 방문한 후에 고객을 방문할 수 있음 - private static void DFS(int depth, int depthLimit) { // 방문 순서를 조합하는 백트래킹 - if (depth == depthLimit) { - Coordinates hunter = new Coordinates(0, 0, 0); // 첫 번째 사냥꾼의 시작 위치는 항상 0, 0 거리도 0 - - int count = 0; - for (int i = 0; i < totalCount; i++) { - int num = orderArr[i]; - hunter = BFS(hunter.x, hunter.y, num, hunter.dist); - count += hunter.dist; - } - - result = Math.min(result, count); - return; - } - - // 음수는 고객, 양수는 몬스터 - for (int i = 0; i < depthLimit; i++) { - int num = allList.get(i); - - if (num < 0 && !monsterisVisited[(Math.abs(num) - 1)]) { // 고객일 때 요청한 몬스터가 죽지 않았으면 방문할 수 없다. - continue; - } - - if (isVisited[i]) continue; - isVisited[i] = true; - - if (num > 0) { // num이 양수 즉, 몬스터 일 때, - monsterisVisited[num - 1] = true; - orderArr[depth] = num; - DFS(depth + 1, depthLimit); - monsterisVisited[num - 1] = false; - } else { // num이 음수 즉, 고객일 때 - orderArr[depth] = num; - DFS(depth + 1, depthLimit); - } - - isVisited[i] = false; - } - } // End of DFS - - private static Coordinates BFS(int x, int y, int target, int totalDist) { - Coordinates hunter = new Coordinates(x, y, totalDist); - - if (tempMap[x][y] == target) { - return hunter; - } - - boolean[][] isVisited = new boolean[N][N]; - Queue que = new LinkedList<>(); - isVisited[x][y] = true; - que.offer(new Coordinates(x, y, 0)); - - while (!que.isEmpty()) { - Coordinates cor = que.poll(); - - for (int i = 0; i < 4; i++) { - int nowX = cor.x + dirX[i]; - int nowY = cor.y + dirY[i]; - int dist = cor.dist; - - if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY]) { - isVisited[nowX][nowY] = true; - if (tempMap[nowX][nowY] == target) { - hunter.dist = dist + 1; - hunter.x = nowX; - hunter.y = nowY; - return hunter; - } - - que.offer(new Coordinates(nowX, nowY, dist + 1)); - } - - } - } - - return hunter; - } // End of BFS - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; - } // End of rangeCheck - - private static void init() { // 변수 초기화 메소드 - map = new int[N][N]; - tempMap = new int[N][N]; - allList = new ArrayList<>(); - result = Integer.MAX_VALUE / 4; // 오버플로우 방지 - } // End of init +import java.io.*; +import java.util.*; + +// https://swexpertacademy.com/main/solvingProblem/solvingProblem.do +// 모든 몬스터를 없애고 고객들에게 확인시켜 작업을 완료하는 데 가장 빠른 시간을 구하는 프로그램을 작성해라. + +// 몬스터를 처리하는 순서는 상관이 없다. 고객들에게 확인시켜 주는 순서도 상관이 없다. +// 몬스터를 처리했다고 해서 바로 그 몬스터를 처리해 달라고 요청한 고객에게 돌아가 확인할 필요도 없다. +public class Main_15172_헌터 { + static int[][] map; + static int[][] tempMap; + + static int N; + static int[] dirX = {0, 0, -1, 1}; // 헌터는 상하좌우로 움직인다. + static int[] dirY = {1, -1, 0, 0}; + + static int[] orderArr; // 경우의 수를 담을 배열 + static List allList; // 전체 몬스터와 고객들이 들어갈 리스트 + static int totalCount; // 총 몬스터와 고객의 수 + + static boolean[] isVisited; // 방문 여부 배열 + static boolean[] monsterisVisited; // 몬스터 처치 여부 배열 + static int result; // 최종 결과 값 + + static class Coordinates { + int x; + int y; + int dist; + + public Coordinates(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } // End of Coordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/15172.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int TC = Integer.parseInt(br.readLine()); + for (int t = 1; t <= TC; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); // 변수들 초기화 + int clientCount = 0; // 고객의 수를 확인할 변수 + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + tempMap[i][j] = map[i][j]; + + if (map[i][j] > 0) { + clientCount = Math.max(clientCount, map[i][j]); + allList.add(map[i][j]); + } else if (map[i][j] < 0) { + allList.add(map[i][j]); + } + } + } + + Collections.sort(allList); + totalCount = allList.size(); + + isVisited = new boolean[totalCount]; + monsterisVisited = new boolean[clientCount]; // 몬스터 방문여부를 체크할 배열 + orderArr = new int[totalCount]; // 방문 순서 경우의 수를 담을 배열 고객의 수의 2배 값으로 배열 크기 할당. + DFS(0, totalCount); // 경우의 수 만들기 + + sb.append(result).append('\n'); + } // End of for(TC) + + bw.write(sb.toString()); + bw.close(); + } // End of main + + // 첫번쨰 해결해야할 과제는 올바른 방문 순서를 만들어서 모든 경우의 수를 만들기 + // 배열의 0번째는 무조건 몬스터가 들어와야 하고, 고객을 방문할 때는 해당 몬스터를 방문한 후에 고객을 방문할 수 있음 + private static void DFS(int depth, int depthLimit) { // 방문 순서를 조합하는 백트래킹 + if (depth == depthLimit) { + Coordinates hunter = new Coordinates(0, 0, 0); // 첫 번째 사냥꾼의 시작 위치는 항상 0, 0 거리도 0 + + int count = 0; + for (int i = 0; i < totalCount; i++) { + int num = orderArr[i]; + hunter = BFS(hunter.x, hunter.y, num, hunter.dist); + count += hunter.dist; + } + + result = Math.min(result, count); + return; + } + + // 음수는 고객, 양수는 몬스터 + for (int i = 0; i < depthLimit; i++) { + int num = allList.get(i); + + if (num < 0 && !monsterisVisited[(Math.abs(num) - 1)]) { // 고객일 때 요청한 몬스터가 죽지 않았으면 방문할 수 없다. + continue; + } + + if (isVisited[i]) continue; + isVisited[i] = true; + + if (num > 0) { // num이 양수 즉, 몬스터 일 때, + monsterisVisited[num - 1] = true; + orderArr[depth] = num; + DFS(depth + 1, depthLimit); + monsterisVisited[num - 1] = false; + } else { // num이 음수 즉, 고객일 때 + orderArr[depth] = num; + DFS(depth + 1, depthLimit); + } + + isVisited[i] = false; + } + } // End of DFS + + private static Coordinates BFS(int x, int y, int target, int totalDist) { + Coordinates hunter = new Coordinates(x, y, totalDist); + + if (tempMap[x][y] == target) { + return hunter; + } + + boolean[][] isVisited = new boolean[N][N]; + Queue que = new LinkedList<>(); + isVisited[x][y] = true; + que.offer(new Coordinates(x, y, 0)); + + while (!que.isEmpty()) { + Coordinates cor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = cor.x + dirX[i]; + int nowY = cor.y + dirY[i]; + int dist = cor.dist; + + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY]) { + isVisited[nowX][nowY] = true; + if (tempMap[nowX][nowY] == target) { + hunter.dist = dist + 1; + hunter.x = nowX; + hunter.y = nowY; + return hunter; + } + + que.offer(new Coordinates(nowX, nowY, dist + 1)); + } + + } + } + + return hunter; + } // End of BFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { // 변수 초기화 메소드 + map = new int[N][N]; + tempMap = new int[N][N]; + allList = new ArrayList<>(); + result = Integer.MAX_VALUE / 4; // 오버플로우 방지 + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.01/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" "b/2022/09.01/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" similarity index 100% rename from "09.01/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" rename to "2022/09.01/\354\235\264\354\225\204\353\246\204/1\353\262\210.cpp" diff --git "a/09.01/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" "b/2022/09.01/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" similarity index 100% rename from "09.01/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" rename to "2022/09.01/\354\235\264\354\225\204\353\246\204/2\353\262\210.cpp" diff --git "a/09.01/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" "b/2022/09.01/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" similarity index 100% rename from "09.01/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" rename to "2022/09.01/\354\241\260\354\210\230\354\227\260/1\353\262\210.java" diff --git "a/09.01/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" "b/2022/09.01/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" similarity index 100% rename from "09.01/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" rename to "2022/09.01/\354\241\260\354\210\230\354\227\260/\355\205\214\354\212\244\355\212\270\354\274\200\354\235\264\354\212\244.txt" diff --git a/09.05/readme.md b/2022/09.05/readme.md similarity index 100% rename from 09.05/readme.md rename to 2022/09.05/readme.md diff --git "a/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" "b/2022/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" similarity index 100% rename from "09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" rename to "2022/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\353\224\224\354\240\200\355\212\270\354\271\264\355\216\230.py" diff --git "a/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" "b/2022/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" similarity index 100% rename from "09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" rename to "2022/09.05/\354\206\241\352\270\260\355\233\210/SWEA_\355\203\210\354\230\245\353\262\224\352\262\200\352\261\260.py" diff --git "a/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" "b/2022/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" similarity index 100% rename from "09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" rename to "2022/09.05/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.py" diff --git "a/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" "b/2022/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" similarity index 100% rename from "09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" rename to "2022/09.05/\354\241\260\354\210\230\354\227\260/\355\203\210\354\243\274\353\262\224 \352\262\200\352\261\260.java" diff --git "a/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" "b/2022/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" similarity index 97% rename from "09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" rename to "2022/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" index 3d59ccf..af66a01 100644 --- "a/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" +++ "b/2022/09.05/\354\265\234\354\260\275\354\230\201/Main_1953_\355\203\210\354\243\274\353\262\224_\352\262\200\352\261\260.java" @@ -1,151 +1,151 @@ -import java.util.*; -import java.io.*; - - -public class Main_1953_탈주범_검거 { - static int N, M, R, C, L; - static int[][] map; - static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 - static int[] dirY = {0, 0, -1, 1}; - static int result; - - static class Coordiantes { - int x; - int y; - int time; - - public Coordiantes(int x, int y, int time) { - this.x = x; - this.y = y; - this.time = time; - } - } // End of Coordinates class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/1953.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - StringTokenizer st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); - R = Integer.parseInt(st.nextToken()); - C = Integer.parseInt(st.nextToken()); - L = Integer.parseInt(st.nextToken()); - - result = 0; - map = new int[N][M]; - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < M; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - } - } - - BFS(R, C); - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void BFS(int x, int y) { - Queue que = new LinkedList<>(); - int[][] isVisited2 = new int[N][M]; - - isVisited2[x][y] = 1; - que.offer(new Coordiantes(x, y, 1)); - int nowX; - int nowY; - int time; - int pipe; - - while (!que.isEmpty()) { - Coordiantes cor = que.poll(); - pipe = map[cor.x][cor.y]; - int loopStart = 0; - int loopLimit = 4; - int loopIncrease = 1; - - if (pipe == 2) { - // 상 하 - loopLimit = 2; - } else if (pipe == 3) { - // 좌 우 - loopStart = 2; - } else if (pipe == 4) { - // 상, 우 - loopIncrease = 3; - } else if (pipe == 5) { - // 하, 우 - loopStart = 1; - loopIncrease = 2; - } else if (pipe == 6) { - // 하, 좌 - loopStart = 1; - loopLimit = 3; - } else if (pipe == 7) { - // 상,좌 - loopLimit = 3; - loopIncrease = 2; - } - - for (int i = loopStart; i < loopLimit; i = i + loopIncrease) { - nowX = cor.x + dirX[i]; - nowY = cor.y + dirY[i]; - time = cor.time + 1; - - // 상 하 좌 우 방향 - - if (rangeCheck(nowX, nowY) && isVisited2[nowX][nowY] == 0) { - if ((i == 0 || i == 1) && map[nowX][nowY] == 3) { - // 상 하 방향인데, 3번 파이프는 불가능 - continue; - } else if ((i == 2 || i == 3) && map[nowX][nowY] == 2) { - // 좌 우 방향에서 , 2번 파이프는 불가능 - continue; - } else if (i == 0 && (map[nowX][nowY] == 4 || map[nowX][nowY] == 7)) { - continue; - } else if (i == 1 && (map[nowX][nowY] == 5 || map[nowX][nowY] == 6)) { - continue; - } else if (i == 2 && (map[nowX][nowY] == 6 || map[nowX][nowY] == 7)) { - continue; - } else if (i == 3 && (map[nowX][nowY] == 4 || map[nowX][nowY] == 5)) { - continue; - } - - if (map[nowX][nowY] != 0) { - if (L == time) { - isVisited2[nowX][nowY] = time; - continue; - } - - isVisited2[nowX][nowY] = time; - que.offer(new Coordiantes(nowX, nowY, time)); - } - } - - } - } - - for (int i = 0; i < N; i++) { - for (int j = 0; j < M; j++) { - if (isVisited2[i][j] > 0 && isVisited2[i][j] <= L) { - result++; - } - } - } - - } // End of BFS - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; - } // End of rangeCheck +import java.util.*; +import java.io.*; + + +public class Main_1953_탈주범_검거 { + static int N, M, R, C, L; + static int[][] map; + static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 + static int[] dirY = {0, 0, -1, 1}; + static int result; + + static class Coordiantes { + int x; + int y; + int time; + + public Coordiantes(int x, int y, int time) { + this.x = x; + this.y = y; + this.time = time; + } + } // End of Coordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/1953.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + + result = 0; + map = new int[N][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + BFS(R, C); + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void BFS(int x, int y) { + Queue que = new LinkedList<>(); + int[][] isVisited2 = new int[N][M]; + + isVisited2[x][y] = 1; + que.offer(new Coordiantes(x, y, 1)); + int nowX; + int nowY; + int time; + int pipe; + + while (!que.isEmpty()) { + Coordiantes cor = que.poll(); + pipe = map[cor.x][cor.y]; + int loopStart = 0; + int loopLimit = 4; + int loopIncrease = 1; + + if (pipe == 2) { + // 상 하 + loopLimit = 2; + } else if (pipe == 3) { + // 좌 우 + loopStart = 2; + } else if (pipe == 4) { + // 상, 우 + loopIncrease = 3; + } else if (pipe == 5) { + // 하, 우 + loopStart = 1; + loopIncrease = 2; + } else if (pipe == 6) { + // 하, 좌 + loopStart = 1; + loopLimit = 3; + } else if (pipe == 7) { + // 상,좌 + loopLimit = 3; + loopIncrease = 2; + } + + for (int i = loopStart; i < loopLimit; i = i + loopIncrease) { + nowX = cor.x + dirX[i]; + nowY = cor.y + dirY[i]; + time = cor.time + 1; + + // 상 하 좌 우 방향 + + if (rangeCheck(nowX, nowY) && isVisited2[nowX][nowY] == 0) { + if ((i == 0 || i == 1) && map[nowX][nowY] == 3) { + // 상 하 방향인데, 3번 파이프는 불가능 + continue; + } else if ((i == 2 || i == 3) && map[nowX][nowY] == 2) { + // 좌 우 방향에서 , 2번 파이프는 불가능 + continue; + } else if (i == 0 && (map[nowX][nowY] == 4 || map[nowX][nowY] == 7)) { + continue; + } else if (i == 1 && (map[nowX][nowY] == 5 || map[nowX][nowY] == 6)) { + continue; + } else if (i == 2 && (map[nowX][nowY] == 6 || map[nowX][nowY] == 7)) { + continue; + } else if (i == 3 && (map[nowX][nowY] == 4 || map[nowX][nowY] == 5)) { + continue; + } + + if (map[nowX][nowY] != 0) { + if (L == time) { + isVisited2[nowX][nowY] = time; + continue; + } + + isVisited2[nowX][nowY] = time; + que.offer(new Coordiantes(nowX, nowY, time)); + } + } + + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (isVisited2[i][j] > 0 && isVisited2[i][j] <= L) { + result++; + } + } + } + + } // End of BFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of rangeCheck } // End of Main class \ No newline at end of file diff --git "a/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" "b/2022/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" similarity index 97% rename from "09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" rename to "2022/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" index da4829b..640a5c4 100644 --- "a/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" +++ "b/2022/09.05/\354\265\234\354\260\275\354\230\201/Main_2105_\353\224\224\354\240\200\355\212\270_\354\271\264\355\216\230.java" @@ -1,94 +1,94 @@ -import java.util.*; -import java.io.*; - -// 디저트를 가장 많이 먹을 수 있는 경우의 디저트 종류 수를 출력 -// 디저트를 먹을 수 없는 경우 -1을 출력 -// 탐색하는 방향에서 직사각형의 특징을 생각해야 됨 -> 직사각형의 특징. 마주보는 변의 길이가 같음 -public class Main_2105_디저트_카페 { - static int N; - static int[][] map; - static int[] dirX = {-1, 1, 1, -1}; // 대각선 방향으로 시계방향. (상우 -> 하우 -> 하좌 -> 상좌) - static int[] dirY = {1, 1, -1, -1}; - static boolean[][] isVisited; // map의 경로상 방문여부를 체크하는 배열 - static boolean[] isVisitedDesert; // 방문한 디저트가 겹치는지 여부를 파악하기 위한 배열 - static int maxResult; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2105.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - N = Integer.parseInt(br.readLine()); - init(); // 변수 초기화 - - for (int i = 0; i < N; i++) { - StringTokenizer st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - } - } - - // 완전탐색 & 백트래킹 - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - if (i == 0 && (j == 0 || j == N - 1)) continue; - else if (i == N - 1 && (j == 0 || j == N - 1)) continue; - - isVisited[i][j] = true; - isVisitedDesert[map[i][j]] = true; - DFS(i, j, i, j, 1, 0); - isVisitedDesert[map[i][j]] = false; - isVisited[i][j] = false; - } - } - - sb.append(maxResult).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void DFS(int startX, int startY, int x, int y, int counting, int index) { - for (int i = index; i < 4; i++) { - int nowX = x + dirX[i]; - int nowY = y + dirY[i]; - - // 재귀 탈출 조건 - // counting이 4이상이고, 시작한 곳으로 돌아오면 중지, - if (startX == nowX && startY == nowY && counting >= 4) { - maxResult = Math.max(maxResult, counting); - return; - } - - // 만약 i의 값으로 계속 이동할 수 있으면 계속해서 이동. - if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && !isVisitedDesert[map[nowX][nowY]]) { - - isVisited[nowX][nowY] = true; - isVisitedDesert[map[nowX][nowY]] = true; - - // 만약 i의 값으로 계속 이동할 수 있으면 계속해서 이동. - DFS(startX, startY, nowX, nowY, counting + 1, i); - isVisitedDesert[map[nowX][nowY]] = false; - isVisited[nowX][nowY] = false; - } - } - - } // End of DFS - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; - } // End of rangeCheck - - private static void init() { // 변수를 초기화 하는 메소드 - map = new int[N][N]; - isVisited = new boolean[N][N]; - isVisitedDesert = new boolean[101]; - maxResult = -1; - } // End of init -} // End of Main class +import java.util.*; +import java.io.*; + +// 디저트를 가장 많이 먹을 수 있는 경우의 디저트 종류 수를 출력 +// 디저트를 먹을 수 없는 경우 -1을 출력 +// 탐색하는 방향에서 직사각형의 특징을 생각해야 됨 -> 직사각형의 특징. 마주보는 변의 길이가 같음 +public class Main_2105_디저트_카페 { + static int N; + static int[][] map; + static int[] dirX = {-1, 1, 1, -1}; // 대각선 방향으로 시계방향. (상우 -> 하우 -> 하좌 -> 상좌) + static int[] dirY = {1, 1, -1, -1}; + static boolean[][] isVisited; // map의 경로상 방문여부를 체크하는 배열 + static boolean[] isVisitedDesert; // 방문한 디저트가 겹치는지 여부를 파악하기 위한 배열 + static int maxResult; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2105.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); // 변수 초기화 + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + // 완전탐색 & 백트래킹 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (i == 0 && (j == 0 || j == N - 1)) continue; + else if (i == N - 1 && (j == 0 || j == N - 1)) continue; + + isVisited[i][j] = true; + isVisitedDesert[map[i][j]] = true; + DFS(i, j, i, j, 1, 0); + isVisitedDesert[map[i][j]] = false; + isVisited[i][j] = false; + } + } + + sb.append(maxResult).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int startX, int startY, int x, int y, int counting, int index) { + for (int i = index; i < 4; i++) { + int nowX = x + dirX[i]; + int nowY = y + dirY[i]; + + // 재귀 탈출 조건 + // counting이 4이상이고, 시작한 곳으로 돌아오면 중지, + if (startX == nowX && startY == nowY && counting >= 4) { + maxResult = Math.max(maxResult, counting); + return; + } + + // 만약 i의 값으로 계속 이동할 수 있으면 계속해서 이동. + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && !isVisitedDesert[map[nowX][nowY]]) { + + isVisited[nowX][nowY] = true; + isVisitedDesert[map[nowX][nowY]] = true; + + // 만약 i의 값으로 계속 이동할 수 있으면 계속해서 이동. + DFS(startX, startY, nowX, nowY, counting + 1, i); + isVisitedDesert[map[nowX][nowY]] = false; + isVisited[nowX][nowY] = false; + } + } + + } // End of DFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { // 변수를 초기화 하는 메소드 + map = new int[N][N]; + isVisited = new boolean[N][N]; + isVisitedDesert = new boolean[101]; + maxResult = -1; + } // End of init +} // End of Main class diff --git "a/09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" "b/2022/09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" similarity index 100% rename from "09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" rename to "2022/09.05/\355\231\251\354\247\200\354\233\220/\355\203\210\354\243\274\353\262\224\352\262\200\352\261\260.java" diff --git a/09.12/Readme.md b/2022/09.12/Readme.md similarity index 100% rename from 09.12/Readme.md rename to 2022/09.12/Readme.md diff --git "a/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" "b/2022/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" similarity index 100% rename from "09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" rename to "2022/09.12/\352\266\214\354\243\274\355\230\204/swea2117.java" diff --git "a/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/2022/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" similarity index 100% rename from "09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" rename to "2022/09.12/\352\266\214\354\243\274\355\230\204/\353\262\214\352\277\200\354\261\204\354\267\250.java" diff --git "a/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" "b/2022/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" similarity index 100% rename from "09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" rename to "2022/09.12/\352\266\214\354\243\274\355\230\204/\353\263\264\355\230\270\355\225\204\353\246\204.java" diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" "b/2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" similarity index 100% rename from "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" rename to "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2112_\353\263\264\355\230\270\355\225\204\353\246\204.py" diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" "b/2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" similarity index 100% rename from "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" rename to "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2115_\353\262\214\352\277\200\354\261\204\354\267\250.py" diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" "b/2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" similarity index 100% rename from "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" rename to "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2117_\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.py" diff --git "a/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" "b/2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" similarity index 100% rename from "09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" rename to "2022/09.12/\354\206\241\352\270\260\355\233\210/SWEA_2382_\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.py" diff --git "a/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" "b/2022/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" similarity index 100% rename from "09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" rename to "2022/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\214\352\277\200 \354\261\204\354\267\250.py" diff --git "a/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" "b/2022/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" similarity index 100% rename from "09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" rename to "2022/09.12/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\231\210 \353\260\251\353\262\225 \354\204\234\353\271\204\354\212\244.py" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" "b/2022/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" similarity index 100% rename from "09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" rename to "2022/09.12/\354\240\225\355\230\270\354\241\260/\353\257\270\354\203\235\353\254\274\352\262\251\353\246\254.java" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/2022/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" similarity index 100% rename from "09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" rename to "2022/09.12/\354\240\225\355\230\270\354\241\260/\353\262\214\352\277\200\354\261\204\354\267\250.java" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" "b/2022/09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" similarity index 100% rename from "09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" rename to "2022/09.12/\354\240\225\355\230\270\354\241\260/\353\263\264\355\230\270\355\225\204\353\246\204.java" diff --git "a/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" "b/2022/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" similarity index 100% rename from "09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" rename to "2022/09.12/\354\240\225\355\230\270\354\241\260/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/README.md" "b/2022/09.12/\354\241\260\354\210\230\354\227\260/README.md" similarity index 100% rename from "09.12/\354\241\260\354\210\230\354\227\260/README.md" rename to "2022/09.12/\354\241\260\354\210\230\354\227\260/README.md" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" "b/2022/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" similarity index 100% rename from "09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" rename to "2022/09.12/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" "b/2022/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" similarity index 100% rename from "09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" rename to "2022/09.12/\354\241\260\354\210\230\354\227\260/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" diff --git "a/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" "b/2022/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" similarity index 100% rename from "09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" rename to "2022/09.12/\354\241\260\354\210\230\354\227\260/\354\234\204\354\236\245.kt" diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" similarity index 96% rename from "09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" rename to "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" index 78348c1..657db5c 100644 --- "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" +++ "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2112_\353\263\264\355\230\270_\355\225\204\353\246\204.java" @@ -1,129 +1,129 @@ -import java.util.*; -import java.io.*; - -// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V1SYKAaUDFAWu - - -// 성능검사를 통과할 수 있는 약품의 최소 투입 횟수이다. 약품을 투입하지 않고도 성능검사를 통과하는 경우에는 0을 출력한다. -// for (int[] arr : tempArr) System.out.println(Arrays.toString(arr)); -public class Main_2112_보호_필름 { - static int D, W, K, result; - static int[][] arr; - static int[] isVisited; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2112.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - st = new StringTokenizer(br.readLine()); - D = Integer.parseInt(st.nextToken()); - W = Integer.parseInt(st.nextToken()); - K = Integer.parseInt(st.nextToken()); - init(); - - for (int i = 0; i < D; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < W; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - } - } - - DFS(0, 0); - sb.append(result).append('\n'); - - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void DFS(int depth, int index) { - - // 약품이 투여되지 않았을 때와 한번이라도 투여됬을 때도 searching시작 하기위해 최소 조건을 줌 - if (depth <= K) { - // 가지치기 조건. - // 지금까지 최소 약품투여횟수와 현재 투여된 약품투여횟수(depth)가 같으면 더 이상 searching할 필요가 없음 - if(depth >= result) { - return; - } - - if (searching()) { - int count = 0; - for (int num : isVisited) { - if (num != 0) { - count++; - } - } - - result = Math.min(result, count); - } - - if (depth == K) { - return; - } - } - - for (int i = index; i < D; i++) { - if (isVisited[i] == 2) continue; - isVisited[i] = 1; // isVisited가 1이면 1로 채우고, 2이면 0으로 채움. - DFS(depth + 1, i + 1); - isVisited[i] = 2; - DFS(depth + 1, i + 1); - isVisited[i] = 0; - } - - } // End of DFS - - private static boolean searching() { - for (int i = 0; i < W; i++) { - boolean check = false; - int zeroCount = 0; - int oneCount = 0; - - for (int j = 0; j < D; j++) { - - if (isVisited[j] == 0) { - if (arr[j][i] == 0) { - zeroCount++; - oneCount = 0; - } else if (arr[j][i] == 1) { - oneCount++; - zeroCount = 0; - } - } else if (isVisited[j] == 1) { - oneCount++; - zeroCount = 0; - } else if (isVisited[j] == 2) { - zeroCount++; - oneCount = 0; - } - - - // 둘 중 하나라도 K를 찍으면 중지. - if (zeroCount == K || oneCount == K) { - check = true; - break; - } - } - - if (!check) { - return false; - } - } - - return true; - } // End of searching - - private static void init() { - arr = new int[D][W]; - isVisited = new int[D]; - result = K+1; - } // End of init -} // End of Main class +import java.util.*; +import java.io.*; + +// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V1SYKAaUDFAWu + + +// 성능검사를 통과할 수 있는 약품의 최소 투입 횟수이다. 약품을 투입하지 않고도 성능검사를 통과하는 경우에는 0을 출력한다. +// for (int[] arr : tempArr) System.out.println(Arrays.toString(arr)); +public class Main_2112_보호_필름 { + static int D, W, K, result; + static int[][] arr; + static int[] isVisited; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2112.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + D = Integer.parseInt(st.nextToken()); + W = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + init(); + + for (int i = 0; i < D; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < W; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + DFS(0, 0); + sb.append(result).append('\n'); + + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int depth, int index) { + + // 약품이 투여되지 않았을 때와 한번이라도 투여됬을 때도 searching시작 하기위해 최소 조건을 줌 + if (depth <= K) { + // 가지치기 조건. + // 지금까지 최소 약품투여횟수와 현재 투여된 약품투여횟수(depth)가 같으면 더 이상 searching할 필요가 없음 + if(depth >= result) { + return; + } + + if (searching()) { + int count = 0; + for (int num : isVisited) { + if (num != 0) { + count++; + } + } + + result = Math.min(result, count); + } + + if (depth == K) { + return; + } + } + + for (int i = index; i < D; i++) { + if (isVisited[i] == 2) continue; + isVisited[i] = 1; // isVisited가 1이면 1로 채우고, 2이면 0으로 채움. + DFS(depth + 1, i + 1); + isVisited[i] = 2; + DFS(depth + 1, i + 1); + isVisited[i] = 0; + } + + } // End of DFS + + private static boolean searching() { + for (int i = 0; i < W; i++) { + boolean check = false; + int zeroCount = 0; + int oneCount = 0; + + for (int j = 0; j < D; j++) { + + if (isVisited[j] == 0) { + if (arr[j][i] == 0) { + zeroCount++; + oneCount = 0; + } else if (arr[j][i] == 1) { + oneCount++; + zeroCount = 0; + } + } else if (isVisited[j] == 1) { + oneCount++; + zeroCount = 0; + } else if (isVisited[j] == 2) { + zeroCount++; + oneCount = 0; + } + + + // 둘 중 하나라도 K를 찍으면 중지. + if (zeroCount == K || oneCount == K) { + check = true; + break; + } + } + + if (!check) { + return false; + } + } + + return true; + } // End of searching + + private static void init() { + arr = new int[D][W]; + isVisited = new int[D]; + result = K+1; + } // End of init +} // End of Main class diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" similarity index 97% rename from "09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" rename to "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" index 9bf41b7..7f7d6bb 100644 --- "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" +++ "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2115_\353\262\214\352\277\200\354\261\204\354\267\250.java" @@ -1,129 +1,129 @@ -import java.util.*; -import java.io.*; - -public class Main_2115_벌꿀채취 { - static int N, M, C, result; - - static int[][] arr; - static boolean[][] isVisited; - static int[] beekeeper; - static int beekeeper1Max; - static Deque deque; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2115.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); // 벌통의 크기 - M = Integer.parseInt(st.nextToken()); // 벌통의 개수 - C = Integer.parseInt(st.nextToken()); // 채취할 수 있는 꿀의 최대양 - init(); - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - } - } - - // 선택된 M개의 벌통에서 값을 조합 - // 조합된 수가 C를 넘지 않도록하기. - // 부분 조합 만들기 <- 완전탐색 - for (int i = 0; i < N; i++) { - for (int j = 0; j <= N - M; j++) { - - // 첫번째 양봉업자 조합 만들기. - int index = 0; - for (int k = j; k < j + M; k++) { - beekeeper[index] = arr[i][k]; - isVisited[i][k] = true; - index++; - } - - // beekeeper1의 조합으로 최댓값을 찾기. - DFS(0, 1, 0); - - // 두번째 양봉 업자 조합 만들기. - madeBekeeper(i); - } - } - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void madeBekeeper(int iIndex) { // 양봉업자1이 만든 벌통을 제외하고 양봉업자 2의 벌통을 만드는 메소드 - for (int i = iIndex; i < N; i++) { - for (int j = 0; j <= N - M; j++) { - // 첫번째 양봉업자가 만든 조합은 지나치도록 isVisited를 사용 - if (isVisited[i][j]) { - continue; - } - - // 두번째 양봉업자 조합 만들기. - int index = 0; - for (int k = j; k < j + M; k++) { - beekeeper[index] = arr[i][k]; - index++; - } - - // 만들어진 벌꿀 통에 대해서 다시 조합을 계산해서 최댓값을 만들기. - DFS(0, 2, 0); - } - } - - } // End of madeBekeeper - - private static void DFS(int depth, int beekeeperNum, int index) { - - if (depth <= M) { - int sum = 0; - int total = 0; - - for (int num : deque) { - sum += num; - total += Math.pow(num, 2); - } - - // 합이 C를 넘으면 안됨. - if (sum <= C) { - if (beekeeperNum == 1) { // 양봉 업자1로 만든 조합에서 최고값을 찾기. - beekeeper1Max = Math.max(beekeeper1Max, total); - } else { // 양봉업자 1이 만든 최고값과 양봉업자2가 만든조합의 합과 최고값 비교. - result = Math.max(beekeeper1Max + total, result); - } - } - - if (depth == M) { - return; - } - } - - // 덱을 사용해서 조합을 만듬. - for (int i = index; i < M; i++) { - deque.offerLast(beekeeper[i]); - DFS(depth + 1, beekeeperNum, i + 1); - deque.pollLast(); - } - } // End of DFS - - private static void init() { - result = Integer.MIN_VALUE; - arr = new int[N][N]; - isVisited = new boolean[N][N]; - beekeeper = new int[M]; - deque = new LinkedList<>(); - beekeeper1Max = Integer.MIN_VALUE; - } // End of init +import java.util.*; +import java.io.*; + +public class Main_2115_벌꿀채취 { + static int N, M, C, result; + + static int[][] arr; + static boolean[][] isVisited; + static int[] beekeeper; + static int beekeeper1Max; + static Deque deque; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2115.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 벌통의 크기 + M = Integer.parseInt(st.nextToken()); // 벌통의 개수 + C = Integer.parseInt(st.nextToken()); // 채취할 수 있는 꿀의 최대양 + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + // 선택된 M개의 벌통에서 값을 조합 + // 조합된 수가 C를 넘지 않도록하기. + // 부분 조합 만들기 <- 완전탐색 + for (int i = 0; i < N; i++) { + for (int j = 0; j <= N - M; j++) { + + // 첫번째 양봉업자 조합 만들기. + int index = 0; + for (int k = j; k < j + M; k++) { + beekeeper[index] = arr[i][k]; + isVisited[i][k] = true; + index++; + } + + // beekeeper1의 조합으로 최댓값을 찾기. + DFS(0, 1, 0); + + // 두번째 양봉 업자 조합 만들기. + madeBekeeper(i); + } + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void madeBekeeper(int iIndex) { // 양봉업자1이 만든 벌통을 제외하고 양봉업자 2의 벌통을 만드는 메소드 + for (int i = iIndex; i < N; i++) { + for (int j = 0; j <= N - M; j++) { + // 첫번째 양봉업자가 만든 조합은 지나치도록 isVisited를 사용 + if (isVisited[i][j]) { + continue; + } + + // 두번째 양봉업자 조합 만들기. + int index = 0; + for (int k = j; k < j + M; k++) { + beekeeper[index] = arr[i][k]; + index++; + } + + // 만들어진 벌꿀 통에 대해서 다시 조합을 계산해서 최댓값을 만들기. + DFS(0, 2, 0); + } + } + + } // End of madeBekeeper + + private static void DFS(int depth, int beekeeperNum, int index) { + + if (depth <= M) { + int sum = 0; + int total = 0; + + for (int num : deque) { + sum += num; + total += Math.pow(num, 2); + } + + // 합이 C를 넘으면 안됨. + if (sum <= C) { + if (beekeeperNum == 1) { // 양봉 업자1로 만든 조합에서 최고값을 찾기. + beekeeper1Max = Math.max(beekeeper1Max, total); + } else { // 양봉업자 1이 만든 최고값과 양봉업자2가 만든조합의 합과 최고값 비교. + result = Math.max(beekeeper1Max + total, result); + } + } + + if (depth == M) { + return; + } + } + + // 덱을 사용해서 조합을 만듬. + for (int i = index; i < M; i++) { + deque.offerLast(beekeeper[i]); + DFS(depth + 1, beekeeperNum, i + 1); + deque.pollLast(); + } + } // End of DFS + + private static void init() { + result = Integer.MIN_VALUE; + arr = new int[N][N]; + isVisited = new boolean[N][N]; + beekeeper = new int[M]; + deque = new LinkedList<>(); + beekeeper1Max = Integer.MIN_VALUE; + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" similarity index 97% rename from "09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" rename to "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" index bc144ba..914f041 100644 --- "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" +++ "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2117_\355\231\210_\353\260\251\353\262\224_\354\204\234\353\271\204\354\212\244.java" @@ -1,117 +1,117 @@ -import java.util.*; -import java.io.*; - -public class Main_2117_홈_방범_서비스 { - static int N, M, maxBenefit, result; - static int[][] arr; - static int[] dirX = {0, 0, -1, 1}; - static int[] dirY = {-1, 1, 0, 0}; - - static class Coordinates { - int x; - int y; - int dist; - - public Coordinates(int x, int y, int dist) { - this.x = x; - this.y = y; - this.dist = dist; - } - } // End of Coordinates class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2117.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); // 집 하나당 지불하는 비용. - init(); - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - } - } - - for (int k = 1; k <= N+1; k++) { // 방범 면적의 크기 증가. - int protectArea = preventionAreaCalc(k); // 방범 면적 계산 - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - BFS(i, j, k, protectArea); - } - } - } - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - // 어차피 K값은 BFS탐색 전에 고정됨. K는 한번만 계산하면 그 값을 활용할 수 있음 - private static void BFS(int x, int y, int distLimit, int protectArea) { - boolean[][] isVisited = new boolean[N][N]; - isVisited[x][y] = true; - int homeCount = 0; - if (arr[x][y] == 1) { - homeCount++; - } - - Queue que = new LinkedList<>(); - que.offer(new Coordinates(x, y, 1)); - - while (!que.isEmpty()) { - Coordinates cor = que.poll(); - - for (int i = 0; i < 4; i++) { - int nowX = cor.x + dirX[i]; - int nowY = cor.y + dirY[i]; - int dist = cor.dist; - - if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && dist < distLimit) { - isVisited[nowX][nowY] = true; - que.offer(new Coordinates(nowX, nowY, dist + 1)); - - if (arr[nowX][nowY] == 1) { - homeCount++; - } - } - } - } - - if (benefitCalc(protectArea, homeCount) >= 0 && maxBenefit <= benefitCalc(protectArea, homeCount)) { - result = Math.max(result, homeCount); - } - - } // End of BFS - - - private static int benefitCalc(int area, int homeCount) { // 이익을 계산하는 메소드 - // 방범 면적 - 집의 개수 * M - return (homeCount * M) - area; - } // End of calc - - private static int preventionAreaCalc(int K) { - return K * K + (K - 1) * (K - 1); - } // End of preventionAreaCalc - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; - } // End of rangeCheck - - private static void init() { - result = Integer.MIN_VALUE; - maxBenefit = Integer.MIN_VALUE; - arr = new int[N][N]; - } // End of init +import java.util.*; +import java.io.*; + +public class Main_2117_홈_방범_서비스 { + static int N, M, maxBenefit, result; + static int[][] arr; + static int[] dirX = {0, 0, -1, 1}; + static int[] dirY = {-1, 1, 0, 0}; + + static class Coordinates { + int x; + int y; + int dist; + + public Coordinates(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + } // End of Coordinates class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2117.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); // 집 하나당 지불하는 비용. + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int k = 1; k <= N+1; k++) { // 방범 면적의 크기 증가. + int protectArea = preventionAreaCalc(k); // 방범 면적 계산 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + BFS(i, j, k, protectArea); + } + } + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + // 어차피 K값은 BFS탐색 전에 고정됨. K는 한번만 계산하면 그 값을 활용할 수 있음 + private static void BFS(int x, int y, int distLimit, int protectArea) { + boolean[][] isVisited = new boolean[N][N]; + isVisited[x][y] = true; + int homeCount = 0; + if (arr[x][y] == 1) { + homeCount++; + } + + Queue que = new LinkedList<>(); + que.offer(new Coordinates(x, y, 1)); + + while (!que.isEmpty()) { + Coordinates cor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = cor.x + dirX[i]; + int nowY = cor.y + dirY[i]; + int dist = cor.dist; + + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && dist < distLimit) { + isVisited[nowX][nowY] = true; + que.offer(new Coordinates(nowX, nowY, dist + 1)); + + if (arr[nowX][nowY] == 1) { + homeCount++; + } + } + } + } + + if (benefitCalc(protectArea, homeCount) >= 0 && maxBenefit <= benefitCalc(protectArea, homeCount)) { + result = Math.max(result, homeCount); + } + + } // End of BFS + + + private static int benefitCalc(int area, int homeCount) { // 이익을 계산하는 메소드 + // 방범 면적 - 집의 개수 * M + return (homeCount * M) - area; + } // End of calc + + private static int preventionAreaCalc(int K) { + return K * K + (K - 1) * (K - 1); + } // End of preventionAreaCalc + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + result = Integer.MIN_VALUE; + maxBenefit = Integer.MIN_VALUE; + arr = new int[N][N]; + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" similarity index 97% rename from "09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" rename to "2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" index d9e2a38..08960a3 100644 --- "a/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" +++ "b/2022/09.12/\354\265\234\354\260\275\354\230\201/Main_2382_\353\257\270\354\203\235\353\254\274_\352\262\251\353\246\254.java" @@ -1,159 +1,159 @@ -import java.util.*; -import java.io.*; - -public class Main_2382_미생물_격리 { - static int N, M, K, result; - static LinkedList list; - - static class Microorganism implements Comparable { - int count; // 미생물 숫자 - int direction; // 이동 방향 - int x; - int y; - - public Microorganism(int x, int y, int count, int direction) { - this.x = x; - this.y = y; - this.count = count; - this.direction = direction; - } - - @Override - public int compareTo(Microorganism o) { - if (this.x == o.x) { - if (this.y == o.y) { - return o.count - this.count; - } - - return this.y - o.y; - } - - return this.x - o.x; - } - } // End of microorganism class - - // 미생물 이동방향 1 : 상 , 2 : 하, 3 : 좌 , 4 : 우 - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2382.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); // 가로 세로 크기 - M = Integer.parseInt(st.nextToken()); // 미생물이 격리되는 시간. - K = Integer.parseInt(st.nextToken()); // 미생물 군집의 숫자 - init(); - - for (int i = 0; i < K; i++) { - st = new StringTokenizer(br.readLine()); - int x = Integer.parseInt(st.nextToken()); - int y = Integer.parseInt(st.nextToken()); - int count = Integer.parseInt(st.nextToken()); - int direction = Integer.parseInt(st.nextToken()); - list.add(new Microorganism(x, y, count, direction)); - } - Collections.sort(list); - - while (M-- > 0) { - int size = list.size(); - for (int i = 0; i < size; i++) { - Microorganism micro = list.get(i); - int x = micro.x; - int y = micro.y; - int count = micro.count; - int direction = micro.direction; - - if (direction == 1) { // 상 - x--; - if (x == 0) { - count = count / 2; - direction = 2; - } - } else if (direction == 2) { // 하 - x++; - if (x == N - 1) { - count = count / 2; - direction = 1; - } - } else if (direction == 3) { // 좌 - y--; - if (y == 0) { - count = count / 2; - direction = 4; - } - } else if (direction == 4) { // 우 - y++; - if (y == N - 1) { - count = count / 2; - direction = 3; - } - } - - list.set(i, new Microorganism(x, y, count, direction)); - } - - // 리스트 정렬, x를 기준으로 정렬, x가 같으면, y값, y도 같으면 count를 기준으로 내림차순 정렬 - Collections.sort(list); - - // 한바퀴를 돌고 난 후 겹치는 값이 있는지 확인. - // x와 y를 기준으로 정렬 후 그래도 값이 같으면 count를 기준으로 정렬. - - List list2 = new LinkedList<>(); - int preX = -1; - int preY = -1; - for (int i = 0; i < list.size(); i++) { - Microorganism micro = list.get(i); - int x = micro.x; - int y = micro.y; - int count = micro.count; - int direction = micro.direction; - if (preX == x && preY == y) continue; - - for (int j = i + 1; j < list.size(); j++) { - Microorganism micro2 = list.get(j); - int x2 = micro2.x; - int y2 = micro2.y; - double count2 = micro2.count; - - if (x != x2) { - break; - } - - if (y == y2) { - count += count2; - } - } - - preX = x; - preY = y; - list2.add(new Microorganism(x, y, count, direction)); - } - - list.clear(); - list.addAll(list2); - } - - // 최종 결과 - for (Microorganism micro : list) { - result += micro.count; - } - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - - private static void init() { - result = 0; - list = new LinkedList<>(); - } // End of init +import java.util.*; +import java.io.*; + +public class Main_2382_미생물_격리 { + static int N, M, K, result; + static LinkedList list; + + static class Microorganism implements Comparable { + int count; // 미생물 숫자 + int direction; // 이동 방향 + int x; + int y; + + public Microorganism(int x, int y, int count, int direction) { + this.x = x; + this.y = y; + this.count = count; + this.direction = direction; + } + + @Override + public int compareTo(Microorganism o) { + if (this.x == o.x) { + if (this.y == o.y) { + return o.count - this.count; + } + + return this.y - o.y; + } + + return this.x - o.x; + } + } // End of microorganism class + + // 미생물 이동방향 1 : 상 , 2 : 하, 3 : 좌 , 4 : 우 + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2382.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 가로 세로 크기 + M = Integer.parseInt(st.nextToken()); // 미생물이 격리되는 시간. + K = Integer.parseInt(st.nextToken()); // 미생물 군집의 숫자 + init(); + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + int count = Integer.parseInt(st.nextToken()); + int direction = Integer.parseInt(st.nextToken()); + list.add(new Microorganism(x, y, count, direction)); + } + Collections.sort(list); + + while (M-- > 0) { + int size = list.size(); + for (int i = 0; i < size; i++) { + Microorganism micro = list.get(i); + int x = micro.x; + int y = micro.y; + int count = micro.count; + int direction = micro.direction; + + if (direction == 1) { // 상 + x--; + if (x == 0) { + count = count / 2; + direction = 2; + } + } else if (direction == 2) { // 하 + x++; + if (x == N - 1) { + count = count / 2; + direction = 1; + } + } else if (direction == 3) { // 좌 + y--; + if (y == 0) { + count = count / 2; + direction = 4; + } + } else if (direction == 4) { // 우 + y++; + if (y == N - 1) { + count = count / 2; + direction = 3; + } + } + + list.set(i, new Microorganism(x, y, count, direction)); + } + + // 리스트 정렬, x를 기준으로 정렬, x가 같으면, y값, y도 같으면 count를 기준으로 내림차순 정렬 + Collections.sort(list); + + // 한바퀴를 돌고 난 후 겹치는 값이 있는지 확인. + // x와 y를 기준으로 정렬 후 그래도 값이 같으면 count를 기준으로 정렬. + + List list2 = new LinkedList<>(); + int preX = -1; + int preY = -1; + for (int i = 0; i < list.size(); i++) { + Microorganism micro = list.get(i); + int x = micro.x; + int y = micro.y; + int count = micro.count; + int direction = micro.direction; + if (preX == x && preY == y) continue; + + for (int j = i + 1; j < list.size(); j++) { + Microorganism micro2 = list.get(j); + int x2 = micro2.x; + int y2 = micro2.y; + double count2 = micro2.count; + + if (x != x2) { + break; + } + + if (y == y2) { + count += count2; + } + } + + preX = x; + preY = y; + list2.add(new Microorganism(x, y, count, direction)); + } + + list.clear(); + list.addAll(list2); + } + + // 최종 결과 + for (Microorganism micro : list) { + result += micro.count; + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + + private static void init() { + result = 0; + list = new LinkedList<>(); + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.12/\355\231\251\354\247\200\354\233\220/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" "b/2022/09.12/\355\231\251\354\247\200\354\233\220/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" similarity index 100% rename from "09.12/\355\231\251\354\247\200\354\233\220/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" rename to "2022/09.12/\355\231\251\354\247\200\354\233\220/\355\231\210\353\260\251\353\262\224\354\204\234\353\271\204\354\212\244.java" diff --git a/09.15/Readme.md b/2022/09.15/Readme.md similarity index 100% rename from 09.15/Readme.md rename to 2022/09.15/Readme.md diff --git "a/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" "b/2022/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" similarity index 100% rename from "09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" rename to "2022/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2383_\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.py" diff --git "a/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" "b/2022/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" similarity index 100% rename from "09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" rename to "2022/09.15/\354\206\241\352\270\260\355\233\210/SWEA_2477_\354\260\250\353\237\211\354\240\225\353\271\204\354\206\214.py" diff --git "a/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" "b/2022/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" similarity index 100% rename from "09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" rename to "2022/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\240\220\354\213\254 \354\213\235\354\202\254\354\213\234\352\260\204.py" diff --git "a/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\260\250\353\237\211 \354\240\225\353\271\204\354\206\214.py" "b/2022/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\260\250\353\237\211 \354\240\225\353\271\204\354\206\214.py" similarity index 100% rename from "09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\260\250\353\237\211 \354\240\225\353\271\204\354\206\214.py" rename to "2022/09.15/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\260\250\353\237\211 \354\240\225\353\271\204\354\206\214.py" diff --git "a/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/2022/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" similarity index 100% rename from "09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" rename to "2022/09.15/\354\240\225\355\230\270\354\241\260/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" diff --git "a/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/2022/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" similarity index 97% rename from "09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" rename to "2022/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" index b8953ed..0d9957b 100644 --- "a/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" +++ "b/2022/09.15/\354\265\234\354\260\275\354\230\201/Main_2383_\354\240\220\354\213\254_\354\213\235\354\202\254\354\213\234\352\260\204.java" @@ -1,188 +1,188 @@ -import java.io.*; -import java.util.*; - -public class Main_2383_점심_식사시간 { - static int N, result; - static int[][] arr; - static int[] ans; - static List personList; - static Stair[] stairArr; - static int finalTime; // 가장 늦게 도착한 사람의 시간. - - static class Person { - int num; - int x; - int y; - int minMin; - - public Person(int num, int x, int y, int minMin) { - this.num = num; - this.x = x; - this.y = y; - this.minMin = minMin; - } - } // End of Person class - - static class Stair { - int x; - int y; - int time; - List waitingList; - - public Stair(int x, int y, int time, List waitingList) { - this.x = x; - this.y = y; - this.time = time; - this.waitingList = waitingList; - } - } // End of Stair class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/2383.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - N = Integer.parseInt(br.readLine()); - init(); - - int stairIndex = 0; - int manCount = 0; - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - if (arr[i][j] == 1) { - personList.add(new Person(manCount, i, j, Integer.MAX_VALUE)); - manCount++; - } else if (arr[i][j] > 1) { - stairArr[stairIndex] = new Stair(i, j, arr[i][j], new LinkedList<>()); - stairIndex++; - } - } - } - - ans = new int[manCount]; - DFS(0, manCount); - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void DFS(int depth, int depthLimit) { - - if (depth == depthLimit) { - int finalTime1 = Integer.MIN_VALUE; - int finalTime2 = Integer.MIN_VALUE; - - for (Stair s : stairArr) { - s.waitingList = new ArrayList<>(); - } - - for (int i = 0; i < depthLimit; i++) { - int stairIndex = ans[i] - 1; - int manNum = i; // 사람 번호 - int distTime = minCalc(personList.get(manNum).x, stairArr[stairIndex].x, personList.get(manNum).y, stairArr[stairIndex].y); - - stairArr[stairIndex].waitingList.add(distTime); - // index에 해당하는 계단으로 이동, - } - - - // 가장 마지막에 빠져나온 사람을 기준으로 result 값을 최솟값으로 갱신 - for (int i = 0; i < 2; i++) { - Stair s = stairArr[i]; - int stairTime = s.time; - - // 대기열이 비었으면 진행 X - if (s.waitingList.isEmpty()) continue; - - // 대기시간 오름차순으로 정렬 - Collections.sort(s.waitingList); - - // 대기열이 3이하까지는 상관없음 - if (s.waitingList.size() <= 3) { - finalTime1 = Math.max(finalTime1, (s.waitingList.get(s.waitingList.size() - 1) + stairTime)); - } else { - Deque deque = new LinkedList<>(); - int time = 0; - - // 먼저 3개를 일단 덱에 탈출시간으로 지정해서 집어넣음. - for (int j = 0; j < 3; j++) { - deque.offerLast(s.waitingList.remove(0) + s.time); - } - - // 조건에 만족해서 탈출할 때 까지 무한반복 - for (; ; ) { - while (!deque.isEmpty() && deque.peekFirst() == time) { - deque.pollFirst(); - } - - if (deque.size() < 3) { - int dif = 3 - deque.size(); - int removeCount = 0; - - for (int j = 0; j < dif; j++) { - if (s.waitingList.isEmpty()) { - break; - } - - if (time < s.waitingList.get(0)) { - break; - } else if (time + s.time == s.waitingList.get(0)) { - deque.offerLast(s.waitingList.get(0) + s.time); - removeCount++; - } else if (time + s.time > s.waitingList.get(0)) { - deque.offerLast(time + s.time); - removeCount++; - } - - s.waitingList.remove(0); - } - } - - if (deque.size() <= 3 && s.waitingList.isEmpty()) { - time = deque.pollLast(); - break; - } - - time++; - } - - finalTime2 = Math.max(finalTime2, time); - } // End of else of if - } // End of for(i); - - // 모든 값이 계산되고 나면 종료 - finalTime = Math.max(finalTime1, finalTime2); - result = Math.min(finalTime, result); - return; - } - - for (int i = 1; i <= 2; i++) { - ans[depth] = i; - DFS(depth + 1, depthLimit); - } - } // End of DFS - - private static int minCalc(int pr, int sr, int pc, int sc) { - int time = Math.abs(pr - sr) + Math.abs(pc - sc); - return time + 1; // 계단을 내려가는 시간이 기준이므로 + 1을 해줌. - } // End of minCalc - - private static void init() { - result = Integer.MAX_VALUE; - arr = new int[N][N]; - stairArr = new Stair[2]; - personList = new ArrayList<>(); - finalTime = Integer.MIN_VALUE; - } // End of init +import java.io.*; +import java.util.*; + +public class Main_2383_점심_식사시간 { + static int N, result; + static int[][] arr; + static int[] ans; + static List personList; + static Stair[] stairArr; + static int finalTime; // 가장 늦게 도착한 사람의 시간. + + static class Person { + int num; + int x; + int y; + int minMin; + + public Person(int num, int x, int y, int minMin) { + this.num = num; + this.x = x; + this.y = y; + this.minMin = minMin; + } + } // End of Person class + + static class Stair { + int x; + int y; + int time; + List waitingList; + + public Stair(int x, int y, int time, List waitingList) { + this.x = x; + this.y = y; + this.time = time; + this.waitingList = waitingList; + } + } // End of Stair class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/2383.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); + + int stairIndex = 0; + int manCount = 0; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + if (arr[i][j] == 1) { + personList.add(new Person(manCount, i, j, Integer.MAX_VALUE)); + manCount++; + } else if (arr[i][j] > 1) { + stairArr[stairIndex] = new Stair(i, j, arr[i][j], new LinkedList<>()); + stairIndex++; + } + } + } + + ans = new int[manCount]; + DFS(0, manCount); + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int depth, int depthLimit) { + + if (depth == depthLimit) { + int finalTime1 = Integer.MIN_VALUE; + int finalTime2 = Integer.MIN_VALUE; + + for (Stair s : stairArr) { + s.waitingList = new ArrayList<>(); + } + + for (int i = 0; i < depthLimit; i++) { + int stairIndex = ans[i] - 1; + int manNum = i; // 사람 번호 + int distTime = minCalc(personList.get(manNum).x, stairArr[stairIndex].x, personList.get(manNum).y, stairArr[stairIndex].y); + + stairArr[stairIndex].waitingList.add(distTime); + // index에 해당하는 계단으로 이동, + } + + + // 가장 마지막에 빠져나온 사람을 기준으로 result 값을 최솟값으로 갱신 + for (int i = 0; i < 2; i++) { + Stair s = stairArr[i]; + int stairTime = s.time; + + // 대기열이 비었으면 진행 X + if (s.waitingList.isEmpty()) continue; + + // 대기시간 오름차순으로 정렬 + Collections.sort(s.waitingList); + + // 대기열이 3이하까지는 상관없음 + if (s.waitingList.size() <= 3) { + finalTime1 = Math.max(finalTime1, (s.waitingList.get(s.waitingList.size() - 1) + stairTime)); + } else { + Deque deque = new LinkedList<>(); + int time = 0; + + // 먼저 3개를 일단 덱에 탈출시간으로 지정해서 집어넣음. + for (int j = 0; j < 3; j++) { + deque.offerLast(s.waitingList.remove(0) + s.time); + } + + // 조건에 만족해서 탈출할 때 까지 무한반복 + for (; ; ) { + while (!deque.isEmpty() && deque.peekFirst() == time) { + deque.pollFirst(); + } + + if (deque.size() < 3) { + int dif = 3 - deque.size(); + int removeCount = 0; + + for (int j = 0; j < dif; j++) { + if (s.waitingList.isEmpty()) { + break; + } + + if (time < s.waitingList.get(0)) { + break; + } else if (time + s.time == s.waitingList.get(0)) { + deque.offerLast(s.waitingList.get(0) + s.time); + removeCount++; + } else if (time + s.time > s.waitingList.get(0)) { + deque.offerLast(time + s.time); + removeCount++; + } + + s.waitingList.remove(0); + } + } + + if (deque.size() <= 3 && s.waitingList.isEmpty()) { + time = deque.pollLast(); + break; + } + + time++; + } + + finalTime2 = Math.max(finalTime2, time); + } // End of else of if + } // End of for(i); + + // 모든 값이 계산되고 나면 종료 + finalTime = Math.max(finalTime1, finalTime2); + result = Math.min(finalTime, result); + return; + } + + for (int i = 1; i <= 2; i++) { + ans[depth] = i; + DFS(depth + 1, depthLimit); + } + } // End of DFS + + private static int minCalc(int pr, int sr, int pc, int sc) { + int time = Math.abs(pr - sr) + Math.abs(pc - sc); + return time + 1; // 계단을 내려가는 시간이 기준이므로 + 1을 해줌. + } // End of minCalc + + private static void init() { + result = Integer.MAX_VALUE; + arr = new int[N][N]; + stairArr = new Stair[2]; + personList = new ArrayList<>(); + finalTime = Integer.MIN_VALUE; + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.cpp" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.cpp" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/JadenCase \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.kt" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/README.md" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\221\220 \355\201\220 \355\225\251 \352\260\231\352\262\214 \353\247\214\353\223\244\352\270\260.kt" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\210\354\203\201 \353\214\200\354\247\204\355\221\234.kt" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\235\264\354\247\204 \353\263\200\355\231\230 \353\260\230\353\263\265\355\225\230\352\270\260.kt" diff --git "a/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" "b/2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" similarity index 100% rename from "09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" rename to "2022/09.15/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\226\211\353\240\254\354\235\230 \352\263\261\354\205\210.kt" diff --git "a/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" "b/2022/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" similarity index 100% rename from "09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" rename to "2022/09.15/\355\231\251\354\247\200\354\233\220/\354\240\220\354\213\254\354\213\235\354\202\254\354\213\234\352\260\204.java" diff --git a/09.19/Readme.md b/2022/09.19/Readme.md similarity index 100% rename from 09.19/Readme.md rename to 2022/09.19/Readme.md diff --git "a/09.19/\352\266\214\354\243\274\355\230\204/swea4012.java" "b/2022/09.19/\352\266\214\354\243\274\355\230\204/swea4012.java" similarity index 100% rename from "09.19/\352\266\214\354\243\274\355\230\204/swea4012.java" rename to "2022/09.19/\352\266\214\354\243\274\355\230\204/swea4012.java" diff --git "a/09.19/\352\266\214\354\243\274\355\230\204/swea4013.java" "b/2022/09.19/\352\266\214\354\243\274\355\230\204/swea4013.java" similarity index 100% rename from "09.19/\352\266\214\354\243\274\355\230\204/swea4013.java" rename to "2022/09.19/\352\266\214\354\243\274\355\230\204/swea4013.java" diff --git "a/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4012_\354\232\224\353\246\254\354\202\254.py" "b/2022/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4012_\354\232\224\353\246\254\354\202\254.py" similarity index 100% rename from "09.19/\354\206\241\352\270\260\355\233\210/SWEA_4012_\354\232\224\353\246\254\354\202\254.py" rename to "2022/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4012_\354\232\224\353\246\254\354\202\254.py" diff --git "a/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4013_\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.py" "b/2022/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4013_\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.py" similarity index 100% rename from "09.19/\354\206\241\352\270\260\355\233\210/SWEA_4013_\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.py" rename to "2022/09.19/\354\206\241\352\270\260\355\233\210/SWEA_4013_\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.py" diff --git "a/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230 SW \354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\232\224\353\246\254\354\202\254.py" "b/2022/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230 SW \354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\232\224\353\246\254\354\202\254.py" similarity index 100% rename from "09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230 SW \354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\232\224\353\246\254\354\202\254.py" rename to "2022/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230 SW \354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\232\224\353\246\254\354\202\254.py" diff --git "a/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\212\271\354\235\264\355\225\234 \354\236\220\354\204\235.py" "b/2022/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\212\271\354\235\264\355\225\234 \354\236\220\354\204\235.py" similarity index 100% rename from "09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\212\271\354\235\264\355\225\234 \354\236\220\354\204\235.py" rename to "2022/09.19/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\212\271\354\235\264\355\225\234 \354\236\220\354\204\235.py" diff --git "a/09.19/\354\240\225\355\230\270\354\241\260/\354\232\224\353\246\254\354\202\254.java" "b/2022/09.19/\354\240\225\355\230\270\354\241\260/\354\232\224\353\246\254\354\202\254.java" similarity index 100% rename from "09.19/\354\240\225\355\230\270\354\241\260/\354\232\224\353\246\254\354\202\254.java" rename to "2022/09.19/\354\240\225\355\230\270\354\241\260/\354\232\224\353\246\254\354\202\254.java" diff --git "a/09.19/\354\240\225\355\230\270\354\241\260/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" "b/2022/09.19/\354\240\225\355\230\270\354\241\260/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" similarity index 100% rename from "09.19/\354\240\225\355\230\270\354\241\260/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" rename to "2022/09.19/\354\240\225\355\230\270\354\241\260/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" diff --git "a/09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" "b/2022/09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" similarity index 96% rename from "09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" rename to "2022/09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" index 9b13c7b..c47d16b 100644 --- "a/09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" +++ "b/2022/09.19/\354\265\234\354\260\275\354\230\201/Main_4012_\354\232\224\353\246\254\354\202\254.java" @@ -1,75 +1,75 @@ -import java.util.*; -import java.io.*; - -public class Main_4012_요리사 { - static int N, result; - static int[][] arr; - static int[] idxArr; - static int[] comb; - static int[] comb2; - static boolean[] isVisited; - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/4012.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - N = Integer.parseInt(br.readLine()); - init(); - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - idxArr[i] = i; - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - } - } - - DFS(0, 0); - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void DFS(int depth, int index) { - if (depth == N / 2) { - int sum = 0; - int sum2 = 0; - for (int i = 0; i < N; i++) { - for (int j = i + 1; j < N; j++) { - if (isVisited[i] && isVisited[j]) { - sum += arr[i][j] + arr[j][i]; - } else if(!isVisited[i] && !isVisited[j]){ - sum2 += arr[i][j] + arr[j][i]; - } - } - } - - result = Math.min(result, Math.abs(sum - sum2)); - return; - } - - for (int i = index; i < N; i++) { - isVisited[i] = true; - DFS(depth + 1, i + 1); - isVisited[i] = false; - } - } // End of DFS - - private static void init() { - result = Integer.MAX_VALUE; - arr = new int[N][N]; - idxArr = new int[N]; - isVisited = new boolean[N]; - comb = new int[N / 2]; - comb2 = new int[N / 2]; - } // End of init +import java.util.*; +import java.io.*; + +public class Main_4012_요리사 { + static int N, result; + static int[][] arr; + static int[] idxArr; + static int[] comb; + static int[] comb2; + static boolean[] isVisited; + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/4012.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + idxArr[i] = i; + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + DFS(0, 0); + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int depth, int index) { + if (depth == N / 2) { + int sum = 0; + int sum2 = 0; + for (int i = 0; i < N; i++) { + for (int j = i + 1; j < N; j++) { + if (isVisited[i] && isVisited[j]) { + sum += arr[i][j] + arr[j][i]; + } else if(!isVisited[i] && !isVisited[j]){ + sum2 += arr[i][j] + arr[j][i]; + } + } + } + + result = Math.min(result, Math.abs(sum - sum2)); + return; + } + + for (int i = index; i < N; i++) { + isVisited[i] = true; + DFS(depth + 1, i + 1); + isVisited[i] = false; + } + } // End of DFS + + private static void init() { + result = Integer.MAX_VALUE; + arr = new int[N][N]; + idxArr = new int[N]; + isVisited = new boolean[N]; + comb = new int[N / 2]; + comb2 = new int[N / 2]; + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/N-Queen.cpp" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230\352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.cpp" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230\352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.cpp" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230\352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.cpp" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230\352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.cpp" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.cpp" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.cpp" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.cpp" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.cpp" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/N-Queen.kt" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/N-Queen.kt" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/N-Queen.kt" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/N-Queen.kt" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230 \352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.kt" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230 \352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.kt" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230 \352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.kt" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/k\354\247\204\354\210\230\354\227\220\354\204\234 \354\206\214\354\210\230 \352\260\234\354\210\230 \352\265\254\355\225\230\352\270\260.kt" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/n^2 \353\260\260\354\227\264 \354\236\220\353\245\264\352\270\260.kt" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/n^2 \353\260\260\354\227\264 \354\236\220\353\245\264\352\270\260.kt" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/n^2 \353\260\260\354\227\264 \354\236\220\353\245\264\352\270\260.kt" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/n^2 \353\260\260\354\227\264 \354\236\220\353\245\264\352\270\260.kt" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" diff --git "a/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.kt" "b/2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.kt" similarity index 100% rename from "09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.kt" rename to "2022/09.19/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\225\230\353\205\270\354\235\264\354\235\230 \355\203\221.kt" diff --git "a/09.19/\355\231\251\354\247\200\354\233\220/\354\232\224\353\246\254\354\202\254.java" "b/2022/09.19/\355\231\251\354\247\200\354\233\220/\354\232\224\353\246\254\354\202\254.java" similarity index 100% rename from "09.19/\355\231\251\354\247\200\354\233\220/\354\232\224\353\246\254\354\202\254.java" rename to "2022/09.19/\355\231\251\354\247\200\354\233\220/\354\232\224\353\246\254\354\202\254.java" diff --git "a/09.19/\355\231\251\354\247\200\354\233\220/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" "b/2022/09.19/\355\231\251\354\247\200\354\233\220/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" similarity index 100% rename from "09.19/\355\231\251\354\247\200\354\233\220/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" rename to "2022/09.19/\355\231\251\354\247\200\354\233\220/\355\212\271\354\235\264\355\225\234\354\236\220\354\204\235.java" diff --git a/09.22/readme.md b/2022/09.22/readme.md similarity index 100% rename from 09.22/readme.md rename to 2022/09.22/readme.md diff --git "a/09.22/\352\266\214\354\243\274\355\230\204/\355\225\200\353\263\274\352\262\214\354\236\204.java" "b/2022/09.22/\352\266\214\354\243\274\355\230\204/\355\225\200\353\263\274\352\262\214\354\236\204.java" similarity index 100% rename from "09.22/\352\266\214\354\243\274\355\230\204/\355\225\200\353\263\274\352\262\214\354\236\204.java" rename to "2022/09.22/\352\266\214\354\243\274\355\230\204/\355\225\200\353\263\274\352\262\214\354\236\204.java" diff --git "a/09.22/\354\206\241\352\270\260\355\233\210/SWEA_5650_\355\225\200\353\263\274\352\262\214\354\236\204.py" "b/2022/09.22/\354\206\241\352\270\260\355\233\210/SWEA_5650_\355\225\200\353\263\274\352\262\214\354\236\204.py" similarity index 100% rename from "09.22/\354\206\241\352\270\260\355\233\210/SWEA_5650_\355\225\200\353\263\274\352\262\214\354\236\204.py" rename to "2022/09.22/\354\206\241\352\270\260\355\233\210/SWEA_5650_\355\225\200\353\263\274\352\262\214\354\236\204.py" diff --git "a/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\233\220\354\236\220 \354\206\214\353\251\270 \354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.py" "b/2022/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\233\220\354\236\220 \354\206\214\353\251\270 \354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.py" similarity index 100% rename from "09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\233\220\354\236\220 \354\206\214\353\251\270 \354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.py" rename to "2022/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\354\233\220\354\236\220 \354\206\214\353\251\270 \354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.py" diff --git "a/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\225\200\353\263\274 \352\262\214\354\236\204.py" "b/2022/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\225\200\353\263\274 \352\262\214\354\236\204.py" similarity index 100% rename from "09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\225\200\353\263\274 \352\262\214\354\236\204.py" rename to "2022/09.22/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\355\225\200\353\263\274 \352\262\214\354\236\204.py" diff --git "a/09.22/\354\240\225\355\230\270\354\241\260/\354\233\220\354\236\220\354\206\214\353\251\270\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.java" "b/2022/09.22/\354\240\225\355\230\270\354\241\260/\354\233\220\354\236\220\354\206\214\353\251\270\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.java" similarity index 100% rename from "09.22/\354\240\225\355\230\270\354\241\260/\354\233\220\354\236\220\354\206\214\353\251\270\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.java" rename to "2022/09.22/\354\240\225\355\230\270\354\241\260/\354\233\220\354\236\220\354\206\214\353\251\270\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230.java" diff --git "a/09.22/\354\240\225\355\230\270\354\241\260/\355\225\200\353\263\274\352\262\214\354\236\204.java" "b/2022/09.22/\354\240\225\355\230\270\354\241\260/\355\225\200\353\263\274\352\262\214\354\236\204.java" similarity index 100% rename from "09.22/\354\240\225\355\230\270\354\241\260/\355\225\200\353\263\274\352\262\214\354\236\204.java" rename to "2022/09.22/\354\240\225\355\230\270\354\241\260/\355\225\200\353\263\274\352\262\214\354\236\204.java" diff --git "a/09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" "b/2022/09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" similarity index 97% rename from "09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" rename to "2022/09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" index 9b15905..55e6189 100644 --- "a/09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" +++ "b/2022/09.22/\354\265\234\354\260\275\354\230\201/Main_5650_\355\225\200\353\263\274_\352\262\214\354\236\204.java" @@ -1,206 +1,206 @@ -import java.util.*; -import java.io.*; - -// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRF8s6ezEDFAUo -// -1 : 블랙홀, 0 : 빈공간, 1 ~ 5 : 블록, 6 ~ 10 : 웜홀 -// 게임에서 얻을 수 있는 최댓값을 구하라. -// 블록, 웜홀, 블랙홀 위치에서는 출발 할 수 없다. -// 점수는 벽에 부딪힌 횟수가 된다. -// 게임은 핀볼이 출발위치로 돌아오거나, 블랙홀에 빠질 때 끝나게 된다. - -// 웜홀에 빠지게 되면, 동일한 숫자를 가진 반대편 웜홀로 나오게 되며 진행방향은 그대로 유지된다. -// 5번은 무조건 뒤로 돌아감 - -public class Main_5650_핀볼_게임 { - static int N, result; - static int[][] map; - static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 - static int[] dirY = {0, 0, -1, 1}; - - static class Coordinates { - int x; - int y; - - public Coordinates(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Coordinates - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/5650.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - N = Integer.parseInt(br.readLine()); - init(); - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - } - } - - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - - // 돌아온다는 것을 감안했을 때, isVisited는 없어도 될 것 같음 - if (map[i][j] == 0) { - for (int k = 0; k < 4; k++) { - DFS(i, j, i, j, k); - } - } - } - } - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void DFS(int startX, int startY, int x, int y, int direction) { - int hitCount = 0; - int nowX = x; - int nowY = y; - - for (; ; ) { - nowX = dirX[direction] + nowX; - nowY = dirY[direction] + nowY; - - // 범위를 벗어나면 벽에 부딪혔기 때문에 방향을 반대로 전환 - if (!rangeCheck(nowX, nowY)) { - // 틀린 코드여서 주석 처리 - //nowX = nowX - dirX[direction]; - //nowY = nowY - dirY[direction]; - direction = backDirection(direction); - // 방향만 바꿔주고 다음턴에서 다시 움직임 - hitCount++; - - } else { - if (map[nowX][nowY] == 0 && nowX == startX && nowY == startY) { - result = Math.max(result, hitCount); - return; - } else if (map[nowX][nowY] == 1) { - if (direction == 0) { - // 상 -> 하 - direction = backDirection(direction); - } else if (direction == 1) { - // 하 -> 우 - direction = 3; - } else if (direction == 2) { - // 좌 -> 상 - direction = 0; - } else { - // 우 -> 좌 - direction = backDirection(direction); - } - - hitCount++; - } else if (map[nowX][nowY] == 2) { - if (direction == 0) { - // 상 -> 우 - direction = 3; - } else if (direction == 1) { - // 하 -> 상 - direction = backDirection(direction); - } else if (direction == 2) { - // 좌 -> 하 - direction = 1; - } else { - // 우 -> 좌 - direction = backDirection(direction); - } - - hitCount++; - } else if (map[nowX][nowY] == 3) { - if (direction == 0) { - // 상 -> 좌 - direction = 2; - } else if (direction == 1) { - // 하 -> 상 - direction = backDirection(direction); - } else if (direction == 2) { - // 좌 -> 우 - direction = backDirection(direction); - } else { - // 우 -> 하 - direction = 1; - } - - hitCount++; - } else if (map[nowX][nowY] == 4) { - if (direction == 0) { - // 상 -> 하 - direction = backDirection(direction); - } else if (direction == 1) { - // 하 -> 좌 - direction = 2; - } else if (direction == 2) { - // 좌 -> 우 - direction = backDirection(direction); - } else { - // 우 -> 상 - direction = 0; - } - - hitCount++; - } else if (map[nowX][nowY] == 5) { - direction = backDirection(direction); - hitCount++; - } else if (map[nowX][nowY] == -1) { - result = Math.max(result, hitCount); - return; - } else if (map[nowX][nowY] >= 6 && map[nowX][nowY] <= 10) { - // System.out.println(map[nowX][nowY]); - Coordinates wormCoor = findWormhole(map[nowX][nowY], nowX, nowY); - nowX = wormCoor.x; - nowY = wormCoor.y; - } - } - } - - } // End of DFS - - private static int backDirection(int dir) { - if (dir == 0) { - return 1; - } else if (dir == 1) { - return 0; - } else if (dir == 2) { - return 3; - } else { - return 2; - } - } // End of backDirection - - private static Coordinates findWormhole(int holeNum, int nowX, int nowY) { - - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - if (map[i][j] == holeNum && (nowX != i || nowY != j)) { - return new Coordinates(i, j); - } - } - } - - return null; - } // End of findWormhole - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; - } // End of rangeCheck - - private static void init() { - map = new int[N][N]; - result = -1; - } // End of init +import java.util.*; +import java.io.*; + +// https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRF8s6ezEDFAUo +// -1 : 블랙홀, 0 : 빈공간, 1 ~ 5 : 블록, 6 ~ 10 : 웜홀 +// 게임에서 얻을 수 있는 최댓값을 구하라. +// 블록, 웜홀, 블랙홀 위치에서는 출발 할 수 없다. +// 점수는 벽에 부딪힌 횟수가 된다. +// 게임은 핀볼이 출발위치로 돌아오거나, 블랙홀에 빠질 때 끝나게 된다. + +// 웜홀에 빠지게 되면, 동일한 숫자를 가진 반대편 웜홀로 나오게 되며 진행방향은 그대로 유지된다. +// 5번은 무조건 뒤로 돌아감 + +public class Main_5650_핀볼_게임 { + static int N, result; + static int[][] map; + static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 + static int[] dirY = {0, 0, -1, 1}; + + static class Coordinates { + int x; + int y; + + public Coordinates(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Coordinates + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/5650.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + N = Integer.parseInt(br.readLine()); + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + + // 돌아온다는 것을 감안했을 때, isVisited는 없어도 될 것 같음 + if (map[i][j] == 0) { + for (int k = 0; k < 4; k++) { + DFS(i, j, i, j, k); + } + } + } + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void DFS(int startX, int startY, int x, int y, int direction) { + int hitCount = 0; + int nowX = x; + int nowY = y; + + for (; ; ) { + nowX = dirX[direction] + nowX; + nowY = dirY[direction] + nowY; + + // 범위를 벗어나면 벽에 부딪혔기 때문에 방향을 반대로 전환 + if (!rangeCheck(nowX, nowY)) { + // 틀린 코드여서 주석 처리 + //nowX = nowX - dirX[direction]; + //nowY = nowY - dirY[direction]; + direction = backDirection(direction); + // 방향만 바꿔주고 다음턴에서 다시 움직임 + hitCount++; + + } else { + if (map[nowX][nowY] == 0 && nowX == startX && nowY == startY) { + result = Math.max(result, hitCount); + return; + } else if (map[nowX][nowY] == 1) { + if (direction == 0) { + // 상 -> 하 + direction = backDirection(direction); + } else if (direction == 1) { + // 하 -> 우 + direction = 3; + } else if (direction == 2) { + // 좌 -> 상 + direction = 0; + } else { + // 우 -> 좌 + direction = backDirection(direction); + } + + hitCount++; + } else if (map[nowX][nowY] == 2) { + if (direction == 0) { + // 상 -> 우 + direction = 3; + } else if (direction == 1) { + // 하 -> 상 + direction = backDirection(direction); + } else if (direction == 2) { + // 좌 -> 하 + direction = 1; + } else { + // 우 -> 좌 + direction = backDirection(direction); + } + + hitCount++; + } else if (map[nowX][nowY] == 3) { + if (direction == 0) { + // 상 -> 좌 + direction = 2; + } else if (direction == 1) { + // 하 -> 상 + direction = backDirection(direction); + } else if (direction == 2) { + // 좌 -> 우 + direction = backDirection(direction); + } else { + // 우 -> 하 + direction = 1; + } + + hitCount++; + } else if (map[nowX][nowY] == 4) { + if (direction == 0) { + // 상 -> 하 + direction = backDirection(direction); + } else if (direction == 1) { + // 하 -> 좌 + direction = 2; + } else if (direction == 2) { + // 좌 -> 우 + direction = backDirection(direction); + } else { + // 우 -> 상 + direction = 0; + } + + hitCount++; + } else if (map[nowX][nowY] == 5) { + direction = backDirection(direction); + hitCount++; + } else if (map[nowX][nowY] == -1) { + result = Math.max(result, hitCount); + return; + } else if (map[nowX][nowY] >= 6 && map[nowX][nowY] <= 10) { + // System.out.println(map[nowX][nowY]); + Coordinates wormCoor = findWormhole(map[nowX][nowY], nowX, nowY); + nowX = wormCoor.x; + nowY = wormCoor.y; + } + } + } + + } // End of DFS + + private static int backDirection(int dir) { + if (dir == 0) { + return 1; + } else if (dir == 1) { + return 0; + } else if (dir == 2) { + return 3; + } else { + return 2; + } + } // End of backDirection + + private static Coordinates findWormhole(int holeNum, int nowX, int nowY) { + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (map[i][j] == holeNum && (nowX != i || nowY != j)) { + return new Coordinates(i, j); + } + } + } + + return null; + } // End of findWormhole + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + map = new int[N][N]; + result = -1; + } // End of init } // End of Main class \ No newline at end of file diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.cpp" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.cpp" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.cpp" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.cpp" diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.cpp" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.cpp" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.cpp" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\243\274\354\260\250\354\232\224\352\270\210\352\263\204\354\202\260.cpp" diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.kt" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.kt" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.kt" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.kt" diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.kt" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.kt" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.kt" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.kt" diff --git "a/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.kt" "b/2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.kt" similarity index 100% rename from "09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.kt" rename to "2022/09.22/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\243\274\354\260\250 \354\232\224\352\270\210 \352\263\204\354\202\260.kt" diff --git a/09.26/readme.md b/2022/09.26/readme.md similarity index 100% rename from 09.26/readme.md rename to 2022/09.26/readme.md diff --git "a/09.26/\352\266\214\354\243\274\355\230\204/\353\262\275\353\217\214\352\271\250\352\270\260.java" "b/2022/09.26/\352\266\214\354\243\274\355\230\204/\353\262\275\353\217\214\352\271\250\352\270\260.java" similarity index 100% rename from "09.26/\352\266\214\354\243\274\355\230\204/\353\262\275\353\217\214\352\271\250\352\270\260.java" rename to "2022/09.26/\352\266\214\354\243\274\355\230\204/\353\262\275\353\217\214\352\271\250\352\270\260.java" diff --git "a/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5653_\354\244\204\352\270\260\354\204\270\355\217\254\353\260\260\354\226\221.py" "b/2022/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5653_\354\244\204\352\270\260\354\204\270\355\217\254\353\260\260\354\226\221.py" similarity index 100% rename from "09.26/\354\206\241\352\270\260\355\233\210/SWEA_5653_\354\244\204\352\270\260\354\204\270\355\217\254\353\260\260\354\226\221.py" rename to "2022/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5653_\354\244\204\352\270\260\354\204\270\355\217\254\353\260\260\354\226\221.py" diff --git "a/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5656_\353\262\275\353\217\214\352\271\250\352\270\260.py" "b/2022/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5656_\353\262\275\353\217\214\352\271\250\352\270\260.py" similarity index 100% rename from "09.26/\354\206\241\352\270\260\355\233\210/SWEA_5656_\353\262\275\353\217\214\352\271\250\352\270\260.py" rename to "2022/09.26/\354\206\241\352\270\260\355\233\210/SWEA_5656_\353\262\275\353\217\214\352\271\250\352\270\260.py" diff --git "a/09.26/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\275\353\217\214\352\271\250\352\270\260.py" "b/2022/09.26/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\275\353\217\214\352\271\250\352\270\260.py" similarity index 100% rename from "09.26/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\275\353\217\214\352\271\250\352\270\260.py" rename to "2022/09.26/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\262\275\353\217\214\352\271\250\352\270\260.py" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/2\352\260\234\354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.cpp" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/2\352\260\234\354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.cpp" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/2\352\260\234\354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.cpp" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/2\352\260\234\354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.cpp" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\206\214\354\210\230\354\260\276\352\270\260.cpp" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\206\214\354\210\230\354\260\276\352\270\260.cpp" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\206\214\354\210\230\354\260\276\352\270\260.cpp" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\206\214\354\210\230\354\260\276\352\270\260.cpp" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\277\274\353\223\234\354\225\225\354\266\225\355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.cpp" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\277\274\353\223\234\354\225\225\354\266\225\355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.cpp" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\277\274\353\223\234\354\225\225\354\266\225\355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.cpp" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\277\274\353\223\234\354\225\225\354\266\225\355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.cpp" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/2\352\260\234 \354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.kt" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/2\352\260\234 \354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.kt" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/2\352\260\234 \354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.kt" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/2\352\260\234 \354\235\264\355\225\230\353\241\234 \353\213\244\353\245\270 \353\271\204\355\212\270.kt" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\206\214\354\210\230 \354\260\276\352\270\260.kt" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\206\214\354\210\230 \354\260\276\352\270\260.kt" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\206\214\354\210\230 \354\260\276\352\270\260.kt" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\206\214\354\210\230 \354\260\276\352\270\260.kt" diff --git "a/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\277\274\353\223\234\354\225\225\354\266\225 \355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.kt" "b/2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\277\274\353\223\234\354\225\225\354\266\225 \355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.kt" similarity index 100% rename from "09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\277\274\353\223\234\354\225\225\354\266\225 \355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.kt" rename to "2022/09.26/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\277\274\353\223\234\354\225\225\354\266\225 \355\233\204 \352\260\234\354\210\230 \354\204\270\352\270\260.kt" diff --git a/10.03/readme.md b/2022/10.03/readme.md similarity index 100% rename from 10.03/readme.md rename to 2022/10.03/readme.md diff --git "a/10.03/\354\206\241\352\270\260\355\233\210/SWEA_5658_\353\263\264\353\254\274\354\203\201\354\236\220\353\271\204\353\260\200\353\262\210\355\230\270.py" "b/2022/10.03/\354\206\241\352\270\260\355\233\210/SWEA_5658_\353\263\264\353\254\274\354\203\201\354\236\220\353\271\204\353\260\200\353\262\210\355\230\270.py" similarity index 100% rename from "10.03/\354\206\241\352\270\260\355\233\210/SWEA_5658_\353\263\264\353\254\274\354\203\201\354\236\220\353\271\204\353\260\200\353\262\210\355\230\270.py" rename to "2022/10.03/\354\206\241\352\270\260\355\233\210/SWEA_5658_\353\263\264\353\254\274\354\203\201\354\236\220\353\271\204\353\260\200\353\262\210\355\230\270.py" diff --git "a/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264.py" "b/2022/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264.py" similarity index 100% rename from "10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264.py" rename to "2022/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_16236_\354\225\204\352\270\260\354\203\201\354\226\264.py" diff --git "a/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_21608_\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.py" "b/2022/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_21608_\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.py" similarity index 100% rename from "10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_21608_\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.py" rename to "2022/10.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_21608_\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.py" diff --git "a/10.03/\354\235\264\354\247\200\354\234\244/README.md" "b/2022/10.03/\354\235\264\354\247\200\354\234\244/README.md" similarity index 100% rename from "10.03/\354\235\264\354\247\200\354\234\244/README.md" rename to "2022/10.03/\354\235\264\354\247\200\354\234\244/README.md" diff --git "a/10.03/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\263\264\353\254\274\354\203\201\354\236\220 \353\271\204\353\260\200\353\262\210\355\230\270.py" "b/2022/10.03/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\263\264\353\254\274\354\203\201\354\236\220 \353\271\204\353\260\200\353\262\210\355\230\270.py" similarity index 100% rename from "10.03/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\263\264\353\254\274\354\203\201\354\236\220 \353\271\204\353\260\200\353\262\210\355\230\270.py" rename to "2022/10.03/\354\235\264\354\247\200\354\234\244/[\353\252\250\354\235\230SW\354\227\255\353\237\211\355\205\214\354\212\244\355\212\270]\353\263\264\353\254\274\354\203\201\354\236\220 \353\271\204\353\260\200\353\262\210\355\230\270.py" diff --git "a/10.03/\354\235\264\354\247\200\354\234\244/\354\225\204\352\270\260\354\203\201\354\226\264.py" "b/2022/10.03/\354\235\264\354\247\200\354\234\244/\354\225\204\352\270\260\354\203\201\354\226\264.py" similarity index 100% rename from "10.03/\354\235\264\354\247\200\354\234\244/\354\225\204\352\270\260\354\203\201\354\226\264.py" rename to "2022/10.03/\354\235\264\354\247\200\354\234\244/\354\225\204\352\270\260\354\203\201\354\226\264.py" diff --git "a/10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" "b/2022/10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" similarity index 97% rename from "10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" rename to "2022/10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" index 13d8c0e..7697087 100644 --- "a/10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" +++ "b/2022/10.03/\354\265\234\354\260\275\354\230\201/Main_16236_\354\225\204\352\270\260_\354\203\201\354\226\264.java" @@ -1,134 +1,134 @@ -import java.util.*; -import java.io.*; - -// 아기 상어가 도움을 요청하지 않고 물고기를 잡아먹을 수 있는 시간을 출력한다. -// 아기상어는 자신보다 작은 물고기만 먹을 수 있다. -// 자신보다 큰 물고기가 있는 칸은 지나갈 수 없다. -// 자신의 크기만큼 물고기를 먹어야 크기가 커진다. - -// 더 이상 먹을 수 있는 물고기가 공간에 없다면 아기 상어는 엄마 상어에게 도움을 요청한다. -// 먹을 수 있는 물고기가 1마리라면, 그 물고기를 먹으러 간다. -// 먹을 수 있는 물고기가 1마리 보다 많앋면, 거리가 가장 가까운 물고기를 먹으러 간다. -// 거리는 아기 상어가 있는 칸에서 물고기가 -// 거리가 가장 가까운 물고기가 많다면, 가장 위에 있는 물고기, 그러한 물고기가 여러마리라면, 가장 왼쪽에 있는 물고기를 먹는다. -public class Main_16236_아기_상어 { - static int N, result, startX, startY; - static int[][] arr; - static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 - static int[] dirY = {0, 0, -1, 1}; - static Shark babyShark; - - static class Coordinates implements Comparable { - int x; - int y; - int dist; - - public Coordinates(int x, int y, int dist) { - this.x = x; - this.y = y; - this.dist = dist; - } - - @Override - public int compareTo(Coordinates o) { - if (dist == o.dist) { - - if (x == o.x) { - return y - o.y; - } - return x - o.x; - } - - return this.dist - o.dist; - } - } // End of Coordinates class - - static class Shark { - int size; - int eatCount; - - public Shark(int size, int eatCount) { - this.size = size; - this.eatCount = eatCount; - } - } // End of Shark class - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/16236.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st; - - st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - init(); - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < N; j++) { - arr[i][j] = Integer.parseInt(st.nextToken()); - - if (arr[i][j] == 9) { - startX = i; - startY = j; - arr[i][j] = 0; - } - } - } - - BFS(startX, startY); - System.out.println(result); - } // End of main - - private static void BFS(int x, int y) { - PriorityQueue pque = new PriorityQueue<>(); - boolean[][] isVisited = new boolean[N][N]; - pque.offer(new Coordinates(x, y, 0)); - isVisited[x][y] = true; - - while (!pque.isEmpty()) { - Coordinates pollCor = pque.poll(); - - for (int i = 0; i < 4; i++) { - int nowX = dirX[i] + pollCor.x; - int nowY = dirY[i] + pollCor.y; - - if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && arr[nowX][nowY] <= babyShark.size) { - isVisited[nowX][nowY] = true; - pque.offer(new Coordinates(nowX, nowY, pollCor.dist + 1)); - } - } - - // 갈 수 있는 방향으로 1 만큼 거리 탐색 후, 갈 수 있는 곳이 있다면, - if (!pque.isEmpty()) { - Coordinates peekCor = pque.peek(); - - if (arr[peekCor.x][peekCor.y] < babyShark.size && arr[peekCor.x][peekCor.y] > 0) { - babyShark.eatCount++; - - // 먹은 수와, 상어의 크기가 같으면 크기가 커진다. - if (babyShark.eatCount == babyShark.size) { - babyShark.size++; - babyShark.eatCount = 0; - } - arr[peekCor.x][peekCor.y] = 0; // 먹은 자리는 0으로 처리 - - pque.clear(); // 다시 출발 하기 위해서 que를 clear - result += peekCor.dist; // 거리 값을 result에 누적 - pque.offer(new Coordinates(peekCor.x, peekCor.y, 0)); // 새로운 출발지 설정 - isVisited = new boolean[N][N]; - isVisited[peekCor.x][peekCor.y] = true; - } - } - } - - } // End of BFS - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; - } // End of rangeCheck - - private static void init() { - arr = new int[N][N]; - babyShark = new Shark(2, 0); - } // End of init +import java.util.*; +import java.io.*; + +// 아기 상어가 도움을 요청하지 않고 물고기를 잡아먹을 수 있는 시간을 출력한다. +// 아기상어는 자신보다 작은 물고기만 먹을 수 있다. +// 자신보다 큰 물고기가 있는 칸은 지나갈 수 없다. +// 자신의 크기만큼 물고기를 먹어야 크기가 커진다. + +// 더 이상 먹을 수 있는 물고기가 공간에 없다면 아기 상어는 엄마 상어에게 도움을 요청한다. +// 먹을 수 있는 물고기가 1마리라면, 그 물고기를 먹으러 간다. +// 먹을 수 있는 물고기가 1마리 보다 많앋면, 거리가 가장 가까운 물고기를 먹으러 간다. +// 거리는 아기 상어가 있는 칸에서 물고기가 +// 거리가 가장 가까운 물고기가 많다면, 가장 위에 있는 물고기, 그러한 물고기가 여러마리라면, 가장 왼쪽에 있는 물고기를 먹는다. +public class Main_16236_아기_상어 { + static int N, result, startX, startY; + static int[][] arr; + static int[] dirX = {-1, 1, 0, 0}; // 상 하 좌 우 + static int[] dirY = {0, 0, -1, 1}; + static Shark babyShark; + + static class Coordinates implements Comparable { + int x; + int y; + int dist; + + public Coordinates(int x, int y, int dist) { + this.x = x; + this.y = y; + this.dist = dist; + } + + @Override + public int compareTo(Coordinates o) { + if (dist == o.dist) { + + if (x == o.x) { + return y - o.y; + } + return x - o.x; + } + + return this.dist - o.dist; + } + } // End of Coordinates class + + static class Shark { + int size; + int eatCount; + + public Shark(int size, int eatCount) { + this.size = size; + this.eatCount = eatCount; + } + } // End of Shark class + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/16236.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + + if (arr[i][j] == 9) { + startX = i; + startY = j; + arr[i][j] = 0; + } + } + } + + BFS(startX, startY); + System.out.println(result); + } // End of main + + private static void BFS(int x, int y) { + PriorityQueue pque = new PriorityQueue<>(); + boolean[][] isVisited = new boolean[N][N]; + pque.offer(new Coordinates(x, y, 0)); + isVisited[x][y] = true; + + while (!pque.isEmpty()) { + Coordinates pollCor = pque.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = dirX[i] + pollCor.x; + int nowY = dirY[i] + pollCor.y; + + if (rangeCheck(nowX, nowY) && !isVisited[nowX][nowY] && arr[nowX][nowY] <= babyShark.size) { + isVisited[nowX][nowY] = true; + pque.offer(new Coordinates(nowX, nowY, pollCor.dist + 1)); + } + } + + // 갈 수 있는 방향으로 1 만큼 거리 탐색 후, 갈 수 있는 곳이 있다면, + if (!pque.isEmpty()) { + Coordinates peekCor = pque.peek(); + + if (arr[peekCor.x][peekCor.y] < babyShark.size && arr[peekCor.x][peekCor.y] > 0) { + babyShark.eatCount++; + + // 먹은 수와, 상어의 크기가 같으면 크기가 커진다. + if (babyShark.eatCount == babyShark.size) { + babyShark.size++; + babyShark.eatCount = 0; + } + arr[peekCor.x][peekCor.y] = 0; // 먹은 자리는 0으로 처리 + + pque.clear(); // 다시 출발 하기 위해서 que를 clear + result += peekCor.dist; // 거리 값을 result에 누적 + pque.offer(new Coordinates(peekCor.x, peekCor.y, 0)); // 새로운 출발지 설정 + isVisited = new boolean[N][N]; + isVisited[peekCor.x][peekCor.y] = true; + } + } + } + + } // End of BFS + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + arr = new int[N][N]; + babyShark = new Shark(2, 0); + } // End of init } // End of Main class \ No newline at end of file diff --git "a/10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" "b/2022/10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" similarity index 97% rename from "10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" rename to "2022/10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" index 8cdce35..bf59cf0 100644 --- "a/10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" +++ "b/2022/10.03/\354\265\234\354\260\275\354\230\201/Main_5658_\353\263\264\353\254\274\354\203\201\354\236\220_\353\271\204\353\260\200\353\262\210\355\230\270.java" @@ -1,69 +1,69 @@ -import java.util.*; -import java.io.*; - -public class Main_5658_보물상자_비밀번호 { - static int N, K, unitCount, result; - static char[] chArr; - static TreeSet pwSet; - - // K 번째로 큰 수 - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/5658.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringBuilder sb = new StringBuilder(); - StringTokenizer st; - - // 처음 회전한 값과 동일 해 질 때 까지 계속 해서 회전. - int T = Integer.parseInt(br.readLine()); - for (int t = 1; t <= T; t++) { - sb.append('#').append(t).append(' '); - - st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - K = Integer.parseInt(st.nextToken()); - init(); - - // unitCount 만큼 회전 - String temp = br.readLine(); - chArr = temp.toCharArray(); - - // 1. 회전을 함. - // 2. 회전된 값을 4등분한다. - // 3. 10진수로 변환 -> treeSet에 넣는다. - // 3. 다시 회전을 한다. 이 과정을 uniCount만큼 반복한다. - - String temp2 = temp; - for (int i = 0; i < unitCount; i++) { - for (int j = 0; j < 4; j++) { - String temp3 = temp2.substring(j * unitCount, (j * unitCount) + unitCount); - pwSet.add(Integer.parseInt(temp3, 16)); - } - temp2 = (temp2.substring(1, temp.length())) + temp2.substring(0, 1); - } - - Iterator iter = pwSet.iterator(); - int indexCount = 0; - while (iter.hasNext()) { - int num = iter.next(); - if (indexCount == pwSet.size() - K) { - result = num; - break; - } - indexCount++; - } - - sb.append(result).append('\n'); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void init() { - unitCount = N / 4; - result = 0; - pwSet = new TreeSet<>(); - chArr = new char[N]; - } // End of init +import java.util.*; +import java.io.*; + +public class Main_5658_보물상자_비밀번호 { + static int N, K, unitCount, result; + static char[] chArr; + static TreeSet pwSet; + + // K 번째로 큰 수 + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/5658.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringBuilder sb = new StringBuilder(); + StringTokenizer st; + + // 처음 회전한 값과 동일 해 질 때 까지 계속 해서 회전. + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + sb.append('#').append(t).append(' '); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + init(); + + // unitCount 만큼 회전 + String temp = br.readLine(); + chArr = temp.toCharArray(); + + // 1. 회전을 함. + // 2. 회전된 값을 4등분한다. + // 3. 10진수로 변환 -> treeSet에 넣는다. + // 3. 다시 회전을 한다. 이 과정을 uniCount만큼 반복한다. + + String temp2 = temp; + for (int i = 0; i < unitCount; i++) { + for (int j = 0; j < 4; j++) { + String temp3 = temp2.substring(j * unitCount, (j * unitCount) + unitCount); + pwSet.add(Integer.parseInt(temp3, 16)); + } + temp2 = (temp2.substring(1, temp.length())) + temp2.substring(0, 1); + } + + Iterator iter = pwSet.iterator(); + int indexCount = 0; + while (iter.hasNext()) { + int num = iter.next(); + if (indexCount == pwSet.size() - K) { + result = num; + break; + } + indexCount++; + } + + sb.append(result).append('\n'); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void init() { + unitCount = N / 4; + result = 0; + pwSet = new TreeSet<>(); + chArr = new char[N]; + } // End of init } // End of Main class \ No newline at end of file diff --git "a/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" "b/2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" similarity index 100% rename from "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" rename to "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/readme.md" diff --git "a/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" "b/2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" similarity index 100% rename from "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" rename to "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" diff --git "a/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" "b/2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" similarity index 100% rename from "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" rename to "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\235\264\354\225\204\353\246\204/\355\201\260\354\210\230\353\247\214\353\223\244\352\270\260.cpp" diff --git "a/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" "b/2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" similarity index 100% rename from "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" rename to "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" diff --git "a/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260.kt" "b/2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260.kt" similarity index 100% rename from "10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260.kt" rename to "2022/10.03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244/\354\241\260\354\210\230\354\227\260/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260.kt" diff --git "a/10.03/\355\231\251\354\247\200\354\233\220/\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.java" "b/2022/10.03/\355\231\251\354\247\200\354\233\220/\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.java" similarity index 100% rename from "10.03/\355\231\251\354\247\200\354\233\220/\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.java" rename to "2022/10.03/\355\231\251\354\247\200\354\233\220/\354\203\201\354\226\264\354\264\210\353\223\261\355\225\231\352\265\220.java" diff --git a/10.06/readme.md b/2022/10.06/readme.md similarity index 100% rename from 10.06/readme.md rename to 2022/10.06/readme.md diff --git "a/10.06/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225.py" "b/2022/10.06/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225.py" similarity index 100% rename from "10.06/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225.py" rename to "2022/10.06/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17144_\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225.py" diff --git "a/10.06/\354\235\264\354\225\204\353\246\204/17144_\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225.cpp" "b/2022/10.06/\354\235\264\354\225\204\353\246\204/17144_\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225.cpp" similarity index 100% rename from "10.06/\354\235\264\354\225\204\353\246\204/17144_\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225.cpp" rename to "2022/10.06/\354\235\264\354\225\204\353\246\204/17144_\353\257\270\354\204\270\353\250\274\354\247\200_\354\225\210\353\205\225.cpp" diff --git "a/10.06/\354\235\264\354\247\200\354\234\244/\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225.py" "b/2022/10.06/\354\235\264\354\247\200\354\234\244/\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225.py" similarity index 100% rename from "10.06/\354\235\264\354\247\200\354\234\244/\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225.py" rename to "2022/10.06/\354\235\264\354\247\200\354\234\244/\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225.py" diff --git "a/10.06/\354\240\225\355\230\270\354\241\260/\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225~.java" "b/2022/10.06/\354\240\225\355\230\270\354\241\260/\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225~.java" similarity index 100% rename from "10.06/\354\240\225\355\230\270\354\241\260/\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225~.java" rename to "2022/10.06/\354\240\225\355\230\270\354\241\260/\353\257\270\354\204\270\353\250\274\354\247\200\354\225\210\353\205\225~.java" diff --git "a/10.06/\354\241\260\354\210\230\354\227\260/17144_\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.kt" "b/2022/10.06/\354\241\260\354\210\230\354\227\260/17144_\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.kt" similarity index 100% rename from "10.06/\354\241\260\354\210\230\354\227\260/17144_\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.kt" rename to "2022/10.06/\354\241\260\354\210\230\354\227\260/17144_\353\257\270\354\204\270\353\250\274\354\247\200 \354\225\210\353\205\225!.kt" diff --git a/10.27/readme.md b/2022/10.27/readme.md similarity index 100% rename from 10.27/readme.md rename to 2022/10.27/readme.md diff --git "a/10.27/\354\206\241\352\270\260\355\233\210/pgm_lv1_\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204.py" "b/2022/10.27/\354\206\241\352\270\260\355\233\210/pgm_lv1_\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204.py" similarity index 100% rename from "10.27/\354\206\241\352\270\260\355\233\210/pgm_lv1_\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204.py" rename to "2022/10.27/\354\206\241\352\270\260\355\233\210/pgm_lv1_\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204.py" diff --git "a/10.27/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3190_\353\261\200.py" "b/2022/10.27/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3190_\353\261\200.py" similarity index 100% rename from "10.27/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3190_\353\261\200.py" rename to "2022/10.27/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_3190_\353\261\200.py" diff --git "a/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" "b/2022/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" similarity index 100% rename from "10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" rename to "2022/10.27/\354\235\264\354\225\204\353\246\204/3190_\353\261\200.cpp" diff --git "a/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" "b/2022/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" similarity index 100% rename from "10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" rename to "2022/10.27/\354\235\264\354\225\204\353\246\204/\354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.cpp" diff --git "a/10.27/\354\235\264\354\247\200\354\234\244/[BOJ_3190]\353\261\200.py" "b/2022/10.27/\354\235\264\354\247\200\354\234\244/[BOJ_3190]\353\261\200.py" similarity index 100% rename from "10.27/\354\235\264\354\247\200\354\234\244/[BOJ_3190]\353\261\200.py" rename to "2022/10.27/\354\235\264\354\247\200\354\234\244/[BOJ_3190]\353\261\200.py" diff --git "a/10.27/\354\235\264\354\247\200\354\234\244/[Programmers_ver1]\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.py" "b/2022/10.27/\354\235\264\354\247\200\354\234\244/[Programmers_ver1]\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.py" similarity index 100% rename from "10.27/\354\235\264\354\247\200\354\234\244/[Programmers_ver1]\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.py" rename to "2022/10.27/\354\235\264\354\247\200\354\234\244/[Programmers_ver1]\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.py" diff --git "a/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200.java" "b/2022/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200.java" similarity index 100% rename from "10.27/\354\240\225\355\230\270\354\241\260/\353\261\200.java" rename to "2022/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200.java" diff --git "a/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" "b/2022/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" similarity index 100% rename from "10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" rename to "2022/10.27/\354\240\225\355\230\270\354\241\260/\353\261\200_dfs.java" diff --git "a/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" "b/2022/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" similarity index 100% rename from "10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" rename to "2022/10.27/\354\240\225\355\230\270\354\241\260/\354\235\270\355\230\225\353\275\221\352\270\260.java" diff --git "a/10.27/\354\241\260\354\210\230\354\227\260/\353\261\200.kt" "b/2022/10.27/\354\241\260\354\210\230\354\227\260/\353\261\200.kt" similarity index 100% rename from "10.27/\354\241\260\354\210\230\354\227\260/\353\261\200.kt" rename to "2022/10.27/\354\241\260\354\210\230\354\227\260/\353\261\200.kt" diff --git "a/10.27/\354\241\260\354\210\230\354\227\260/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.kt" "b/2022/10.27/\354\241\260\354\210\230\354\227\260/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.kt" similarity index 100% rename from "10.27/\354\241\260\354\210\230\354\227\260/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.kt" rename to "2022/10.27/\354\241\260\354\210\230\354\227\260/\355\201\254\353\240\210\354\235\270 \354\235\270\355\230\225\353\275\221\352\270\260 \352\262\214\354\236\204.kt" diff --git a/10.31/readme.md b/2022/10.31/readme.md similarity index 100% rename from 10.31/readme.md rename to 2022/10.31/readme.md diff --git "a/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" "b/2022/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" similarity index 100% rename from "10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" rename to "2022/10.31/\352\266\214\354\243\274\355\230\204/bj1026.java" diff --git "a/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" "b/2022/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" similarity index 100% rename from "10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" rename to "2022/10.31/\352\266\214\354\243\274\355\230\204/\353\251\200\353\246\254\353\233\260\352\270\260.java" diff --git "a/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" "b/2022/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" similarity index 94% rename from "10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" rename to "2022/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" index ef6de67..d41d15e 100644 --- "a/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" +++ "b/2022/10.31/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\353\246\254\353\233\260\352\270\260.py" @@ -1,33 +1,33 @@ -import math - - -def solution(n): - count1 = 0 - count2 = n // 2 - answer = 0 - - for i in range(count2 + 1): - count1 = n - i * 2 - answer += math.factorial(count1 + i) // (math.factorial(count1) * math.factorial(i)) - - return answer % 1234567 - - -""" -def solution(n): - count1 = 0 - count2 = n // 2 - answer = 0 - - for i in range(count2+1): - count1 = n - i * 2 - answer += factorial(count1+i) // (factorial(count1) * factorial(i)) - - return answer % 1234567 - -def factorial(x): - if x > 1: - return x * factorial(x-1) - else: - return 1 -""" +import math + + +def solution(n): + count1 = 0 + count2 = n // 2 + answer = 0 + + for i in range(count2 + 1): + count1 = n - i * 2 + answer += math.factorial(count1 + i) // (math.factorial(count1) * math.factorial(i)) + + return answer % 1234567 + + +""" +def solution(n): + count1 = 0 + count2 = n // 2 + answer = 0 + + for i in range(count2+1): + count1 = n - i * 2 + answer += factorial(count1+i) // (factorial(count1) * factorial(i)) + + return answer % 1234567 + +def factorial(x): + if x > 1: + return x * factorial(x-1) + else: + return 1 +""" diff --git "a/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" "b/2022/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" similarity index 94% rename from "10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" rename to "2022/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" index ed9efbc..84cd587 100644 --- "a/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" +++ "b/2022/10.31/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1026_\353\263\264\353\254\274.py" @@ -1,19 +1,19 @@ -n = int(input()) - -aList = list(map(int, input().split())) -bList = list(map(int, input().split())) -minValue = 10 ** 9 - - -def calculate(tempA): - global minValue - result = 0 - for i in range(n): - result += tempA[i] * bList[i] - - return result - -aList.sort() -bList.sort(reverse=True) - +n = int(input()) + +aList = list(map(int, input().split())) +bList = list(map(int, input().split())) +minValue = 10 ** 9 + + +def calculate(tempA): + global minValue + result = 0 + for i in range(n): + result += tempA[i] * bList[i] + + return result + +aList.sort() +bList.sort(reverse=True) + print(calculate(aList)) \ No newline at end of file diff --git "a/10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" "b/2022/10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" similarity index 100% rename from "10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" rename to "2022/10.31/\354\235\264\354\225\204\353\246\204/1026_\353\263\264\353\254\274.cpp" diff --git "a/10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" "b/2022/10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" similarity index 100% rename from "10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" rename to "2022/10.31/\354\235\264\354\225\204\353\246\204/\353\251\200\353\246\254\353\233\260\352\270\260.cpp" diff --git "a/10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" "b/2022/10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" similarity index 100% rename from "10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" rename to "2022/10.31/\354\235\264\354\247\200\354\234\244/\353\251\200\353\246\254\353\233\260\352\270\260.py" diff --git "a/10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" "b/2022/10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" similarity index 100% rename from "10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" rename to "2022/10.31/\354\235\264\354\247\200\354\234\244/\353\263\264\353\254\274.py" diff --git "a/10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" "b/2022/10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" similarity index 100% rename from "10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" rename to "2022/10.31/\354\241\260\354\210\230\354\227\260/\353\251\200\353\246\254 \353\233\260\352\270\260.kt" diff --git "a/10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" "b/2022/10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" similarity index 100% rename from "10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" rename to "2022/10.31/\354\241\260\354\210\230\354\227\260/\353\263\264\353\254\274.kt" diff --git "a/10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" "b/2022/10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" similarity index 100% rename from "10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" rename to "2022/10.31/\354\265\234\354\260\275\354\230\201/Main_1026_\353\263\264\353\254\274.java" diff --git "a/10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" "b/2022/10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" similarity index 100% rename from "10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" rename to "2022/10.31/\355\231\251\354\247\200\354\233\220/\353\251\200\353\246\254\353\233\260\352\270\260.java" diff --git "a/10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" "b/2022/10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" similarity index 100% rename from "10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" rename to "2022/10.31/\355\231\251\354\247\200\354\233\220/\353\263\264\353\254\274.java" diff --git a/11.03/readme.md b/2022/11.03/readme.md similarity index 100% rename from 11.03/readme.md rename to 2022/11.03/readme.md diff --git "a/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" "b/2022/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" similarity index 100% rename from "11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" rename to "2022/11.03/\352\266\214\354\243\274\355\230\204/BJ14499.java" diff --git "a/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" "b/2022/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" similarity index 100% rename from "11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" rename to "2022/11.03/\352\266\214\354\243\274\355\230\204/\353\266\200\353\266\204\355\225\251.java" diff --git "a/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" "b/2022/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" similarity index 100% rename from "11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" rename to "2022/11.03/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\227\260\354\206\215_\353\266\200\353\266\204_\354\210\230\354\227\264_\355\225\251\354\235\230_\352\260\234\354\210\230.py" diff --git "a/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" "b/2022/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" similarity index 100% rename from "11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" rename to "2022/11.03/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_14499_\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.py" diff --git "a/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" "b/2022/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" similarity index 100% rename from "11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" rename to "2022/11.03/\354\235\264\354\225\204\353\246\204/14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.cpp" diff --git "a/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" "b/2022/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" similarity index 100% rename from "11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" rename to "2022/11.03/\354\235\264\354\225\204\353\246\204/\353\266\200\353\266\204\355\225\251\352\265\254\355\225\230\352\270\260.cpp" diff --git "a/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" "b/2022/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" similarity index 100% rename from "11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" rename to "2022/11.03/\354\240\225\355\230\270\354\241\260/\354\227\260\354\206\215\353\266\200\353\266\204\354\210\230\354\227\264\355\225\251\354\235\230\352\260\234\354\210\230.java" diff --git "a/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" "b/2022/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" similarity index 100% rename from "11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" rename to "2022/11.03/\354\240\225\355\230\270\354\241\260/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" diff --git "a/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" "b/2022/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" similarity index 100% rename from "11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" rename to "2022/11.03/\354\241\260\354\210\230\354\227\260/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.kt" diff --git "a/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" "b/2022/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" similarity index 100% rename from "11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" rename to "2022/11.03/\354\241\260\354\210\230\354\227\260/\354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.kt" diff --git "a/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" "b/2022/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" similarity index 97% rename from "11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" rename to "2022/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" index 6a8db3a..85a6807 100644 --- "a/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" +++ "b/2022/11.03/\354\265\234\354\260\275\354\230\201/Main_14499_\354\243\274\354\202\254\354\234\204_\352\265\264\353\246\254\352\270\260.java" @@ -1,101 +1,101 @@ -import java.io.*; -import java.util.*; - -public class Main_14499_주사위_굴리기 { - static int N, M, startX, startY; - static int[][] map = new int[21][21]; - static int[] dice = new int[7]; - static int[] dirX = {1, -1, 0, 0}; - static int[] dirY = {0, 0, - 1, 1}; - static StringBuilder sb; - - // 가장 처음에 주사위에는 모든 면에 0이 적혀있다. - // 동쪽은 1, 서쪽은 2, 북쪽은 3 남쪽은 4 - // 이동한 칸에 쓰여있는 수가 0이면, 주사위의 바닥면에 쓰여 있는 수가 칸에 복사된다. - // 0이 아닌경우에는 칸에 쓰여있는 수가 주사위 바닥면으로 복사되며, 칸에 쓰여있는 수는 0이 된다. - - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/14499.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - StringTokenizer st; - - st = new StringTokenizer(br.readLine()); - N = Integer.parseInt(st.nextToken()); - M = Integer.parseInt(st.nextToken()); - startY = Integer.parseInt(st.nextToken()); - startX = Integer.parseInt(st.nextToken()); - int K = Integer.parseInt(st.nextToken()); - init(); - - for (int i = 0; i < N; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < M; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - } - } - - st = new StringTokenizer(br.readLine()); - for (int i = 0; i < K; i++) { - move(Integer.parseInt(st.nextToken())); - } - - bw.write(sb.toString()); - bw.close(); - } // End of main - - private static void move(int direction) { - int nowX = startX + dirX[direction - 1]; - int nowY = startY + dirY[direction - 1]; - - if (!rangeCheck(nowX, nowY)) return; - - roll(direction, nowX, nowY); - startX = nowX; - startY = nowY; - } // End of move - - private static void roll(int num, int x, int y) { - int temp = dice[3]; - - if (num == 1) { - dice[3] = dice[4]; - dice[4] = dice[6]; - dice[6] = dice[2]; - dice[2] = temp; - } else if (num == 2) { - dice[3] = dice[2]; - dice[2] = dice[6]; - dice[6] = dice[4]; - dice[4] = temp; - } else if (num == 3) { - dice[3] = dice[5]; - dice[5] = dice[6]; - dice[6] = dice[1]; - dice[1] = temp; - } else if (num == 4) { - dice[3] = dice[1]; - dice[1] = dice[6]; - dice[6] = dice[5]; - dice[5] = temp; - } - - if (map[y][x] == 0) { - map[y][x] = dice[6]; - } else { - dice[6] = map[y][x]; - map[y][x] = 0; - } - - sb.append(dice[3]).append('\n'); - } // End of roll - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < M && nowY >= 0 && nowY < N; - } // End of rangeCheck - - private static void init() { - sb = new StringBuilder(); - } // End of init +import java.io.*; +import java.util.*; + +public class Main_14499_주사위_굴리기 { + static int N, M, startX, startY; + static int[][] map = new int[21][21]; + static int[] dice = new int[7]; + static int[] dirX = {1, -1, 0, 0}; + static int[] dirY = {0, 0, - 1, 1}; + static StringBuilder sb; + + // 가장 처음에 주사위에는 모든 면에 0이 적혀있다. + // 동쪽은 1, 서쪽은 2, 북쪽은 3 남쪽은 4 + // 이동한 칸에 쓰여있는 수가 0이면, 주사위의 바닥면에 쓰여 있는 수가 칸에 복사된다. + // 0이 아닌경우에는 칸에 쓰여있는 수가 주사위 바닥면으로 복사되며, 칸에 쓰여있는 수는 0이 된다. + + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/14499.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + startY = Integer.parseInt(st.nextToken()); + startX = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + init(); + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < K; i++) { + move(Integer.parseInt(st.nextToken())); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void move(int direction) { + int nowX = startX + dirX[direction - 1]; + int nowY = startY + dirY[direction - 1]; + + if (!rangeCheck(nowX, nowY)) return; + + roll(direction, nowX, nowY); + startX = nowX; + startY = nowY; + } // End of move + + private static void roll(int num, int x, int y) { + int temp = dice[3]; + + if (num == 1) { + dice[3] = dice[4]; + dice[4] = dice[6]; + dice[6] = dice[2]; + dice[2] = temp; + } else if (num == 2) { + dice[3] = dice[2]; + dice[2] = dice[6]; + dice[6] = dice[4]; + dice[4] = temp; + } else if (num == 3) { + dice[3] = dice[5]; + dice[5] = dice[6]; + dice[6] = dice[1]; + dice[1] = temp; + } else if (num == 4) { + dice[3] = dice[1]; + dice[1] = dice[6]; + dice[6] = dice[5]; + dice[5] = temp; + } + + if (map[y][x] == 0) { + map[y][x] = dice[6]; + } else { + dice[6] = map[y][x]; + map[y][x] = 0; + } + + sb.append(dice[3]).append('\n'); + } // End of roll + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < M && nowY >= 0 && nowY < N; + } // End of rangeCheck + + private static void init() { + sb = new StringBuilder(); + } // End of init } // End of Main class \ No newline at end of file diff --git "a/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" "b/2022/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" similarity index 100% rename from "11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" rename to "2022/11.03/\355\231\251\354\247\200\354\233\220/\354\227\260\354\206\215 \353\266\200\353\266\204 \354\210\230\354\227\264 \355\225\251\354\235\230 \352\260\234\354\210\230.java" diff --git "a/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" "b/2022/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" similarity index 100% rename from "11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" rename to "2022/11.03/\355\231\251\354\247\200\354\233\220/\354\243\274\354\202\254\354\234\204\352\265\264\353\246\254\352\270\260.java" diff --git a/11.07/readme.md b/2022/11.07/readme.md similarity index 100% rename from 11.07/readme.md rename to 2022/11.07/readme.md diff --git "a/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" "b/2022/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" similarity index 100% rename from "11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" rename to "2022/11.07/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\260\260\353\213\254.py" diff --git "a/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" "b/2022/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" similarity index 100% rename from "11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" rename to "2022/11.07/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.py" diff --git "a/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" "b/2022/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" similarity index 100% rename from "11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" rename to "2022/11.07/\354\235\264\354\225\204\353\246\204/15685_\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.cpp" diff --git "a/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" "b/2022/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" similarity index 100% rename from "11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" rename to "2022/11.07/\354\235\264\354\225\204\353\246\204/\353\260\260\353\213\254.cpp" diff --git "a/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" "b/2022/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" similarity index 100% rename from "11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" rename to "2022/11.07/\354\240\225\355\230\270\354\241\260/\353\223\234\353\236\230\352\263\244\354\273\244\353\270\214.java" diff --git "a/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" "b/2022/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" similarity index 100% rename from "11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" rename to "2022/11.07/\354\240\225\355\230\270\354\241\260/\353\260\260\353\213\254.java" diff --git "a/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" "b/2022/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" similarity index 100% rename from "11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" rename to "2022/11.07/\354\241\260\354\210\230\354\227\260/\353\223\234\353\236\230\352\263\244 \354\273\244\353\270\214.kt" diff --git "a/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" "b/2022/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" similarity index 100% rename from "11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" rename to "2022/11.07/\354\241\260\354\210\230\354\227\260/\353\260\260\353\213\254.kt" diff --git "a/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" "b/2022/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" similarity index 96% rename from "11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" rename to "2022/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" index 09f3e07..794f20e 100644 --- "a/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" +++ "b/2022/11.07/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\260\260\353\213\254.java" @@ -1,104 +1,104 @@ -import java.util.*; - -public class Main_PRG_배달 { - private static final int INF = Integer.MAX_VALUE; - static int N, K; - static int[][] road; - static List> nodeList; - - static class Node implements Comparable { - int nodeNum; - int weight; - - public Node(int nodeNum, int weight) { - this.nodeNum = nodeNum; - this.weight = weight; - } - - @Override - public int compareTo(Node o) { - return weight - o.weight; - } - } // End of Node class - - public static void main(String[] args) { - Main_PRG_배달 m = new Main_PRG_배달(); - - int N = 6; - int[][] road = {{1, 2, 1}, {1, 3, 2}, {2, 3, 2}, {3, 4, 3}, {3, 5, 2}, {3, 5, 3}, {5, 6, 1}}; - int K = 4; - - System.out.println(m.solution(N, road, K)); - } // End of main - - // 참고 - // 양방향으로 통행 가능 - - private int solution(int N, int[][] road, int K) { - this.N = N; // 마을의 개수 (노드) - this.road = road; // 도로 (간선) - this.K = K; // 음식 배달이 가능한 시간 (제한 사항) - init(); - - // K시간 이내로 받을 수 있는 집. 찾기 - - int len = road.length; - for (int i = 0; i < len; i++) { - int a = road[i][0]; - int b = road[i][1]; - int c = road[i][2]; - - nodeList.get(a).add(new Node(b, c)); - nodeList.get(b).add(new Node(a, c)); - } - - // 1번 마을에 있는 음식점이 K 이하의 시간에 배달이 가능한 마을의 개수를 return 하면 됩니다. - return resultCheck(dijkstra(1)); - } // End of solution - - private static int[] dijkstra(int startNodeNum) { - PriorityQueue pque = new PriorityQueue<>(); - boolean[] isVisited = new boolean[N + 1]; - int dist[] = new int[N + 1]; - - Arrays.fill(dist, INF); - dist[startNodeNum] = 0; - pque.offer(new Node(startNodeNum, 0)); - - while (!pque.isEmpty()) { - Node pollNode = pque.poll(); - - if (isVisited[pollNode.nodeNum]) continue; - isVisited[pollNode.nodeNum] = true; - - for (Node node : nodeList.get(pollNode.nodeNum)) { - if (!isVisited[node.nodeNum] && dist[node.nodeNum] > dist[pollNode.nodeNum] + node.weight) { - dist[node.nodeNum] = dist[pollNode.nodeNum] + node.weight; - pque.offer(new Node(node.nodeNum, dist[node.nodeNum])); - } - } - } - - return dist; - } // End of dijkstra - - private static int resultCheck(int[] dist) { - int sum = 0; - for (int i = 1; i <= N; i++) { - if (dist[i] <= K) { - sum++; - } - } - - return sum; - } // End of resultCheck - - private static void init() { - nodeList = new ArrayList<>(); - - for (int i = 0; i <= N; i++) { - nodeList.add(new ArrayList<>()); - } - - } // End of init -} // End of Main class +import java.util.*; + +public class Main_PRG_배달 { + private static final int INF = Integer.MAX_VALUE; + static int N, K; + static int[][] road; + static List> nodeList; + + static class Node implements Comparable { + int nodeNum; + int weight; + + public Node(int nodeNum, int weight) { + this.nodeNum = nodeNum; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return weight - o.weight; + } + } // End of Node class + + public static void main(String[] args) { + Main_PRG_배달 m = new Main_PRG_배달(); + + int N = 6; + int[][] road = {{1, 2, 1}, {1, 3, 2}, {2, 3, 2}, {3, 4, 3}, {3, 5, 2}, {3, 5, 3}, {5, 6, 1}}; + int K = 4; + + System.out.println(m.solution(N, road, K)); + } // End of main + + // 참고 + // 양방향으로 통행 가능 + + private int solution(int N, int[][] road, int K) { + this.N = N; // 마을의 개수 (노드) + this.road = road; // 도로 (간선) + this.K = K; // 음식 배달이 가능한 시간 (제한 사항) + init(); + + // K시간 이내로 받을 수 있는 집. 찾기 + + int len = road.length; + for (int i = 0; i < len; i++) { + int a = road[i][0]; + int b = road[i][1]; + int c = road[i][2]; + + nodeList.get(a).add(new Node(b, c)); + nodeList.get(b).add(new Node(a, c)); + } + + // 1번 마을에 있는 음식점이 K 이하의 시간에 배달이 가능한 마을의 개수를 return 하면 됩니다. + return resultCheck(dijkstra(1)); + } // End of solution + + private static int[] dijkstra(int startNodeNum) { + PriorityQueue pque = new PriorityQueue<>(); + boolean[] isVisited = new boolean[N + 1]; + int dist[] = new int[N + 1]; + + Arrays.fill(dist, INF); + dist[startNodeNum] = 0; + pque.offer(new Node(startNodeNum, 0)); + + while (!pque.isEmpty()) { + Node pollNode = pque.poll(); + + if (isVisited[pollNode.nodeNum]) continue; + isVisited[pollNode.nodeNum] = true; + + for (Node node : nodeList.get(pollNode.nodeNum)) { + if (!isVisited[node.nodeNum] && dist[node.nodeNum] > dist[pollNode.nodeNum] + node.weight) { + dist[node.nodeNum] = dist[pollNode.nodeNum] + node.weight; + pque.offer(new Node(node.nodeNum, dist[node.nodeNum])); + } + } + } + + return dist; + } // End of dijkstra + + private static int resultCheck(int[] dist) { + int sum = 0; + for (int i = 1; i <= N; i++) { + if (dist[i] <= K) { + sum++; + } + } + + return sum; + } // End of resultCheck + + private static void init() { + nodeList = new ArrayList<>(); + + for (int i = 0; i <= N; i++) { + nodeList.add(new ArrayList<>()); + } + + } // End of init +} // End of Main class diff --git "a/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" "b/2022/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" similarity index 100% rename from "11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" rename to "2022/11.07/\355\231\251\354\247\200\354\233\220/\353\223\234\353\236\230\352\263\244_\354\273\244\353\270\214.java" diff --git a/11.10/readme.md b/2022/11.10/readme.md similarity index 100% rename from 11.10/readme.md rename to 2022/11.10/readme.md diff --git "a/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" "b/2022/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" similarity index 100% rename from "11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" rename to "2022/11.10/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.py" diff --git "a/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" "b/2022/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" similarity index 100% rename from "11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" rename to "2022/11.10/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17140_\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.py" diff --git "a/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" "b/2022/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" similarity index 100% rename from "11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" rename to "2022/11.10/\354\235\264\354\225\204\353\246\204/17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.cpp" diff --git "a/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" "b/2022/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" similarity index 100% rename from "11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" rename to "2022/11.10/\354\235\264\354\225\204\353\246\204/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.cpp" diff --git "a/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" "b/2022/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" similarity index 100% rename from "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" rename to "2022/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_gcd.py" diff --git "a/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" "b/2022/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" similarity index 100% rename from "11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" rename to "2022/11.10/\354\235\264\354\247\200\354\234\244/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225_\354\213\234\352\260\204\354\264\210\352\263\274.py" diff --git "a/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" "b/2022/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" similarity index 100% rename from "11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" rename to "2022/11.10/\354\240\225\355\230\270\354\241\260/\353\251\200\354\251\241\355\225\234\354\202\254\352\260\201\355\230\225.java" diff --git "a/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" "b/2022/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" similarity index 100% rename from "11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" rename to "2022/11.10/\354\240\225\355\230\270\354\241\260/\354\235\264\354\260\250\354\233\220\353\260\260\354\227\264\352\263\274\354\227\260\354\202\260.java" diff --git "a/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" "b/2022/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" similarity index 100% rename from "11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" rename to "2022/11.10/\354\241\260\354\210\230\354\227\260/\353\251\200\354\251\241\355\225\234 \354\202\254\352\260\201\355\230\225.kt" diff --git "a/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" "b/2022/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" similarity index 100% rename from "11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" rename to "2022/11.10/\354\241\260\354\210\230\354\227\260/\354\235\264\354\260\250\354\233\220 \353\260\260\354\227\264\352\263\274 \354\227\260\354\202\260.kt" diff --git "a/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" "b/2022/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" similarity index 96% rename from "11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" rename to "2022/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" index e7ae477..3a8ecf5 100644 --- "a/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" +++ "b/2022/11.10/\354\265\234\354\260\275\354\230\201/Main_17140_\354\235\264\354\260\250\354\233\220_\353\260\260\354\227\264\352\263\274_\354\227\260\354\202\260.java" @@ -1,216 +1,216 @@ -import java.io.*; -import java.util.*; - -public class Main_17140_이차원_배열과_연산 { - private static final int N = 101; - static int R, C, K, xLen, yLen; - static int[][] map = new int[N][N]; - static int[][] tempMap; - - static class Coordinates { - int x; - int y; - - public Coordinates(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Coordinates class - - static class Number implements Comparable { - int num; - int freq; - - public Number(int num, int freq) { - this.num = num; - this.freq = freq; - } - - @Override - public int compareTo(Number o) { - - if (freq > o.freq) { - return 1; - } else if (freq == o.freq) { - return num - o.num; - } else { - return -1; - } - } - } // End of Number class - - // 100초가 지나도 A[r][c] = k가 되지 않으면 -1을 출력한다. - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/17140.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st; - - st = new StringTokenizer(br.readLine()); - R = Integer.parseInt(st.nextToken()); - C = Integer.parseInt(st.nextToken()); - K = Integer.parseInt(st.nextToken()); - xLen = 3; - yLen = 3; - - for (int i = 0; i < 3; i++) { - st = new StringTokenizer(br.readLine()); - for (int j = 0; j < 3; j++) { - map[i][j] = Integer.parseInt(st.nextToken()); - } - } - - System.out.println(solution()); - } // End of main - - // 행 또는 열의 크기가 커진 곳에는 0이 채워진다. 수를 정렬할 때 0은 무시해야 한다 - // 행과 열의 위치를 파악할 때는 0,0을 1,1로 해야된다. - // 0이 아닌 것의 개수 - private static int solution() { - - for (int t = 0; t < 101; t++) { - if (map[R - 1][C - 1] == K) { - // 가장 먼저 해당 위치에 K값이 일치하는지 체크. - // 일치한다면 곧 바로 t를 return - return t; - } - - // 행과 열의 수를 알아내기. - Coordinates cor = rowLine_ColumnLine_Check(); - - // 행과 열의 수에 따른 정렬 실행 - if (cor.x <= cor.y) { - // R연산 (행을 기준으로 정렬) - calcR(); - } else { - // C연산 (열을 기준으로 정렬) - calcC(); - } - } - - return -1; - } - - // 행,열 수 체크 - private static Coordinates rowLine_ColumnLine_Check() { - // 가장 큰 행을 기준으로 모든 행의 크기가 변하고, - // 가장 큰 열을 기준으로 모든 열의 크기가 변한다. - - int maxRow = -1; - int maxCol = -1; - for (int i = 0; i < N; i++) { - int rowLen = 0; - int colLen = 0; - for (int j = 0; j < N; j++) { - if (map[i][j] != 0) { - rowLen++; - } - - if (map[j][i] != 0) { - colLen++; - } - } - - maxRow = Math.max(maxRow, rowLen); - maxCol = Math.max(maxCol, colLen); - } - - return new Coordinates(maxRow, maxCol); - } // End of rowLine_ColumnLine_Check - - // R연산 (행을 기준으로 정렬) - private static void calcR() { - tempMap = new int[N][N]; - int maxCol = -1; - - for (int i = 0; i < N; i++) { - HashMap rowHashMap = new HashMap<>(); - PriorityQueue pque = new PriorityQueue<>(); - - for (int j = 0; j < N; j++) { - int num = map[i][j]; - if (num == 0) continue; - - rowHashMap.put(num, rowHashMap.getOrDefault(num, 0) + 1); - } - - // 횟수가 적은 순으로 나열 해야됨. - // key값을 기준으로 정렬. - Iterator> iter = rowHashMap.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entrySet = iter.next(); - int key = entrySet.getKey(); - int value = entrySet.getValue(); - - pque.offer(new Number(key, value)); - } - - int index = -1; - while (!pque.isEmpty()) { - Number num = pque.poll(); - - tempMap[i][++index] = num.num; - if (index >= 100) break; - - tempMap[i][++index] = num.freq; - if (index >= 100) break; - } - - - maxCol = Math.max(index, maxCol); - } - - copy(); - } // End of calcR - - // C연산 (열을 기준으로 정렬) - private static void calcC() { - tempMap = new int[N][N]; - int maxRow = -1; - - for (int i = 0; i < N; i++) { - HashMap colHashMap = new HashMap<>(); - PriorityQueue pque = new PriorityQueue<>(); - - for (int j = 0; j < N; j++) { - int num = map[j][i]; - if (num == 0) continue; - - colHashMap.put(num, colHashMap.getOrDefault(num, 0) + 1); - } - - // 횟수가 적은 순으로 나열 해야됨. - // key값을 기준으로 정렬. - Iterator> iter = colHashMap.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entrySet = (Map.Entry) iter.next(); - int key = entrySet.getKey(); - int value = entrySet.getValue(); - - pque.offer(new Number(key, value)); - } - - int index = -1; - while (!pque.isEmpty()) { - Number num = pque.poll(); - - tempMap[++index][i] = num.num; - if (index >= 100) break; - tempMap[++index][i] = num.freq; - if (index >= 100) break; - } - - - maxRow = Math.max(index, maxRow); - } - - copy(); - } // End of calcC - - private static void copy() { - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - map[i][j] = tempMap[i][j]; - } - } - } // End of copy +import java.io.*; +import java.util.*; + +public class Main_17140_이차원_배열과_연산 { + private static final int N = 101; + static int R, C, K, xLen, yLen; + static int[][] map = new int[N][N]; + static int[][] tempMap; + + static class Coordinates { + int x; + int y; + + public Coordinates(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Coordinates class + + static class Number implements Comparable { + int num; + int freq; + + public Number(int num, int freq) { + this.num = num; + this.freq = freq; + } + + @Override + public int compareTo(Number o) { + + if (freq > o.freq) { + return 1; + } else if (freq == o.freq) { + return num - o.num; + } else { + return -1; + } + } + } // End of Number class + + // 100초가 지나도 A[r][c] = k가 되지 않으면 -1을 출력한다. + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/17140.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + xLen = 3; + yLen = 3; + + for (int i = 0; i < 3; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + System.out.println(solution()); + } // End of main + + // 행 또는 열의 크기가 커진 곳에는 0이 채워진다. 수를 정렬할 때 0은 무시해야 한다 + // 행과 열의 위치를 파악할 때는 0,0을 1,1로 해야된다. + // 0이 아닌 것의 개수 + private static int solution() { + + for (int t = 0; t < 101; t++) { + if (map[R - 1][C - 1] == K) { + // 가장 먼저 해당 위치에 K값이 일치하는지 체크. + // 일치한다면 곧 바로 t를 return + return t; + } + + // 행과 열의 수를 알아내기. + Coordinates cor = rowLine_ColumnLine_Check(); + + // 행과 열의 수에 따른 정렬 실행 + if (cor.x <= cor.y) { + // R연산 (행을 기준으로 정렬) + calcR(); + } else { + // C연산 (열을 기준으로 정렬) + calcC(); + } + } + + return -1; + } + + // 행,열 수 체크 + private static Coordinates rowLine_ColumnLine_Check() { + // 가장 큰 행을 기준으로 모든 행의 크기가 변하고, + // 가장 큰 열을 기준으로 모든 열의 크기가 변한다. + + int maxRow = -1; + int maxCol = -1; + for (int i = 0; i < N; i++) { + int rowLen = 0; + int colLen = 0; + for (int j = 0; j < N; j++) { + if (map[i][j] != 0) { + rowLen++; + } + + if (map[j][i] != 0) { + colLen++; + } + } + + maxRow = Math.max(maxRow, rowLen); + maxCol = Math.max(maxCol, colLen); + } + + return new Coordinates(maxRow, maxCol); + } // End of rowLine_ColumnLine_Check + + // R연산 (행을 기준으로 정렬) + private static void calcR() { + tempMap = new int[N][N]; + int maxCol = -1; + + for (int i = 0; i < N; i++) { + HashMap rowHashMap = new HashMap<>(); + PriorityQueue pque = new PriorityQueue<>(); + + for (int j = 0; j < N; j++) { + int num = map[i][j]; + if (num == 0) continue; + + rowHashMap.put(num, rowHashMap.getOrDefault(num, 0) + 1); + } + + // 횟수가 적은 순으로 나열 해야됨. + // key값을 기준으로 정렬. + Iterator> iter = rowHashMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entrySet = iter.next(); + int key = entrySet.getKey(); + int value = entrySet.getValue(); + + pque.offer(new Number(key, value)); + } + + int index = -1; + while (!pque.isEmpty()) { + Number num = pque.poll(); + + tempMap[i][++index] = num.num; + if (index >= 100) break; + + tempMap[i][++index] = num.freq; + if (index >= 100) break; + } + + + maxCol = Math.max(index, maxCol); + } + + copy(); + } // End of calcR + + // C연산 (열을 기준으로 정렬) + private static void calcC() { + tempMap = new int[N][N]; + int maxRow = -1; + + for (int i = 0; i < N; i++) { + HashMap colHashMap = new HashMap<>(); + PriorityQueue pque = new PriorityQueue<>(); + + for (int j = 0; j < N; j++) { + int num = map[j][i]; + if (num == 0) continue; + + colHashMap.put(num, colHashMap.getOrDefault(num, 0) + 1); + } + + // 횟수가 적은 순으로 나열 해야됨. + // key값을 기준으로 정렬. + Iterator> iter = colHashMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entrySet = (Map.Entry) iter.next(); + int key = entrySet.getKey(); + int value = entrySet.getValue(); + + pque.offer(new Number(key, value)); + } + + int index = -1; + while (!pque.isEmpty()) { + Number num = pque.poll(); + + tempMap[++index][i] = num.num; + if (index >= 100) break; + tempMap[++index][i] = num.freq; + if (index >= 100) break; + } + + + maxRow = Math.max(index, maxRow); + } + + copy(); + } // End of calcC + + private static void copy() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + map[i][j] = tempMap[i][j]; + } + } + } // End of copy } // End of Main class \ No newline at end of file diff --git "a/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" "b/2022/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" similarity index 100% rename from "11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" rename to "2022/11.10/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\251\200\354\251\241\355\225\234_\354\202\254\352\260\201\355\230\225.java" diff --git a/11.14/readme.md b/2022/11.14/readme.md similarity index 100% rename from 11.14/readme.md rename to 2022/11.14/readme.md diff --git "a/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" "b/2022/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" similarity index 100% rename from "11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" rename to "2022/11.14/\354\206\241\352\270\260\355\233\210/pgm_lv2_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.py" diff --git "a/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" "b/2022/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" similarity index 100% rename from "11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" rename to "2022/11.14/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11559_Puyo_Puyo.py" diff --git "a/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" "b/2022/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" similarity index 100% rename from "11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" rename to "2022/11.14/\354\235\264\354\225\204\353\246\204/11559_\353\277\214\354\232\224\353\277\214\354\232\224.cpp" diff --git "a/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" "b/2022/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" similarity index 100% rename from "11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" rename to "2022/11.14/\354\235\264\354\225\204\353\246\204/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.cpp" diff --git "a/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" "b/2022/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" similarity index 100% rename from "11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" rename to "2022/11.14/\354\240\225\355\230\270\354\241\260/\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255.java" diff --git "a/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" "b/2022/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" similarity index 100% rename from "11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" rename to "2022/11.14/\354\240\225\355\230\270\354\241\260/\353\277\214\354\232\224\353\277\214\354\232\224.java" diff --git "a/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" "b/2022/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" similarity index 100% rename from "11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" rename to "2022/11.14/\354\241\260\354\210\230\354\227\260/Puyo Puyo.kt" diff --git "a/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" "b/2022/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" similarity index 100% rename from "11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" rename to "2022/11.14/\354\241\260\354\210\230\354\227\260/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.kt" diff --git "a/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" "b/2022/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" similarity index 97% rename from "11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" rename to "2022/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" index 6623362..21fdbbf 100644 --- "a/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" +++ "b/2022/11.14/\354\265\234\354\260\275\354\230\201/Main_11559_Puyo_Puyo.java" @@ -1,162 +1,162 @@ -import java.io.*; -import java.util.*; - -// https://www.acmicpc.net/problem/11559 -// 상대방의 필드가 주어졌을 때, 연쇄가 몇 번 연속으로 일어날지 계산 -// 포인트 -> 터질 수 있는 뿌요가 여러 그룹이 있다면 동시에 터져야 하고 여러 그룹이 터지더라도 한번의 연쇄가 추가된다. - -public class Main_11559_Puyo_Puyo { - private static final int N = 12; - private static final int M = 6; - static char[][] map = new char[N][M]; - static char[][] tempMap; - static boolean[][] isVisited; - - static int[] dirX = {-1, 1, 0, 0}; - static int[] dirY = {0, 0, -1, 1}; - static List popColorCoorList; - - static class Coordinates { - int x; - int y; - int count; - - public Coordinates(int x, int y, int count) { - this.x = x; - this.y = y; - this.count = count; - } - - public Coordinates(int x, int y) { - this.x = x; - this.y = y; - } - } // End of Coordinates - - - public static void main(String[] args) throws Exception { - System.setIn(new FileInputStream("res/11559.txt")); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - popColorCoorList = new ArrayList<>(); - - for (int i = 0; i < N; i++) { - String temp = br.readLine(); - for (int j = 0; j < M; j++) { - map[i][j] = temp.charAt(j); - } - } - - int result = 0; // 최종 결과값 - for (; ; ) { - // 터트릴 수 있는 것들을 한번에 터트려야 하므로, 터지는 곳의 좌표를 모두 저장. - popColorCoorList = new ArrayList<>(); - isVisited = new boolean[N][M]; - - for (int i = N - 1; i >= 0; i--) { - for (int j = 0; j < M; j++) { - if (map[i][j] != '.' && !isVisited[i][j]) { - findColor(i, j, map[i][j]); - } - } - } - - // list에 들어가있는 블럭들을 터트리는 작업 진행 - if (popColorCoorList.isEmpty()) { - break; - } else { - result++; - popColor(); // 색깔 터트리기 - gravityApplication(); // 중력으로 아래로 당기기 - copy(); // 다시 배열 복사해주기. - } - } - - System.out.print(result); - } // End of main - - // 1. 현재 주어진 상황에서 어떤 색깔이 터질 수 있는지를 체크, - // 2. 터지고 나면 뿌요들을 내리는 작업을 시작. (내릴 때는 열을 기준으로 내린다.) -> 배열 복사 - private static boolean findColor(int x, int y, char color) { - Queue que = new LinkedList<>(); - List tempList = new ArrayList<>(); - - que.offer(new Coordinates(x, y, 0)); - tempList.add(new Coordinates(x, y)); - isVisited[x][y] = true; - - int totalCount = 1; - while (!que.isEmpty()) { - Coordinates pollCoor = que.poll(); - - for (int i = 0; i < 4; i++) { - int nowX = dirX[i] + pollCoor.x; - int nowY = dirY[i] + pollCoor.y; - int nowCount = pollCoor.count; - - if (!rangeCheck(nowX, nowY) || isVisited[nowX][nowY] || map[nowX][nowY] != color) continue; - - que.offer(new Coordinates(nowX, nowY, ++nowCount)); - tempList.add(new Coordinates(nowX, nowY)); - isVisited[nowX][nowY] = true; - totalCount++; - } - } - - if (totalCount >= 4) { - // tempList에 저장해뒀다가 전체 터트릴 수 있는 색깔의 블럭이 4개이상일 경우에만 list에 저장함. - for (Coordinates coor : tempList) { - popColorCoorList.add(new Coordinates(coor.x, coor.y)); - } - - return true; - } - - return false; - } // End of findColor - - private static void popColor() { - // 터트릴 수 있는 색깔들 터트리고 .으로 변경 - - for (Coordinates coor : popColorCoorList) { - map[coor.x][coor.y] = '.'; - } - } // End of popColor - - private static void gravityApplication() { - tempMap = new char[N][M]; - - for (int i = 0; i < M; i++) { - // 빈 공간이 있을 경우, 밑으로 내려줌 - Deque deque = new LinkedList<>(); - for (int j = N - 1; j >= 0; j--) { - - if (map[j][i] != '.') { - deque.offerFirst(map[j][i]); - } - } - - int index = N - 1; - while (!deque.isEmpty()) { - char ch = deque.pollLast(); - tempMap[index--][i] = ch; - } - - for (int j = index; j >= 0; j--) { - tempMap[j][i] = '.'; - } - } - - } // End of gravityApplication - - private static void copy() { - for (int i = 0; i < N; i++) { - for (int j = 0; j < M; j++) { - map[i][j] = tempMap[i][j]; - } - } - } // End of copy - - private static boolean rangeCheck(int nowX, int nowY) { - return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; - } // End of rangeCheck -} // End of Main class +import java.io.*; +import java.util.*; + +// https://www.acmicpc.net/problem/11559 +// 상대방의 필드가 주어졌을 때, 연쇄가 몇 번 연속으로 일어날지 계산 +// 포인트 -> 터질 수 있는 뿌요가 여러 그룹이 있다면 동시에 터져야 하고 여러 그룹이 터지더라도 한번의 연쇄가 추가된다. + +public class Main_11559_Puyo_Puyo { + private static final int N = 12; + private static final int M = 6; + static char[][] map = new char[N][M]; + static char[][] tempMap; + static boolean[][] isVisited; + + static int[] dirX = {-1, 1, 0, 0}; + static int[] dirY = {0, 0, -1, 1}; + static List popColorCoorList; + + static class Coordinates { + int x; + int y; + int count; + + public Coordinates(int x, int y, int count) { + this.x = x; + this.y = y; + this.count = count; + } + + public Coordinates(int x, int y) { + this.x = x; + this.y = y; + } + } // End of Coordinates + + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/11559.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + popColorCoorList = new ArrayList<>(); + + for (int i = 0; i < N; i++) { + String temp = br.readLine(); + for (int j = 0; j < M; j++) { + map[i][j] = temp.charAt(j); + } + } + + int result = 0; // 최종 결과값 + for (; ; ) { + // 터트릴 수 있는 것들을 한번에 터트려야 하므로, 터지는 곳의 좌표를 모두 저장. + popColorCoorList = new ArrayList<>(); + isVisited = new boolean[N][M]; + + for (int i = N - 1; i >= 0; i--) { + for (int j = 0; j < M; j++) { + if (map[i][j] != '.' && !isVisited[i][j]) { + findColor(i, j, map[i][j]); + } + } + } + + // list에 들어가있는 블럭들을 터트리는 작업 진행 + if (popColorCoorList.isEmpty()) { + break; + } else { + result++; + popColor(); // 색깔 터트리기 + gravityApplication(); // 중력으로 아래로 당기기 + copy(); // 다시 배열 복사해주기. + } + } + + System.out.print(result); + } // End of main + + // 1. 현재 주어진 상황에서 어떤 색깔이 터질 수 있는지를 체크, + // 2. 터지고 나면 뿌요들을 내리는 작업을 시작. (내릴 때는 열을 기준으로 내린다.) -> 배열 복사 + private static boolean findColor(int x, int y, char color) { + Queue que = new LinkedList<>(); + List tempList = new ArrayList<>(); + + que.offer(new Coordinates(x, y, 0)); + tempList.add(new Coordinates(x, y)); + isVisited[x][y] = true; + + int totalCount = 1; + while (!que.isEmpty()) { + Coordinates pollCoor = que.poll(); + + for (int i = 0; i < 4; i++) { + int nowX = dirX[i] + pollCoor.x; + int nowY = dirY[i] + pollCoor.y; + int nowCount = pollCoor.count; + + if (!rangeCheck(nowX, nowY) || isVisited[nowX][nowY] || map[nowX][nowY] != color) continue; + + que.offer(new Coordinates(nowX, nowY, ++nowCount)); + tempList.add(new Coordinates(nowX, nowY)); + isVisited[nowX][nowY] = true; + totalCount++; + } + } + + if (totalCount >= 4) { + // tempList에 저장해뒀다가 전체 터트릴 수 있는 색깔의 블럭이 4개이상일 경우에만 list에 저장함. + for (Coordinates coor : tempList) { + popColorCoorList.add(new Coordinates(coor.x, coor.y)); + } + + return true; + } + + return false; + } // End of findColor + + private static void popColor() { + // 터트릴 수 있는 색깔들 터트리고 .으로 변경 + + for (Coordinates coor : popColorCoorList) { + map[coor.x][coor.y] = '.'; + } + } // End of popColor + + private static void gravityApplication() { + tempMap = new char[N][M]; + + for (int i = 0; i < M; i++) { + // 빈 공간이 있을 경우, 밑으로 내려줌 + Deque deque = new LinkedList<>(); + for (int j = N - 1; j >= 0; j--) { + + if (map[j][i] != '.') { + deque.offerFirst(map[j][i]); + } + } + + int index = N - 1; + while (!deque.isEmpty()) { + char ch = deque.pollLast(); + tempMap[index--][i] = ch; + } + + for (int j = index; j >= 0; j--) { + tempMap[j][i] = '.'; + } + } + + } // End of gravityApplication + + private static void copy() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + map[i][j] = tempMap[i][j]; + } + } + } // End of copy + + private static boolean rangeCheck(int nowX, int nowY) { + return nowX >= 0 && nowX < N && nowY >= 0 && nowY < M; + } // End of rangeCheck +} // End of Main class diff --git "a/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" "b/2022/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" similarity index 100% rename from "11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" rename to "2022/11.14/\354\265\234\354\260\275\354\230\201/Main_PRG_\353\213\244\353\246\254\353\245\274_\354\247\200\353\202\230\353\212\224_\355\212\270\353\237\255.java" diff --git a/11.17/readme.md b/2022/11.17/readme.md similarity index 100% rename from 11.17/readme.md rename to 2022/11.17/readme.md diff --git "a/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" "b/2022/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" similarity index 100% rename from "11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" rename to "2022/11.17/\354\206\241\352\270\260\355\233\210/pgm_lv2_\354\202\274\352\260\201_\353\213\254\355\214\275\354\235\264.py" diff --git "a/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" "b/2022/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" similarity index 100% rename from "11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" rename to "2022/11.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_17142_\354\227\260\352\265\254\354\206\2143.py" diff --git "a/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" "b/2022/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" similarity index 100% rename from "11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" rename to "2022/11.17/\354\235\264\354\225\204\353\246\204/\354\202\274\352\260\201\353\213\254\355\214\275\354\235\264.cpp" diff --git "a/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" "b/2022/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" similarity index 100% rename from "11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" rename to "2022/11.17/\354\241\260\354\210\230\354\227\260/\354\202\274\352\260\201 \353\213\254\355\214\275\354\235\264.kt" diff --git "a/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" "b/2022/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" similarity index 100% rename from "11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" rename to "2022/11.17/\354\241\260\354\210\230\354\227\260/\354\227\260\352\265\254\354\206\214 3.kt" diff --git "a/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" "b/2022/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" similarity index 100% rename from "11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" rename to "2022/11.17/\354\265\234\354\260\275\354\230\201/Main_17142_\354\227\260\352\265\254\354\206\214_3.java" diff --git a/12.29/readme.md b/2022/12.29/readme.md similarity index 100% rename from 12.29/readme.md rename to 2022/12.29/readme.md diff --git "a/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" "b/2022/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" similarity index 100% rename from "12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" rename to "2022/12.29/\354\206\241\352\270\260\355\233\210/pgm_lv2_\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.py" diff --git "a/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" "b/2022/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" similarity index 100% rename from "12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" rename to "2022/12.29/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1068_\355\212\270\353\246\254.py" diff --git "a/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" "b/2022/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" similarity index 100% rename from "12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" rename to "2022/12.29/\354\235\264\354\225\204\353\246\204/1068_\355\212\270\353\246\254.cpp" diff --git "a/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" "b/2022/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" similarity index 100% rename from "12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" rename to "2022/12.29/\354\235\264\354\225\204\353\246\204/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.cpp" diff --git "a/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" "b/2022/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" similarity index 100% rename from "12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" rename to "2022/12.29/\354\241\260\354\210\230\354\227\260/1068_\355\212\270\353\246\254.kt" diff --git "a/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" "b/2022/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" similarity index 100% rename from "12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" rename to "2022/12.29/\354\241\260\354\210\230\354\227\260/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" diff --git "a/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" "b/2022/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" similarity index 100% rename from "12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" rename to "2022/12.29/\354\265\234\354\260\275\354\230\201/Main 1068 \355\212\270\353\246\254.kt" diff --git "a/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" "b/2022/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" similarity index 100% rename from "12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" rename to "2022/12.29/\354\265\234\354\260\275\354\230\201/PRG \352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" diff --git "a/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" "b/2022/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" similarity index 100% rename from "12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" rename to "2022/12.29/\355\231\251\354\247\200\354\233\220/\352\264\204\355\230\270\355\232\214\354\240\204\355\225\230\352\270\260.java" diff --git "a/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" "b/2022/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" similarity index 100% rename from "12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" rename to "2022/12.29/\355\231\251\354\247\200\354\233\220/\355\212\270\353\246\254.java" diff --git a/2023/03.09/README.md b/2023/03.13/README.md similarity index 100% rename from 2023/03.09/README.md rename to 2023/03.13/README.md diff --git "a/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" "b/2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" similarity index 100% rename from "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" rename to "2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv3_\355\221\234\355\216\270\354\247\221_linked_list.py" diff --git "a/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" "b/2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" similarity index 100% rename from "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" rename to "2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.py" diff --git "a/2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" "b/2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" similarity index 100% rename from "2023/03.09/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" rename to "2023/03.13/\354\206\241\352\270\260\355\233\210/pgm_lv4_\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225_\355\232\250\354\234\250\354\213\244\355\214\250.py" diff --git "a/2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" "b/2023/03.13/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" similarity index 100% rename from "2023/03.09/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" rename to "2023/03.13/\354\234\240\354\212\271\354\232\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" "b/2023/03.13/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" similarity index 100% rename from "2023/03.09/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" rename to "2023/03.13/\354\235\264\354\225\204\353\246\204/\355\221\234\355\216\270\354\247\221.cpp" diff --git "a/2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" "b/2023/03.13/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" similarity index 100% rename from "2023/03.09/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" rename to "2023/03.13/\354\235\264\354\225\204\353\246\204/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.cpp" diff --git "a/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" "b/2023/03.13/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" similarity index 100% rename from "2023/03.09/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" rename to "2023/03.13/\354\240\225\355\230\270\354\241\260/\355\221\234\355\216\270\354\247\221.java" diff --git "a/2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" "b/2023/03.13/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" similarity index 100% rename from "2023/03.09/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" rename to "2023/03.13/\354\240\225\355\230\270\354\241\260/\355\230\270\355\205\224\353\260\251\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" "b/2023/03.13/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" similarity index 100% rename from "2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" rename to "2023/03.13/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" diff --git "a/2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" "b/2023/03.13/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" similarity index 100% rename from "2023/03.09/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" rename to "2023/03.13/\354\241\260\354\210\230\354\227\260/\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.kt" diff --git "a/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" "b/2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" similarity index 100% rename from "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" rename to "2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\354\213\234\355\227\230\354\236\245_\353\202\230\353\210\204\352\270\260.java" diff --git "a/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" "b/2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" similarity index 100% rename from "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" rename to "2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\355\221\234_\355\216\270\354\247\221.java" diff --git "a/2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" "b/2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" similarity index 100% rename from "2023/03.09/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" rename to "2023/03.13/\354\265\234\354\260\275\354\230\201/PRG_\355\230\270\355\205\224_\353\260\251_\353\260\260\354\240\225.java" From 6200855fc3fc47bf9d02eb96755fc44d3f6a8ff9 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 13 Mar 2023 20:51:55 +0900 Subject: [PATCH 556/822] Create README.md --- 2023/03.16/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 2023/03.16/README.md diff --git a/2023/03.16/README.md b/2023/03.16/README.md new file mode 100644 index 0000000..c50aee2 --- /dev/null +++ b/2023/03.16/README.md @@ -0,0 +1,6 @@ +# 3.16(목) 스터디 + +- 프로그래머스 + - [단어변환](https://school.programmers.co.kr/learn/courses/30/lessons/43163) +- SWEA + - [동아리실 관리하기](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWBnFuhqxE8DFAWr) From d03b6c6e8ffcbf7ae210988b87de6ede19c525ec Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 13 Mar 2023 22:39:58 +0900 Subject: [PATCH 557/822] =?UTF-8?q?SOLVE=20:=20=EB=8B=A8=EC=96=B4=5F?= =?UTF-8?q?=EB=B3=80=ED=99=98.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\226\264_\353\263\200\355\231\230.kt" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" diff --git "a/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" "b/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" new file mode 100644 index 0000000..b1ed1ad --- /dev/null +++ "b/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" @@ -0,0 +1,56 @@ +import java.util.LinkedList +import java.util.Queue + +fun main() { + Solution().solution(begin = "hit", target = "cog", words = arrayOf("hot", "dot", "dog", "lot", "log")) +} + +class Solution { + fun solution(begin: String, target: String, words: Array): Int { + var answer = 0 + val queue: Queue>> = LinkedList() + if (words.contains(target)) { // 글자 수 하나 다른 단어 선택하기 + for (i in words.indices) { + var count = 0 + for (j in begin.indices) { + if (begin[j] != words[i][j]) count++ + if (count > 1) break + } + if (count == 1) queue.add(Pair(words[i], arrayListOf(i))) + } + answer = bfs(queue, target, words) // 탐색 시작 + } + return answer + } + + fun bfs(queue: Queue>>, target: String, words: Array): Int { + var count = 1 + + while (queue.isNotEmpty()) { + for (i in queue.indices) { + val info = queue.poll() + val changeWord = info.first // 바뀐 단어 + val indexList = info.second // 방문한 인덱스 리스트 + + if (changeWord == target) return count // poll 했을 때 target이면 count 반환 + + for (j in words.indices) { + if (!indexList.contains(j)) { // 중복 제거 + var count = 0 + for (k in changeWord.indices) { + if (changeWord[k] != words[j][k]) count++ + if (count > 1) break + } + + if (count == 1) { // 문자가 하나만 다르면 queue에 add + indexList.add(j) + queue.add(Pair(words[j], indexList)) + } + } + } + } + count++ + } + return count + } +} \ No newline at end of file From 0dd9e10bfa85059e860c725f176fedf77887622d Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 13 Mar 2023 22:58:09 +0900 Subject: [PATCH 558/822] =?UTF-8?q?SOLVE=20:=20=EB=8B=A8=EC=96=B4=5F?= =?UTF-8?q?=EB=B3=80=ED=99=98.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\213\250\354\226\264_\353\263\200\355\231\230.kt" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" "b/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" index b1ed1ad..4b8df30 100644 --- "a/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" +++ "b/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.kt" @@ -36,13 +36,13 @@ class Solution { for (j in words.indices) { if (!indexList.contains(j)) { // 중복 제거 - var count = 0 + var diffcnt = 0 for (k in changeWord.indices) { - if (changeWord[k] != words[j][k]) count++ - if (count > 1) break + if (changeWord[k] != words[j][k]) diffcnt++ + if (diffcnt > 1) break } - if (count == 1) { // 문자가 하나만 다르면 queue에 add + if (diffcnt == 1) { // 문자가 하나만 다르면 queue에 add indexList.add(j) queue.add(Pair(words[j], indexList)) } From 2af2aece709e6c4dded716249c70c0eda0403bb8 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 13 Mar 2023 23:08:28 +0900 Subject: [PATCH 559/822] =?UTF-8?q?SOLVE=20:=20=EB=8B=A8=EC=96=B4=5F?= =?UTF-8?q?=EB=B3=80=ED=99=98.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\226\264_\353\263\200\355\231\230.java" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.java" diff --git "a/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.java" "b/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.java" new file mode 100644 index 0000000..cb09a9b --- /dev/null +++ "b/2023/03.16/\354\241\260\354\210\230\354\227\260/\353\213\250\354\226\264_\353\263\200\355\231\230.java" @@ -0,0 +1,85 @@ +import java.util.*; + +public class Problem { + public static void main(String[] args) { + new SolutionJava().solution("hit","cog", new String[]{"hot", "dot", "dog", "lot", "log", "cog"}); + } +} + +class WordInfo{ + String word; + ArrayList indexList = new ArrayList(); + + public WordInfo(String word, ArrayList indexList) { + this.word = word; + this.indexList = indexList; + } +} +class SolutionJava { + public int solution(String begin, String target, String[] words) { + int answer = 0; + Queue queue = new LinkedList<>(); + + boolean isExist = false; + + for (int i = 0; i < words.length; i++) { // 단어가 존재하는지 체크 + if (words[i].equals(target)) { + isExist = true; + break; + } + } + + if (isExist){ + for (int i = 0; i < words.length; i++) { // 글자 수 하나 다른 단어 선택하기 + int count = 0; + for (int j = 0; j < begin.length(); j++) { + if (begin.charAt(j) != words[i].charAt(j)) count++; + if (count > 1) break; + } + + if (count == 1){ + ArrayList indexList = new ArrayList<>(); + indexList.add(i); + queue.add(new WordInfo(words[i],indexList)); + } + + } + answer = bfs(queue,target,words); + } + + return answer; + } + + public int bfs(Queue queue, String target, String[] words){ + int count = 1; + + while (!queue.isEmpty()){ + for (int i = 0; i < queue.size(); i++) { + WordInfo info = queue.poll(); + String changeWord = info.word; // 바뀐 단어 + ArrayList indexList = info.indexList; // 방문한 인덱스 리스트 + + if (changeWord.equals(target)) return count; // poll 했을 때 target이면 count 반환 + + for (int j = 0; j < words.length; j++) { + if (!indexList.contains(j)){ // 중복 제거 + int diffCnt = 0; + for (int k = 0; k < changeWord.length(); k++) { + if (changeWord.charAt(k) != words[j].charAt(k)) diffCnt++; + if (diffCnt > 1) break; + } + + if (diffCnt == 1){ // 문자가 하나만 다르면 queue에 add + indexList.add(j); + queue.add(new WordInfo(words[j],indexList)); + } + } + } + } + count++; + } + return count; + } +} + + From 10a1094e0f1a3ef8a71a6dd8e80dceece4da91f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=95=84=EB=A6=84?= <72062916+Lee-Areum@users.noreply.github.com> Date: Sun, 19 Mar 2023 20:45:51 +0900 Subject: [PATCH 560/822] =?UTF-8?q?Create=20=EB=8B=A8=EC=96=B4=EB=B3=80?= =?UTF-8?q?=ED=99=98.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\226\264\353\263\200\355\231\230.cpp" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "2023/03.16/\354\235\264\354\225\204\353\246\204/\353\213\250\354\226\264\353\263\200\355\231\230.cpp" diff --git "a/2023/03.16/\354\235\264\354\225\204\353\246\204/\353\213\250\354\226\264\353\263\200\355\231\230.cpp" "b/2023/03.16/\354\235\264\354\225\204\353\246\204/\353\213\250\354\226\264\353\263\200\355\231\230.cpp" new file mode 100644 index 0000000..5d47cbe --- /dev/null +++ "b/2023/03.16/\354\235\264\354\225\204\353\246\204/\353\213\250\354\226\264\353\263\200\355\231\230.cpp" @@ -0,0 +1,39 @@ +#include +#include +#include + +using namespace std; + +bool canChange(string begin, string compare) { + int count = 0; + for (int i = 0; i < begin.size(); i++) { + if (begin[i] != compare[i]) { + count++; + if (count > 1) return false; + } + } + return true; +} + +int solution(string begin, string target, vector words) { + queue> q; + q.push({ begin,0 }); + bool visited[51] = { false }; + while (!q.empty()) { + string str = q.front().first; + int cnt = q.front().second; + q.pop(); + if (str.compare(target) == 0) { + return cnt; + } + for (int i = 0; i < words.size(); i++) { + if (!visited[i]) { + if (canChange(str, words[i])) { + q.push({ words[i],cnt + 1 }); + visited[i] = true; + } + } + } + } + return 0; +} From 6d0c79a1b3d6514a97bb36081c5b77db5916d6eb Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 22 Mar 2023 02:26:38 +0900 Subject: [PATCH 561/822] =?UTF-8?q?Create=20=EB=8B=A8=EC=96=B4=EB=B3=80?= =?UTF-8?q?=ED=99=98.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\226\264\353\263\200\355\231\230.java" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "2023/03.16/\354\240\225\355\230\270\354\241\260/\353\213\250\354\226\264\353\263\200\355\231\230.java" diff --git "a/2023/03.16/\354\240\225\355\230\270\354\241\260/\353\213\250\354\226\264\353\263\200\355\231\230.java" "b/2023/03.16/\354\240\225\355\230\270\354\241\260/\353\213\250\354\226\264\353\263\200\355\231\230.java" new file mode 100644 index 0000000..0e4910e --- /dev/null +++ "b/2023/03.16/\354\240\225\355\230\270\354\241\260/\353\213\250\354\226\264\353\263\200\355\231\230.java" @@ -0,0 +1,61 @@ +public class 단어변환 { + + public static void main(String[] args) { + String begin = "hit"; + String target = "hhh"; + String[] words = {"hhh", "hht"}; + + Solution s = new Solution(); + System.out.println(s.solution(begin, target, words)); + } + + static class Solution { + static int answer; + + public int solution(String begin, String target, String[] words) { + answer = Integer.MAX_VALUE; + + for (int i = 0; i < words.length; i++) { + if (words[i].equals(target)) { + getResult(0, begin, target, words, new boolean[words.length]); + break; + } + } + + if (answer == Integer.MAX_VALUE) { + answer = 0; + } + + return answer; + } + + static void getResult(int cnt, String curWord, String target, String[] words, boolean[] vis) { + if (curWord.equals(target)) { + answer = Math.min(answer, cnt); + return; + } + + for (int i = 0; i < curWord.length(); i++) { + String curTemp = curWord.substring(0, i) + curWord.substring(i + 1); + int check = 0; + for (int j = 0; j < words.length; j++) { + if (i == 1 && j == 1) { + } + if (!vis[j]) { + check++; + String wordTemp = words[j].substring(0,i) + words[j].substring(i+1); + + if (curTemp.equals(wordTemp)) { + vis[j] = true; + getResult(cnt + 1, words[j], target, words, vis); + vis[j] = false; + } + } + } + if (check == 0) { + return; + } + } + } + } +} From 840b8ed898003a073cf39d16deaf7776a4a4257b Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 22 Mar 2023 02:27:04 +0900 Subject: [PATCH 562/822] =?UTF-8?q?Create=20=EB=8F=99=EC=95=84=EB=A6=AC?= =?UTF-8?q?=EC=8B=A4=EA=B4=80=EB=A6=AC=ED=95=98=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\246\254\355\225\230\352\270\260.java" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "2023/03.16/\354\240\225\355\230\270\354\241\260/\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.java" diff --git "a/2023/03.16/\354\240\225\355\230\270\354\241\260/\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.java" "b/2023/03.16/\354\240\225\355\230\270\354\241\260/\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.java" new file mode 100644 index 0000000..b6b6c7a --- /dev/null +++ "b/2023/03.16/\354\240\225\355\230\270\354\241\260/\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.java" @@ -0,0 +1,46 @@ +import java.io.*; +import java.util.*; + +public class 동아리실관리하기_3316 { + static String str; + static int answer; + static int[][] cases; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= t; tc++) { + str = br.readLine(); + cases = new int[str.length()][16]; + answer = 0; + getResult(); + System.out.printf("#%d %d\n", tc, answer); + } + } + + static void getResult() { + for (int day = 0; day < cases.length; day++) { + int master = 1 << str.charAt(day) - 'A'; + for (int people = 1; people <= 15; people++) { + if (day == 0) { + if ((people & 1) != 0 && (people & master) != 0) { //첫째날 키잡이(A)와 담당자가 속해있는 경우만 1 입력 + cases[day][people] = 1; + } + } else { + if (cases[day - 1][people] != 0) { // 전날까지 가능했던 경우의 수 중 + for (int curcase = 1; curcase <= 15; curcase++) { + if ((curcase & master) != 0 && ((people & curcase) != 0)) { // 담당자가 참석하고 전날 참석했던 인원 중 일부라도 참석한 경우의 수 + cases[day][curcase] = (cases[day][curcase] + cases[day - 1][people]) % 1000000007; //나누면서 더하지 않으면 음수 값이 나옴 + } + } + } + } + } + + } + + for (int i = 1; i < 16; i++) { + answer = (answer + cases[str.length() - 1][i]) % 1000000007; + } + } +} From de7b44888fba421d5418f00b34a3f0e8f4121ae5 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 12 Apr 2023 01:19:45 +0900 Subject: [PATCH 563/822] =?UTF-8?q?=EC=95=84=EB=AC=B4=EB=8F=84=20=EB=82=98?= =?UTF-8?q?=EB=9E=91=20=EC=95=88=EB=86=80=EC=95=84=EC=A4=98..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\270\265\352\261\264\353\254\274.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/04.12/\354\240\225\355\230\270\354\241\260/\352\263\240\354\270\265\352\261\264\353\254\274.java" diff --git "a/2023/04.12/\354\240\225\355\230\270\354\241\260/\352\263\240\354\270\265\352\261\264\353\254\274.java" "b/2023/04.12/\354\240\225\355\230\270\354\241\260/\352\263\240\354\270\265\352\261\264\353\254\274.java" new file mode 100644 index 0000000..a6aa45a --- /dev/null +++ "b/2023/04.12/\354\240\225\355\230\270\354\241\260/\352\263\240\354\270\265\352\261\264\353\254\274.java" @@ -0,0 +1,40 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 고층건물_1027 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + int[] arr = new int[N]; + int[] cnt = new int[N]; + int ans = 0; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + for (int i = 0; i < N - 1; i++) { + cnt[i]++; + cnt[i + 1]++; + double slope = arr[i + 1] - arr[i]; + for (int j = i + 2; j < N; j++) { + double nextSlope = (double)(arr[j] - arr[i])/(j-i); + if(slope >= nextSlope) continue; + slope = nextSlope; + cnt[i]++; + cnt[j]++; + } + } + + Arrays.sort(cnt); + System.out.println(cnt[cnt.length-1]); + } +} + + From acd1ee98b1bba24ad6484dd24a9c68011cbe56ea Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 12 Apr 2023 23:28:04 +0900 Subject: [PATCH 564/822] =?UTF-8?q?=EC=95=84=EB=AC=B4=EB=8F=84=20=EB=82=98?= =?UTF-8?q?=EB=9E=91=20=EC=95=88=EB=86=80=EC=95=84=EC=A4=98...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\236\250\355\224\204_1034.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/04.12/\354\240\225\355\230\270\354\241\260/\353\236\250\355\224\204_1034.java" diff --git "a/2023/04.12/\354\240\225\355\230\270\354\241\260/\353\236\250\355\224\204_1034.java" "b/2023/04.12/\354\240\225\355\230\270\354\241\260/\353\236\250\355\224\204_1034.java" new file mode 100644 index 0000000..7759520 --- /dev/null +++ "b/2023/04.12/\354\240\225\355\230\270\354\241\260/\353\236\250\355\224\204_1034.java" @@ -0,0 +1,40 @@ +import java.nio.Buffer; +import java.util.*; +import java.io.*; + +public class 램프_1034 { + static int N, M, K, ans; + static Map map; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + map = new HashMap<>(); + ans = 0; + for (int i = 0; i < N; i++) { + String str = br.readLine(); + if(map.containsKey(str)){ + map.replace(str, map.get(str) + 1); + } else { + map.put(str, 1); + } + } + K = Integer.parseInt(br.readLine()); + + for (String row: map.keySet()){ + int cnt = 0; + for(int i=0; i= cnt && (K-cnt) %2 == 0){ + ans = Math.max(ans, map.get(row)); + } + } + + System.out.println(ans); + } +} From e69ffe1646e2396724fa26702ead94fe5462509f Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 18 Apr 2023 00:06:07 +0900 Subject: [PATCH 565/822] =?UTF-8?q?=EC=95=84=EB=AC=B4=EB=8F=84=20=EB=82=98?= =?UTF-8?q?=EB=9E=91=20=EC=95=88=EB=86=80=EC=95=84=EC=A4=98....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...261\260\354\247\223\353\247\220_1043.java" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" diff --git "a/2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" "b/2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" new file mode 100644 index 0000000..963c77f --- /dev/null +++ "b/2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" @@ -0,0 +1,101 @@ +import java.io.*; +import java.util.*; + +public class 거짓말_1043 { + static int[] parents; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int ans = 0; + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + + parents = new int[N + 1]; + boolean[] knowReal = new boolean[N + 1]; + HashSet[] party = new HashSet[M + 1]; + + for (int i = 1; i <= M; i++) { + party[i] = new HashSet<>(); + } + + //진실을 아는 사람 + st = new StringTokenizer(br.readLine()); + int knowCnt = Integer.parseInt(st.nextToken()); + for (int i = 1; i <= knowCnt; i++) { + knowReal[Integer.parseInt(st.nextToken())] = true; + } + + for (int i = 1; i <= N; i++) { + parents[i] = i; + } + + //사람들마다 연관관계 지어줌(union-find) + for (int i = 1; i <= M; i++) { + st = new StringTokenizer(br.readLine()); + int partyCnt = Integer.parseInt(st.nextToken()); + + if (partyCnt <= 1) { + party[i].add(Integer.parseInt(st.nextToken())); + } else { + int[] temp = new int[partyCnt]; + for (int j = 0; j < partyCnt; j++) { + temp[j] = Integer.parseInt(st.nextToken()); + } + + for (int j = 0; j < partyCnt-1; j++) { + int a = temp[j]; + int b = temp[j + 1]; + if (find(a) != find(b)) { //둘의 parent가 같지 않으면, 즉 연관 관계가 없으면 관계 만들어줌 + union(a, b); + } + party[i].add(a); + party[i].add(b); + } + } + } + + //진실을 아는 사람과 함께 파티에 참석한적 있는지 체크 + boolean[] vis = new boolean[N + 1]; //불필요한 탐색 방지 + for (int i = 1; i <= N; i++) { + if (knowReal[i] && !vis[i]) { //진실을 아는 사람이면 + int root = find(i); //연관관계 중 가장 최상위 부모 + for (int j = 1; j <= N; j++) { + if (find(j) == root) { //j번째 사람이 root와 관계가 있으면 진실을 아는 사람과 같이 파티에 참석한 적 있는 것 + knowReal[j] = true; + vis[j] = true; + } + } + } + } + + //가능한 파티 수를 구함 + for (int i = 1; i <= M; i++) { + boolean check = true; + for (int j : party[i]) { + if (knowReal[j]) { + check = false; + break; + } + } + if (check) { + ans++; + } + } + + System.out.println(ans); + } + + static int find(int num) { + if (parents[num] == num) { + return parents[num]; + } + parents[num] = find(parents[num]); + return parents[num]; + } + + static void union(int a, int b) { + parents[find(b)] = a; + } +} From 1d54793cedb27fbb29d821c2ab7ef128bba3899e Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:34:54 +0900 Subject: [PATCH 566/822] =?UTF-8?q?=EC=95=84=EB=AC=B4=EB=8F=84=20=EB=82=98?= =?UTF-8?q?=EB=9E=91=20=EC=95=88=EB=86=80=EC=95=84=EC=A4=98.....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...260\200\353\245\264\354\271\250_1062.java" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "2023/04.20/\354\240\225\355\230\270\354\241\260/\352\260\200\353\245\264\354\271\250_1062.java" diff --git "a/2023/04.20/\354\240\225\355\230\270\354\241\260/\352\260\200\353\245\264\354\271\250_1062.java" "b/2023/04.20/\354\240\225\355\230\270\354\241\260/\352\260\200\353\245\264\354\271\250_1062.java" new file mode 100644 index 0000000..28ddc12 --- /dev/null +++ "b/2023/04.20/\354\240\225\355\230\270\354\241\260/\352\260\200\353\245\264\354\271\250_1062.java" @@ -0,0 +1,67 @@ +import java.io.*; +import java.util.*; + +public class 가르침_1062 { + static boolean[] vis; + static int N, K, ans; + static String[] str; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + ans = 0; + vis = new boolean[26]; + str = new String[N]; + + if (K < 5) { //K < 5 이면 읽을 수 있는 단어 없음 + System.out.println("0"); + } else if (K == 26) { //K==26이면 모든 단어 다 읽을 수 있음 + System.out.println(N); + } else { + for (int i = 0; i < N; i++) { + str[i] = br.readLine(); + } + vis['a' - 'a'] = true; + vis['n' - 'a'] = true; + vis['t' - 'a'] = true; + vis['i' - 'a'] = true; + vis['c' - 'a'] = true; + + combination(0, 0, 26, K - 5); + System.out.println(ans); + } + } + + //조합으로 K-5개의 알파벳 뽑아서 가능한 단어 추출 + static void combination(int index, int start, int n, int m) { + if (index == m) { + int result = 0; + for (int i = 0; i < N; i++) { + boolean possible = true; + for (int j = 4; j < str[i].length() - 4; j++) { + if (!vis[str[i].charAt(j) - 'a']) { + possible = false; + break; + } + } + if (possible) { + result++; + } + } + ans = Math.max(ans, result); + return; + } + + for (int i = start; i < n; i++) { + if (!vis[i]) { + vis[i] = true; + combination(index + 1, i+1, n, m); + vis[i] = false; + } + } + + } +} From ad294837cffba2493229d8616c02dba2bf16ba68 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 21 Apr 2023 00:35:38 +0900 Subject: [PATCH 567/822] =?UTF-8?q?=EC=95=84=EB=AC=B4=EB=8F=84=20=EB=82=98?= =?UTF-8?q?=EB=9E=91=20=EC=95=88=EB=86=80=EC=95=84=EC=A4=98....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\352\261\260\354\247\223\353\247\220_1043.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" => "2023/04.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" (100%) diff --git "a/2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" "b/2023/04.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" similarity index 100% rename from "2023/4.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" rename to "2023/04.17/\354\240\225\355\230\270\354\241\260/\352\261\260\354\247\223\353\247\220_1043.java" From baa2b939fac4a8da68f526d4f90f498f9260d16d Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 27 Apr 2023 23:22:06 +0900 Subject: [PATCH 568/822] =?UTF-8?q?=EC=95=84=EB=AC=B4=EB=8F=84=20=EB=82=98?= =?UTF-8?q?=EB=9E=91=20=EC=95=88=EB=86=80=EC=95=84=EC=A4=98......?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\223\234\354\204\236\352\270\260.java" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "2023/04.26/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\354\204\236\352\270\260.java" diff --git "a/2023/04.26/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\354\204\236\352\270\260.java" "b/2023/04.26/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\354\204\236\352\270\260.java" new file mode 100644 index 0000000..75aece8 --- /dev/null +++ "b/2023/04.26/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\354\204\236\352\270\260.java" @@ -0,0 +1,74 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 카드섞기_1091 { + static int[] initCard, curCard, beforeCard, p, s; + static ArrayList[] resultCard; + static int N, ans; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + ans = 0; + initCard = new int[N]; + curCard = new int[N]; + beforeCard = new int[N]; + p = new int[N]; + s = new int[N]; + resultCard = new ArrayList[3]; + for (int i = 0; i < 3; i++) { + resultCard[i] = new ArrayList(); + } + + StringTokenizer st1 = new StringTokenizer(br.readLine()); + StringTokenizer st2 = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + p[i] = Integer.parseInt(st1.nextToken()); + s[i] = Integer.parseInt(st2.nextToken()); + initCard[i] = i; + curCard[i] = i; + beforeCard[i] = i; + } + + for (int i = 0; i < N; i++) { //정답 카드 -> 각 번호의 사람들이 가질 수 있는 카드를 list로 넣어줌 + + resultCard[p[i]].add(i); + } + + while (true) { + if (isDone()) break; + if (ans > 0 && Arrays.equals(curCard, initCard)) { //종료 조건 : 섞은 현재 카드가 다시 맨 처음 카드로 돌아왔을 경우 + ans = -1; + break; + } + + ans++; + for (int i = 0; i < N; i++) { //카드 섞기 + curCard[s[i]] = beforeCard[i]; + } + + for (int i = 0; i < N; i++) { //다음 턴에서 섞을 때를 위해 현재 카드를 beforeCard에 저장 + beforeCard[i] = curCard[i]; + } + } + + System.out.println(ans); + } + + static boolean isDone() { //각 번호의 사람이 알맞게 카드를 갖고있는지 체크 + int cnt = 0; + for (int i = 0; i < N; i++) { + if (resultCard[i % 3].contains(curCard[i])) { + cnt++; + } + } + + if (cnt == N) return true; + else return false; + } +} From f9a61279c951e0ce0821eecaf14ef1e124696208 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 3 May 2023 00:08:34 +0900 Subject: [PATCH 569/822] =?UTF-8?q?=ED=85=9C=ED=8F=AC=20=EB=A7=9E=EC=B6=B0?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\223\234\354\204\236\352\270\260.py" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/04.26/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1091_\354\271\264\353\223\234\354\204\236\352\270\260.py" diff --git "a/2023/04.26/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1091_\354\271\264\353\223\234\354\204\236\352\270\260.py" "b/2023/04.26/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1091_\354\271\264\353\223\234\354\204\236\352\270\260.py" new file mode 100644 index 0000000..ff28a07 --- /dev/null +++ "b/2023/04.26/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1091_\354\271\264\353\223\234\354\204\236\352\270\260.py" @@ -0,0 +1,44 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) +p = list(map(int, input().split())) # 결과가 될 배열 +s = list(map(int, input().split())) +answer = 0 + +card = [] + +for i in range(n): + card.append(i) + +while True: + flag = False + + for i in range(n): + # 결과와 같지 않으면 섞어준다 + if card[i] % 3 != p[i]: + answer += 1 + temp = [] + + # j번째 카드는 s[j]로 이동한다 + for j in range(n): + # 이동한 카드가 자기 자리로 이동하지 않으면 flag는 True + # 증명 + # https://injae-kim.github.io/problem_solving/2020/02/20/baekjoon-1091.html + if s[card[j]] != j: + flag = True + + temp.append(s[card[j]]) + + card = temp + + break + else: + break + + if not flag: + answer = -1 + break + +print(answer) From f9604a1366d0a69b0fb63685a17a8a3e172a8b1c Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 4 May 2023 00:04:36 +0900 Subject: [PATCH 570/822] =?UTF-8?q?=ED=85=9C=ED=8F=AC=20=EB=A7=9E=EC=B6=B0?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2_\352\260\200\353\245\264\354\271\250.py" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "2023/04.20/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250.py" diff --git "a/2023/04.20/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250.py" "b/2023/04.20/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250.py" new file mode 100644 index 0000000..a53d19f --- /dev/null +++ "b/2023/04.20/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1062_\352\260\200\353\245\264\354\271\250.py" @@ -0,0 +1,57 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, k = map(int, input().split()) +words = [set(list(input())) for _ in range(n)] +answer = 0 + + +def solution(n, k, words): + global answer + # a n t i c + # 5 미만이면 배울 수 있는게 없다. + if k < 5: + print(answer) + return + elif k == 26: + print(n) + return + else: + alphabet = [False] * 26 + + for char in ('a', 'n', 't', 'i', 'c'): + alphabet[ord(char) - ord('a')] = True + + dfs(0, 0, k, words, alphabet) + print(answer) + return + + +def dfs(index, count, k, words, alphabet): + global answer + # 탈출 조건 + if count == k - 5: + tempAnswer = 0 + for word in words: + flag = True + # 알파벳을 배웠나 체크 + for c in word: + if not alphabet[ord(c) - ord('a')]: + flag = False + break + # 모두 배웠으면 +1 + if flag == True: + tempAnswer += 1 + answer = max(answer, tempAnswer) + return + + for i in range(index, 26): + # 안 배운 알파벳이면 배우고 원상 복구 + if not alphabet[i]: + alphabet[i] = True + dfs(i, count+1, k, words, alphabet) + alphabet[i] = False + + +solution(n, k, words) From c24e1815c9208c173e5532aa503a039968f527d5 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 6 May 2023 14:50:00 +0900 Subject: [PATCH 571/822] =?UTF-8?q?=ED=85=9C=ED=8F=AC=20=EB=A7=9E=EC=B6=B0?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3_\352\261\260\354\247\223\353\247\220.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "2023/04.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1043_\352\261\260\354\247\223\353\247\220.py" diff --git "a/2023/04.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1043_\352\261\260\354\247\223\353\247\220.py" "b/2023/04.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1043_\352\261\260\354\247\223\353\247\220.py" new file mode 100644 index 0000000..b5424c9 --- /dev/null +++ "b/2023/04.17/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1043_\352\261\260\354\247\223\353\247\220.py" @@ -0,0 +1,28 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, m = map(int, input().split()) + +truth = set(map(int, input().split()[1:])) + +party_list = [] + +for _ in range(m): + party_list.append(set(map(int, input().split()[1:]))) + +# 진실을 아는 사람 + 진실을 아는 사람과 같이 파티에 참가한 사람을 걸러야 함 +# 같이 참가한 사람 + 그 사람과 참가한 사람... +# 파티 회차마다 생기므로 m번 확인 해야됨 +for _ in range(m): + for party in party_list: + # 교집합이 있다면 진실을 아는 사람에 추가함 + if party & truth: + truth = truth.union(party) + +answer = 0 +for party in party_list: + if not party & truth: + answer += 1 + +print(answer) From 14d2ad95a32539e9fb3c894bcab133a8adcd772a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 7 May 2023 14:18:34 +0900 Subject: [PATCH 572/822] =?UTF-8?q?=ED=85=9C=ED=8F=AC=20=EB=A7=9E=EC=B6=B0?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\354\270\265\352\261\264\353\254\274.py" | 35 ++++++++++++++++++ ...\244\200_1034_\353\236\250\355\224\204.py" | 36 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 "2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1027_\352\263\240\354\270\265\352\261\264\353\254\274.py" create mode 100644 "2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1034_\353\236\250\355\224\204.py" diff --git "a/2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1027_\352\263\240\354\270\265\352\261\264\353\254\274.py" "b/2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1027_\352\263\240\354\270\265\352\261\264\353\254\274.py" new file mode 100644 index 0000000..5a75453 --- /dev/null +++ "b/2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1027_\352\263\240\354\270\265\352\261\264\353\254\274.py" @@ -0,0 +1,35 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) +buildings = list(map(int, input().split())) + + +def slope(x1, y1, x2, y2): + return (y2 - y1) / (x2 - x1) + + +answer = 0 + +# 건물의 왼쪽은 기울기가 점점 작아져야 됨 +# 건물의 오른쪽은 기울기가 점점 커져야 됨 +for i in range(len(buildings)): + temp_answer = 0 + left_slope = float('inf') + right_slope = -float('inf') + # 왼쪽 + for j in range(i-1, -1, -1): + temp_slope = slope(i, buildings[i], j, buildings[j]) + if temp_slope < left_slope: + left_slope = temp_slope + temp_answer += 1 + # 오른쪽 + for j in range(i+1, n): + temp_slope = slope(i, buildings[i], j, buildings[j]) + if temp_slope > right_slope: + right_slope = temp_slope + temp_answer += 1 + answer = max(answer, temp_answer) + +print(answer) diff --git "a/2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1034_\353\236\250\355\224\204.py" "b/2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1034_\353\236\250\355\224\204.py" new file mode 100644 index 0000000..8c9df05 --- /dev/null +++ "b/2023/04.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1034_\353\236\250\355\224\204.py" @@ -0,0 +1,36 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, m = map(int, input().split()) +matrix = [] + +for _ in range(n): + matrix.append(list(map(int, list(input())))) + +k = int(input()) + +# 모든 열이 켜져 있는 최대 행의 수 +# 행의 패턴이 같다 = 같이 다 켜짐 +# 꺼진 전등 -> 홀수번 = 켜짐, 짝수번 = 꺼짐 +# 한 행을 기준으로 불을 다 켰을 때, 다 켜진 곳은 어디인가?? + +count = [0] * n + +if k % 2 == 1: + for i in range(n): + zero = matrix[i].count(0) + print(i, zero) + if zero % 2 == 1 and zero <= k: + for j in range(n): + if matrix[i] == matrix[j]: + count[i] += 1 +else: + for i in range(n): + zero = matrix[i].count(0) + if zero % 2 == 0 and zero <= k: + for j in range(n): + if matrix[i] == matrix[j]: + count[i] += 1 + +print(max(count)) From b53a3ea03183d2d76226cffcb54cf783edb643a6 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 14 May 2023 17:17:45 +0900 Subject: [PATCH 573/822] Create Readme.md --- 2023/04.12/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/04.12/Readme.md diff --git a/2023/04.12/Readme.md b/2023/04.12/Readme.md new file mode 100644 index 0000000..e7128ad --- /dev/null +++ b/2023/04.12/Readme.md @@ -0,0 +1,5 @@ +# 4.12(수) 스터디 + +- 백준 + - [고층건물](https://www.acmicpc.net/problem/1027) + - [램프](https://www.acmicpc.net/problem/1034) From ad48fc5096a16b6ee58b1bdce119d4e80dc327f6 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 14 May 2023 17:18:48 +0900 Subject: [PATCH 574/822] Create Readme.md --- 2023/04.17/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 2023/04.17/Readme.md diff --git a/2023/04.17/Readme.md b/2023/04.17/Readme.md new file mode 100644 index 0000000..f685642 --- /dev/null +++ b/2023/04.17/Readme.md @@ -0,0 +1,4 @@ +# 4.17(월) 스터디 + +- 백준 + - [거짓말](https://www.acmicpc.net/problem/1043) From 10fa5560f1ccfb47302428c81c253e638fae0d01 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 14 May 2023 17:19:37 +0900 Subject: [PATCH 575/822] Create Readme.md --- 2023/04.20/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 2023/04.20/Readme.md diff --git a/2023/04.20/Readme.md b/2023/04.20/Readme.md new file mode 100644 index 0000000..259f74b --- /dev/null +++ b/2023/04.20/Readme.md @@ -0,0 +1,4 @@ +# 4.20(목) 스터디 + +- 백준 + - [가르침](https://www.acmicpc.net/problem/1062) From e3cffc51296b204234e01365aac723261da9e111 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 14 May 2023 17:20:13 +0900 Subject: [PATCH 576/822] Create Readme.md --- 2023/04.26/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 2023/04.26/Readme.md diff --git a/2023/04.26/Readme.md b/2023/04.26/Readme.md new file mode 100644 index 0000000..4a4c642 --- /dev/null +++ b/2023/04.26/Readme.md @@ -0,0 +1,4 @@ +# 4.26(수) 스터디 + +- 백준 + - [카드섞기](https://www.acmicpc.net/problem/1091) From bb8a12922fd499f4948bac1e1606930cc4bd92cb Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 14 May 2023 17:22:16 +0900 Subject: [PATCH 577/822] =?UTF-8?q?=EC=99=9C=20=EC=95=88=20=EC=98=AC?= =?UTF-8?q?=EB=A0=B8=EC=97=88=EC=A7=80=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\353\246\254\355\225\230\352\270\260.py" | 30 ++++++++++++++++++ ...50\354\226\264\353\263\200\355\231\230.py" | 31 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 "2023/03.16/\354\206\241\352\270\260\355\233\210/SWEA_3316_\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.py" create mode 100644 "2023/03.16/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\213\250\354\226\264\353\263\200\355\231\230.py" diff --git "a/2023/03.16/\354\206\241\352\270\260\355\233\210/SWEA_3316_\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.py" "b/2023/03.16/\354\206\241\352\270\260\355\233\210/SWEA_3316_\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..f5a563b --- /dev/null +++ "b/2023/03.16/\354\206\241\352\270\260\355\233\210/SWEA_3316_\353\217\231\354\225\204\353\246\254\354\213\244\352\264\200\353\246\254\355\225\230\352\270\260.py" @@ -0,0 +1,30 @@ +import sys + +sys.stdin = open("03.16/sample_input.txt", "r", encoding="UTF-8") + +T = int(input()) + +# D C B A +# 0 0 0 0 + +for test_case in range(1, T+1): + # 아스키 코드를 이용해서 숫자로 변환 + input_list = list(map(lambda x: ord(x) - ord("A"), input())) + # dp[n][16] 16가지 경우의 수와 n일 + dp = [[0 for _ in range(16)] for _ in range(len(input_list))] + + for i in range(1, 16): + # 첫 날 A와 담당자가 있는 경우 (비트연산) + if i & 1 and i & 1 << input_list[0]: + dp[0][i] += 1 + + # 둘째 날부터... + for i in range(1, len(input_list)): + for j in range(1, 16): + for k in range(1, 16): + # j 경우, k 경우에 공통으로 같이 있는 사람 + # i일 담당자가 j 경우의 수에 포함되는가 + if j & k and j & 1 << input_list[i]: + dp[i][j] = (dp[i][j] + dp[i-1][k]) % 1000000007 + + print("#{} {}".format(test_case, sum(dp[-1]) % 1000000007)) diff --git "a/2023/03.16/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\213\250\354\226\264\353\263\200\355\231\230.py" "b/2023/03.16/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\213\250\354\226\264\353\263\200\355\231\230.py" new file mode 100644 index 0000000..092c9fb --- /dev/null +++ "b/2023/03.16/\354\206\241\352\270\260\355\233\210/pgm_lv3_\353\213\250\354\226\264\353\263\200\355\231\230.py" @@ -0,0 +1,31 @@ +from collections import deque + + +def solution(begin, target, words): + answer = 0 + visited = [False for _ in range(len(words))] + q = deque() + # 단어, depth + q.append((begin, 0)) + while q: + word, depth = q.popleft() + if word == target: + answer = depth + break + for i in range(len(words)): + same_cnt = 0 + # 방문하지 않은 단어와 한 글자 차이인가? + if not visited[i]: + for j in range(len(word)): + if word[j] != words[i][j]: + same_cnt += 1 + if same_cnt > 1: + break + # 한 글자 차이라면 큐에 넣고 돌림 + if same_cnt == 1: + q.append((words[i], depth + 1)) + visited[i] = True + return answer + + +print(solution("hit", "cog", ["hot", "dot", "dog", "lot", "log", "cog"])) From 5db20721ab6d123eb7e3cf89fd6d946452fdec7a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 17 May 2023 16:41:54 +0900 Subject: [PATCH 578/822] =?UTF-8?q?kihun=20pgm=5Flv3=5F=EC=97=AC=ED=96=89?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\355\226\211\352\262\275\353\241\234.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "2023/05.14/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\227\254\355\226\211\352\262\275\353\241\234.py" diff --git "a/2023/05.14/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\227\254\355\226\211\352\262\275\353\241\234.py" "b/2023/05.14/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\227\254\355\226\211\352\262\275\353\241\234.py" new file mode 100644 index 0000000..c4a8676 --- /dev/null +++ "b/2023/05.14/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\227\254\355\226\211\352\262\275\353\241\234.py" @@ -0,0 +1,24 @@ +from collections import deque + + +def solution(tickets): + answer = [] + + q = deque() + # 출발지, 경로, visited + q.append(("ICN", ["ICN"], [])) + + while q: + start, path, visited = q.popleft() + # 티켓을 모두 소모했다면 answer에 추가 + if len(visited) == len(tickets): + answer.append(path) + + for idx, ticket in enumerate(tickets): + if ticket[0] == start and not idx in visited: + q.append((ticket[1], path+[ticket[1]], visited+[idx])) + + # 알파벳순으로 정렬 + answer.sort() + + return answer[0] From 66a5930f102dd6d79da5a9ff5cb579738ed5c121 Mon Sep 17 00:00:00 2001 From: "bigyoung8375@naver.com" Date: Wed, 24 May 2023 13:07:46 +0900 Subject: [PATCH 579/822] =?UTF-8?q?PRG=20=EC=96=B5=EC=96=B5=EB=8B=A8?= =?UTF-8?q?=EC=9D=84=20=EC=99=B8=EC=9A=B0=EC=9E=90=20Solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\231\270\354\232\260\354\236\220.kt" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "2023/05.25/\354\260\275\354\230\201/PRG \354\226\265\354\226\265\353\213\250\354\235\204 \354\231\270\354\232\260\354\236\220.kt" diff --git "a/2023/05.25/\354\260\275\354\230\201/PRG \354\226\265\354\226\265\353\213\250\354\235\204 \354\231\270\354\232\260\354\236\220.kt" "b/2023/05.25/\354\260\275\354\230\201/PRG \354\226\265\354\226\265\353\213\250\354\235\204 \354\231\270\354\232\260\354\236\220.kt" new file mode 100644 index 0000000..f30b396 --- /dev/null +++ "b/2023/05.25/\354\260\275\354\230\201/PRG \354\226\265\354\226\265\353\213\250\354\235\204 \354\231\270\354\232\260\354\236\220.kt" @@ -0,0 +1,95 @@ +package DP_부수기 + +import java.io.BufferedWriter +import java.io.OutputStreamWriter +import java.util.* + + +// 우선순위 큐 +private var pque: PriorityQueue = PriorityQueue() +private var tempPque: PriorityQueue = PriorityQueue() + + +// 메모이제이션 +private lateinit var memo: Array + +private data class Point( + var n: Int?, + var c: Int? +) : Comparable { + // Point 정렬 조건 -> c역순, n 정순으로 정렬 + override fun compareTo(other: Point): Int { + if (c!! < other.c!!) { + return 1 + } else if (c!! > other.c!!) { + return -1 + } else { + if (n!! > other.n!!) { + return 1 + } else if (n!! < other.n!!) { + return -1 + } else { + return 0 + } + } + } +} // End of Point class + +fun main() { + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + val sb = StringBuilder() + + val e = 8 + val starts = intArrayOf(1, 3, 7) + sb.append(solution(e, starts).contentToString()) + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun solution(e: Int, starts: IntArray): IntArray { + val size = starts.size + val result = IntArray(size) + + DP(e) + + val pqueSize = pque.size + for (i in 0 until size) { + val s = starts[i] + + tempPque.forEach { + pque.offer(it) + } + tempPque.clear() + + for (j in 0 until pqueSize) { + val temp = pque.poll() + tempPque.offer(temp) + + if (temp.n!! >= s) { + result[i] = temp.n!! + break + } + } + } + + return result +} // End of solution + +private fun DP(e: Int) { + memo = Array(e) { Point(null, null) } + for (i in 1..e) { + memo[i - 1] = Point(i, 1) + } + + // 각 수의 약수 갯수 모두 구하기 + for (i in 2..e step 1) { + for (j in 1..(e / i) step 1) { + memo[(i * j) - 1].c = memo[(i * j) - 1].c!! + 1 + } + } + + memo.forEach { + pque.offer(it) + } +} // End of DP From 5663587f88b80b28803704b17847e3284cffc730 Mon Sep 17 00:00:00 2001 From: SooYun Jo Date: Fri, 26 May 2023 10:42:04 +0900 Subject: [PATCH 580/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=20=EB=B0=B1?= =?UTF-8?q?=EC=A4=80=2019941=20:=20=ED=96=84=EB=B2=84=EA=B1=B0=20=EB=B6=84?= =?UTF-8?q?=EB=B0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\261\260_\353\266\204\353\260\260.java" | 70 +++++++++++++++++++ ...4\352\261\260_\353\266\204\353\260\260.kt" | 70 +++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 "2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.java" create mode 100644 "2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.kt" diff --git "a/2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.java" "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.java" new file mode 100644 index 0000000..8653823 --- /dev/null +++ "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.java" @@ -0,0 +1,70 @@ +import java.util.*; +import java.io.*; + +class Main { + public static void main(String args[]) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer token = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(token.nextToken()); + int K = Integer.parseInt(token.nextToken()); + + String info = br.readLine(); + boolean[] ate = new boolean[N]; + int answer = 0; + boolean isFind; + + for (int i = info.length() - 1; i >= 0; i--) { + if (info.charAt(i) == 'P') { + + isFind = false; + + if (i + K > info.length() - 1) { + for (int j = info.length() - 1; j >= i + 1; j--) { + if (info.charAt(j) == 'H' && !ate[j]) { + ate[j] = true; + answer++; + isFind = true; + break; + } + } + } else { + for (int j = i + K; j >= i + 1; j--) { + if (info.charAt(j) == 'H' && !ate[j]) { + ate[j] = true; + answer++; + isFind = true; + break; + } + } + } + + if (isFind) continue; + + if (i - K < 0) { + for (int j = i - 1; j >= 0; j--) { + if (info.charAt(j) == 'H' && !ate[j]) { + ate[j] = true; + answer++; + break; + } + } + } else { + for (int j = i - 1; j >= i - K; j--) { + if (info.charAt(j) == 'H' && !ate[j]) { + ate[j] = true; + answer++; + break; + } + } + } + } + } + + bw.write(String.valueOf(answer)); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file diff --git "a/2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.kt" "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.kt" new file mode 100644 index 0000000..366dfc4 --- /dev/null +++ "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\355\226\204\353\262\204\352\261\260_\353\266\204\353\260\260.kt" @@ -0,0 +1,70 @@ +import java.util.* +import java.io.* + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val token = StringTokenizer(readLine()) + val N = token.nextToken().toInt() + val K = token.nextToken().toInt() + + val info = readLine() + val ate = BooleanArray(N) // 햄버거를 먹었는지 체크하는 배열 + var answer = 0 + var isFind = false + + for (i in info.length - 1 downTo 0) { + if (info[i] == 'P') { + + isFind = false // 오른쪽에서 체크 결과 초기화 + + // 오른쪽부터 탐색 + if (i + K > info.length - 1) { // K 더한 거리가 범위를 벗어날 경우 + for (j in info.length - 1 downTo i + 1) { + if (info[j] == 'H' && !ate[j]) { + ate[j] = true + answer++ + isFind = true + break + } + } + } else { + for (j in i + K downTo i + 1) { + if (info[j] == 'H' && !ate[j]) { + ate[j] = true + answer++ + isFind = true + break + } + } + } + + if (isFind) continue + + // 왼쪽 탐색 + if (i - K < 0) { // K 더한 거리가 범위를 벗어날 경우 + for (j in i - 1 downTo 0) { + if (info[j] == 'H' && !ate[j]) { + ate[j] = true + answer++ + break + } + } + } else { + for (j in i - 1 downTo i - K) { + if (info[j] == 'H' && !ate[j]) { + ate[j] = true + answer++ + break + } + } + } + } + } + + bw.write("$answer") + + bw.flush() + bw.close() +} From d49d76a1a4a8c87421a41eab3987e6a07392cb4a Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 29 May 2023 13:42:43 +0900 Subject: [PATCH 581/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=20=EB=B0=B1?= =?UTF-8?q?=EC=A4=80=202565=20:=20=EC=A0=84=EA=B9=83=EC=A4=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\240\204\352\271\203\354\244\204.kt" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" diff --git "a/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" new file mode 100644 index 0000000..b70c46c --- /dev/null +++ "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" @@ -0,0 +1,44 @@ +import java.util.* +import java.io.* +import kotlin.collections.ArrayList +import kotlin.math.max + +data class Wire( + val start: Int, + val end: Int, +) + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val N = readLine().toInt() + val wireList = ArrayList() + + repeat(N){ + val token = StringTokenizer(readLine()) + val wire = Wire(token.nextToken().toInt(),token.nextToken().toInt()) + wireList.add(wire) + } + + wireList.sortBy { it.start } // 왼쪽 전봇대 번호를 기준으로 정렬 + + var dp = IntArray(N) + var maxWire = -1 // 전깃줄을 가장 많이 연결할 수 있는 갯수 + + for (i in 0 until N){ + dp[i] = 1 + for (j in 0 until i){ + if (wireList[j].end < wireList[i].end){ // 다음 전깃줄이 이전의 전깃줄보다 위에 있으면 교차하므로 +1 + dp[i] = max(dp[i],dp[j]+1) + } // 다음에 나오는 전깃줄 번호가 이전의 전깃줄 번호의 끝보다 밑에 있으면 연결해도 문제 없음 + } + maxWire = max(maxWire,dp[i]) + } + + bw.write("${N - maxWire}") // 총 전깃줄 갯수에서 최대로 연결할 수 있는 전깃줄을 빼면 최소로 이을 수 있는 전깃줄 갯수가 나온다 + + bw.flush() + bw.close() +} + From 6e93394fd711be5498a386456b1027b8ee852404 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 29 May 2023 13:51:58 +0900 Subject: [PATCH 582/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=20=EB=B0=B1?= =?UTF-8?q?=EC=A4=80=202565=20:=20=EC=A0=84=EA=B9=83=EC=A4=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\240\204\352\271\203\354\244\204.kt" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" index b70c46c..c6fbb3b 100644 --- "a/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" +++ "b/2023/05.25/\354\241\260\354\210\230\354\227\260/\354\240\204\352\271\203\354\244\204.kt" @@ -29,9 +29,9 @@ fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { for (i in 0 until N){ dp[i] = 1 for (j in 0 until i){ - if (wireList[j].end < wireList[i].end){ // 다음 전깃줄이 이전의 전깃줄보다 위에 있으면 교차하므로 +1 + if (wireList[j].end < wireList[i].end){ // 이전의 전깃줄보다 현재 전깃줄의 끝 번호가 더 밑에 있으면 연결할 수 있으니깐 +1 dp[i] = max(dp[i],dp[j]+1) - } // 다음에 나오는 전깃줄 번호가 이전의 전깃줄 번호의 끝보다 밑에 있으면 연결해도 문제 없음 + } } maxWire = max(maxWire,dp[i]) } From 7a7555892922d7434348089338a9520b83613865 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 29 May 2023 14:11:40 +0900 Subject: [PATCH 583/822] kihun --- ...04\354\231\270\354\232\260\354\236\220.py" | 116 ++++++++++++++++++ ...04\352\261\260\353\266\204\353\260\260.py" | 47 +++++++ ...5_\354\240\204\352\271\203\354\244\204.py" | 29 +++++ 3 files changed, 192 insertions(+) create mode 100644 "2023/05.25/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\226\265\354\226\265\353\213\250\354\235\204\354\231\270\354\232\260\354\236\220.py" create mode 100644 "2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_19941_\355\226\204\353\262\204\352\261\260\353\266\204\353\260\260.py" create mode 100644 "2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2565_\354\240\204\352\271\203\354\244\204.py" diff --git "a/2023/05.25/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\226\265\354\226\265\353\213\250\354\235\204\354\231\270\354\232\260\354\236\220.py" "b/2023/05.25/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\226\265\354\226\265\353\213\250\354\235\204\354\231\270\354\232\260\354\236\220.py" new file mode 100644 index 0000000..4896ee7 --- /dev/null +++ "b/2023/05.25/\354\206\241\352\270\260\355\233\210/pgm_lv3_\354\226\265\354\226\265\353\213\250\354\235\204\354\231\270\354\232\260\354\236\220.py" @@ -0,0 +1,116 @@ +# from collections import defaultdict +# import math + +""" +# 70점 +def solution(e, starts): + answer = [] + + dict = defaultdict(int) + min_start = min(starts) + + for num in range(min_start, e+1): + dict[num] = submultiple(num) + + for start in starts: + temp_key = float('inf') + temp_value = -1 + for (key, value) in dict.items(): + if key < start: + continue + if value > temp_value: + temp_key = key + temp_value = value + answer.append(temp_key) + return answer +""" + +""" +# 80점 +def solution(e, starts): + answer = [] + + dict = defaultdict(int) + min_start = min(starts) + + for num in range(min_start, e+1): + dict[num] = submultiple(num) + + + sorted_dict = sorted(dict.items(), key= lambda x: x[1], reverse=True) + + for start in starts: + for key, value in sorted_dict: + if key >= start: + answer.append(key) + break + return answer +""" + + +""" +def submultiple(num): + root_num = math.sqrt(num) + count = 0 + + for i in range(1, int(root_num)+1): + if (num % i == 0): + count += 2 + + if (num % root_num == 0): + count -= 1 + + return count +""" + +""" +# 90점 -> 약수 구하는 방식도 느리고 답을 찾는 과정도 느림 +from collections import defaultdict + +def solution(e, starts): + answer = [] + + dict = defaultdict(lambda: 1) + + dict[1] = 1 + + for i in range(2, e+1): + for j in range(1, e+1): + if (i * j > e): + break + dict[i * j] += 1 + + sorted_dict = sorted(dict.items(), key= lambda x: x[1], reverse=True) + + for start in starts: + for key, value in sorted_dict: + if (key >= start): + answer.append(key) + break + + return answer +""" + + +def solution(e, starts): + answer = [] + divisors = [0 for _ in range(e+1)] + answers = [0 for _ in range(e+1)] + max_value = 0 + + for n in range(1, int(e**0.5)+1): + divisors[n*n] += 1 + for i in range(n*(n+1), e+1, n): + divisors[i] += 2 + + for i in range(e, -1, -1): + if divisors[i] >= max_value: + max_value = divisors[i] + answers[i] = i + else: + answers[i] = answers[i+1] + + for s in starts: + answer.append(answers[s]) + + return answer diff --git "a/2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_19941_\355\226\204\353\262\204\352\261\260\353\266\204\353\260\260.py" "b/2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_19941_\355\226\204\353\262\204\352\261\260\353\266\204\353\260\260.py" new file mode 100644 index 0000000..ce6dd4b --- /dev/null +++ "b/2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_19941_\355\226\204\353\262\204\352\261\260\353\266\204\353\260\260.py" @@ -0,0 +1,47 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="utf-8") + +n, k = map(int, input().split()) +table_list = list(input()) +answer = 0 + +for i in range(n): + if table_list[i] == "P": + for j in range(max(i - k, 0), min(i + k + 1, n)): + if table_list[j] == "H": + table_list[j] = "X" + answer += 1 + break +print(answer) + +# 테이블을 도면서 사람이면 k 범위 내에서 왼쪽부터 탐색 +# 왼쪽부터 탐색해야 뒷 사람이 먹을게 있다 + +""" +사람 리스트, 햄버거 리스트 구하고 +각각 사람마다 사정거리 + 햄버거 있는 위치의 집합을 만듬 +그리고 첫번째 사람부터 for문을 돌면서 왼쪽꺼를 고르게 하려고 함 +-> for문을 불필요하게 많이 도는 것 같다 +people_list = [] +hamburger_list = [] +possible_set = set() + +for i in range(n): + if table_list[i] == "H": + hamburger_list.append(i) + else: + people_list.append(i) + +for person in people_list: + for delta in range(-k, k+1): + if ((person + delta) < n) and ((person + delta) >= 0): + possible_set.add(person + delta) + +possible_set = possible_set - set(people_list) + +""" + + + + diff --git "a/2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2565_\354\240\204\352\271\203\354\244\204.py" "b/2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2565_\354\240\204\352\271\203\354\244\204.py" new file mode 100644 index 0000000..824ceeb --- /dev/null +++ "b/2023/05.25/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2565_\354\240\204\352\271\203\354\244\204.py" @@ -0,0 +1,29 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="utf-8") + +n = int(input()) +wires = [] +dp = [1 for _ in range(n)] + +for _ in range(n): + a, b = map(int, input().split()) + wires.append([a, b]) + +# a를 오름차순으로 정렬 +wires.sort() + +# 연결 조건 +# A1 - B1, A2 - B2에서 A1 < A2 이면 B1 < B2 가 성립해야 함 +# B에서 증가하는 가장 긴 부분 수열을 구한다 +# https://zidarn87.tistory.com/291 +# https://zidarn87.tistory.com/285 + +# for문 2개를 돌면서 해당 조건에 맞는 것들을 찾고 더 해준다 +for i in range(1, n): + for j in range(0, i): + if wires[j][1] < wires[i][1]: + dp[i] = max(dp[i], dp[j] + 1) + +# 총 전깃줄 수 - 최대 연결 가능한 전깃줄 수 +print(n - max(dp)) From 55f90e3d3678d991723f075aeb0ae2272359b6e6 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 29 May 2023 14:13:43 +0900 Subject: [PATCH 584/822] Create Readme.md --- 2023/05.25/Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 2023/05.25/Readme.md diff --git a/2023/05.25/Readme.md b/2023/05.25/Readme.md new file mode 100644 index 0000000..59b9e74 --- /dev/null +++ b/2023/05.25/Readme.md @@ -0,0 +1,8 @@ +# 5.25(목) 스터디 + +- 백준 + - [전깃줄](https://www.acmicpc.net/problem/2565) + - [햄버거 분배](https://www.acmicpc.net/problem/19941) + +- 프로그래머스 + - [억억단을 외우자](https://school.programmers.co.kr/learn/courses/30/lessons/138475) From 58f6bc7a8fb0ed535e0de7af62cbefe941a84995 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Tue, 30 May 2023 10:01:33 +0900 Subject: [PATCH 585/822] Create Readme.md --- 2023/06.01/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.01/Readme.md diff --git a/2023/06.01/Readme.md b/2023/06.01/Readme.md new file mode 100644 index 0000000..be20e35 --- /dev/null +++ b/2023/06.01/Readme.md @@ -0,0 +1,5 @@ +# 6.1(목) 스터디 + +- 백준 + - [동물원](https://www.acmicpc.net/problem/1309) + - [가장 긴 증가하는 부분 수열](https://www.acmicpc.net/problem/11053) From d7066272089002ba2913139087e402685aea0392 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 1 Jun 2023 15:33:00 +0900 Subject: [PATCH 586/822] kihun --- ...00\353\266\204\354\210\230\354\227\264.py" | 15 ++++++++ ...9_\353\217\231\353\254\274\354\233\220.py" | 35 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 "2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11053_\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\264.py" create mode 100644 "2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1309_\353\217\231\353\254\274\354\233\220.py" diff --git "a/2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11053_\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\264.py" "b/2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11053_\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\264.py" new file mode 100644 index 0000000..e96187c --- /dev/null +++ "b/2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11053_\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\264.py" @@ -0,0 +1,15 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) +numberList = list(map(int, input().split())) +dp = [1 for _ in range(n)] + +for i in range(1, n): + for j in range(0, i): + # j가 i보다 작으면 1 추가 + if numberList[j] < numberList[i]: + dp[i] = max(dp[i], dp[j] + 1) + +print(max(dp)) diff --git "a/2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1309_\353\217\231\353\254\274\354\233\220.py" "b/2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1309_\353\217\231\353\254\274\354\233\220.py" new file mode 100644 index 0000000..cd60a90 --- /dev/null +++ "b/2023/06.01/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1309_\353\217\231\353\254\274\354\233\220.py" @@ -0,0 +1,35 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) + +# 1차원 배열로 줄이기 +dp = [0 for _ in range(n + 1)] +dp[0] = 1 +dp[1] = 3 + +for i in range(2, n+1): + # for문을 돌 때 % 연산을 안하니까 메모리 초과 + dp[i] = (dp[i - 2] + dp[i - 1] * 2) % 9901 + +print(dp[n]) + + +""" 메모리 초과 +# 안 넣기, 왼쪽, 오른쪽 +dp = [[0, 0] for _ in range(n+1)] +dp[1] = [1, 1] + +# 안 넣기 = 안 넣기 + 왼쪽 + 오른쪽 +# 왼쪽 = 안 넣기 + 오른쪽 +# 오른쪽 = 안 넣기 + 왼쪽 + +dp = [[0, 0, 0] for _ in range(n+1)] +dp[1] = [1, 1, 1] + +for i in range(2, n + 1): + dp[i][0] = dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2] + dp[i][1] = dp[i - 1][0] + dp[i - 1][2] + dp[i][2] = dp[i - 1][0] + dp[i - 1][1] +""" From 4ed3c23a5c9d6c7254aa95174dd7afd119407d00 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 1 Jun 2023 15:39:43 +0900 Subject: [PATCH 587/822] Create Readme.md --- 2023/06.05/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.05/Readme.md diff --git a/2023/06.05/Readme.md b/2023/06.05/Readme.md new file mode 100644 index 0000000..a370f93 --- /dev/null +++ b/2023/06.05/Readme.md @@ -0,0 +1,5 @@ +# 6.5(월) 스터디 + +- 백준 + - [점프](https://www.acmicpc.net/problem/1890) + - [강의실 배정](https://www.acmicpc.net/problem/11000) From 43d1dfb1725e45da7685bb2f090181bc2f692041 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sat, 3 Jun 2023 15:56:31 +0900 Subject: [PATCH 588/822] =?UTF-8?q?BOJ=2011000=20=EA=B0=95=EC=9D=98?= =?UTF-8?q?=EC=8B=A4=20=EB=B0=B0=EC=A0=95=20&=20BOJ=201309=20=EB=8F=99?= =?UTF-8?q?=EB=AC=BC=EC=9B=90=20Solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\213\244 \353\260\260\354\240\225.kt" | 81 +++++++++++++++++++ ...9 \353\217\231\353\254\274\354\233\220.kt" | 55 +++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 "2023/06.05/\354\260\275\354\230\201/Main 11000 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.kt" create mode 100644 "2023/06.05/\354\260\275\354\230\201/Main 1309 \353\217\231\353\254\274\354\233\220.kt" diff --git "a/2023/06.05/\354\260\275\354\230\201/Main 11000 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.kt" "b/2023/06.05/\354\260\275\354\230\201/Main 11000 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.kt" new file mode 100644 index 0000000..dbddbae --- /dev/null +++ "b/2023/06.05/\354\260\275\354\230\201/Main 11000 \352\260\225\354\235\230\354\213\244 \353\260\260\354\240\225.kt" @@ -0,0 +1,81 @@ +package 정렬_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 선생님에계 새로운 과제가 주어졌다. + 수업이 끝난 직후에 다음 수업을 시작할 수 있다 (즉, Ti <= Si일 경우 i 수업과 j 수업은 같이 들을 수 있다) + 수강신청 대충한 게 찔리면, 선생님을 도와드리자! + + 첫 번째 줄에 N이 주어진다. (1 <= N <= 200,000) + 이후 N개의 줄에 Si, Ti가 주어진다. (0 <= Si <= Ti <= 10^9) + + 강의실의 개수를 출력하라 + */ + +// Input +private lateinit var br: BufferedReader + +// Variables +private var N = 0 +private var pQue: PriorityQueue = PriorityQueue() +private var timePque = PriorityQueue() +private lateinit var lectures: Array + +private data class Lecture( + var startTime: Int, // 수업 시작 시간 + var endTime: Int // 수업 끝나는 시간 +) : Comparable { + // End of Class + override fun compareTo(other: Lecture): Int { + if (startTime == other.startTime) { + return endTime - other.endTime + } + return startTime - other.startTime + } +} // End of Lecture class + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\정렬_부수기\\res\\11000.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + val sb = StringBuilder() + + input() + + var index = 0 + while (pQue.isNotEmpty()) { + lectures[index++] = pQue.poll() + } + + timePque.offer(lectures[0].endTime) + + for (i in 1 until N) { + if (timePque.peek() <= lectures[i].startTime) { + timePque.poll() + } + timePque.offer(lectures[i].endTime) + } + + sb.append(timePque.size) + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + N = br.readLine().toInt() + lectures = Array(N) { Lecture(0, 0) } + for (i in 0 until N) { + val st = StringTokenizer(br.readLine()) + pQue.offer( + Lecture( + st.nextToken().toInt(), st.nextToken().toInt() + ) + ) + } +} // End of input diff --git "a/2023/06.05/\354\260\275\354\230\201/Main 1309 \353\217\231\353\254\274\354\233\220.kt" "b/2023/06.05/\354\260\275\354\230\201/Main 1309 \353\217\231\353\254\274\354\233\220.kt" new file mode 100644 index 0000000..2dfc107 --- /dev/null +++ "b/2023/06.05/\354\260\275\354\230\201/Main 1309 \353\217\231\353\254\274\354\233\220.kt" @@ -0,0 +1,55 @@ +package DP_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter + +/* + 사자들을 우리에 가둘 때, 가로로도 세로로도 붙어 있게 배치할 수는 없다. + 우리가 2*N 배열에 사자를 배치하는 경우의 수가 몇 가지인지를 알아내는 프로그램을 작성해 주도록 하자. + 사자를 한 마리도 배치하지 않는 경우도 하나의 경우의 수로 친다고 가정한다. + */ + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 +private const val MOD = 9901 +private lateinit var memo: Array + + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\DP_부수기\\res\\1309.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + val sb = StringBuilder() + + input() + + for (i in 2..N) { + memo[i][0] = (memo[i - 1][0] + memo[i - 1][1] + memo[i - 1][2]) + memo[i][1] = (memo[i - 1][0] + memo[i - 1][2]) + memo[i][2] = (memo[i - 1][0] + memo[i - 1][1]) + memo[i][0] %= MOD + memo[i][1] %= MOD + memo[i][2] %= MOD + } + + val result = (memo[N][0] + memo[N][1] + memo[N][2]) % MOD + sb.append(result).append('\n') + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + N = br.readLine().toInt() + memo = Array(N + 1) { IntArray(3) { 1 } } + + // 기저 사례 + memo[1][0] = 1 + memo[1][1] = 1 + memo[1][2] = 1 +} // End of input From 74b4b0c237fa2ff7e77deff39a398d06f14ca55a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 5 Jun 2023 17:34:38 +0900 Subject: [PATCH 589/822] kihun --- ...30\354\213\244\353\260\260\354\240\225.py" | 33 +++++++++++++++++++ ...\244\200_1890_\354\240\220\355\224\204.py" | 25 ++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 "2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11000_\352\260\225\354\235\230\354\213\244\353\260\260\354\240\225.py" create mode 100644 "2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1890_\354\240\220\355\224\204.py" diff --git "a/2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11000_\352\260\225\354\235\230\354\213\244\353\260\260\354\240\225.py" "b/2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11000_\352\260\225\354\235\230\354\213\244\353\260\260\354\240\225.py" new file mode 100644 index 0000000..ca35ff9 --- /dev/null +++ "b/2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_11000_\352\260\225\354\235\230\354\213\244\353\260\260\354\240\225.py" @@ -0,0 +1,33 @@ +import heapq +import sys + +# https://joooosan.tistory.com/entry/%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%B0%B1%EC%A4%80-11000%EB%B2%88-%EA%B0%95%EC%9D%98%EC%8B%A4-%EB%B0%B0%EC%A0%95 + +""" +1. 강의 리스트를 정렬한다. +2. 첫 번째 강의가 끝나는 시간을 우선순위 큐에 추가한다. +3. 강의 리스트의 1번째 인덱스부터 마지막까지 반복문을 실행한다 +3-1. 우선순위 큐에 첫 번째 인덱스에 접근한다 (항상 끝나는 시간이 가장 빠른 순) +3-2. 만약 강의의 시작시간이 우선순위 큐의 첫 번째 인덱스보다 작다면 해당 강의의 끝나는 시간을 우선순위 큐에 추가한다. +3-3. 아니라면 우선순위 큐의 첫 번째 인덱스를 pop 한 후 해당 강의의 끝나는 시간을 우선순위 큐에 추가한다. +""" + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) + +lecture_list = [list(map(int, input().split())) for _ in range(n)] + +lecture_list.sort() + +lecture_queue = [] +heapq.heappush(lecture_queue, lecture_list[0][1]) + +for i in range(1, n): + if lecture_list[i][0] < lecture_queue[0]: + heapq.heappush(lecture_queue, lecture_list[i][1]) + else: + heapq.heappop(lecture_queue) + heapq.heappush(lecture_queue, lecture_list[i][1]) + +print(len(lecture_queue)) diff --git "a/2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1890_\354\240\220\355\224\204.py" "b/2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1890_\354\240\220\355\224\204.py" new file mode 100644 index 0000000..65039e1 --- /dev/null +++ "b/2023/06.05/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_1890_\354\240\220\355\224\204.py" @@ -0,0 +1,25 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) + +# 입력, 도착할 수 있는 방법의 수 +matrix = [] +dp = [[0 for _ in range(n)] for _ in range(n)] + +for _ in range(n): + matrix.append(list(map(int, input().split()))) + +dp[0][0] = 1 + +for i in range(n): + for j in range(n): + if matrix[i][j] != 0 and dp[i][j] != 0: + # 이동 시키기 + if matrix[i][j] + i < n: + dp[i + matrix[i][j]][j] += dp[i][j] + if matrix[i][j] + j < n: + dp[i][j + matrix[i][j]] += dp[i][j] + +print(dp[n-1][n-1]) From 98e5409397bb53651ffe9c9c3ca29ca4f68adab4 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 5 Jun 2023 18:39:32 +0900 Subject: [PATCH 590/822] Create Readme.md --- 2023/06.09/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.09/Readme.md diff --git a/2023/06.09/Readme.md b/2023/06.09/Readme.md new file mode 100644 index 0000000..1c536f1 --- /dev/null +++ b/2023/06.09/Readme.md @@ -0,0 +1,5 @@ +# 6.9(금) 스터디 + +- 백준 + - [동전2](https://www.acmicpc.net/problem/2294) + - [카드 합체 놀이](https://www.acmicpc.net/problem/15903) From 9fd84a8e5021955f4f8e5383f6c0575321bef135 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 8 Jun 2023 01:25:42 +0900 Subject: [PATCH 591/822] =?UTF-8?q?Create=20=EB=8F=99=EC=A0=842.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\217\231\354\240\2042.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/06.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2042.java" diff --git "a/2023/06.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2042.java" "b/2023/06.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2042.java" new file mode 100644 index 0000000..5e05180 --- /dev/null +++ "b/2023/06.09/\354\240\225\355\230\270\354\241\260/\353\217\231\354\240\2042.java" @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Collections; +import java.util.StringTokenizer; + +public class 동전2_2294 { + static int n, k, ans; + static int[] coin, dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + ans = 0; + coin = new int[n]; + dp = new int[k + 1]; + + for (int i = 0; i < n; i++) { + coin[i] = Integer.parseInt(br.readLine()); + } + + Arrays.fill(dp, Integer.MAX_VALUE -1); // -1을 안해주면 밑에서 dp[j - coin[i]] + 1 값이 max value를 넘어갈 때 음수 값이 나옴 + dp[0] = 0; //dp[i]가 i 가치를 구하기 위한 동전의 개수일 때, i원의 동전으로 i값을 구하는 경우의 수가 1이 되려면 dp[0]을 항상 0 으로 둬야함 + + //LIS 의 Bottom-Up 방식 + for (int i = 0; i < n; i++) { + for (int j = coin[i]; j <= k; j++) { + dp[j] = Math.min(dp[j], dp[j - coin[i]] + 1); + } + } + + if (dp[k] == Integer.MAX_VALUE - 1) { + ans = -1; + } else { + ans = dp[k]; + } + + System.out.println(ans); + } +} From d2c14a67a90e5fafb1a4dbd34e47db95f8b88944 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 8 Jun 2023 01:26:06 +0900 Subject: [PATCH 592/822] =?UTF-8?q?Create=20=EC=B9=B4=EB=93=9C=ED=95=A9?= =?UTF-8?q?=EC=B2=B4.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\223\234\355\225\251\354\262\264.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/06.09/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\355\225\251\354\262\264.java" diff --git "a/2023/06.09/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\355\225\251\354\262\264.java" "b/2023/06.09/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\355\225\251\354\262\264.java" new file mode 100644 index 0000000..8c37e2b --- /dev/null +++ "b/2023/06.09/\354\240\225\355\230\270\354\241\260/\354\271\264\353\223\234\355\225\251\354\262\264.java" @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collections; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class 카드합체놀이_15903 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + long ans = 0; + + st = new StringTokenizer(br.readLine()); + PriorityQueue prQueue = new PriorityQueue<>(); + + for (int i = 0; i < n; i++) { + long num = Integer.parseInt(st.nextToken()); + prQueue.add(num); + ans += num; + } + + for (int i = 0; i < m; i++) { + long x = prQueue.poll(); //숫자가 int 범위를 넘어서는지 잘 확인해야됨 + long y = prQueue.poll(); + long sum = x + y; + + prQueue.add(sum); + prQueue.add(sum); + } + + if(m != 0){ + ans = 0; + while (!prQueue.isEmpty()){ + ans += prQueue.poll(); + } + } + + System.out.println(ans); + } +} From cc60b30625d61a4890b08188c4b7839ee1daa6af Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Fri, 9 Jun 2023 15:17:42 +0900 Subject: [PATCH 593/822] BOJ 15903 Solve --- ...1\354\262\264 \353\206\200\354\235\264.kt" | 57 ++++++++++++++++ .../Main 2294 \353\217\231\354\240\204 2.kt" | 65 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 "2023/06.09/\354\265\234\354\260\275\354\230\201/Main 15903 \354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.kt" create mode 100644 "2023/06.09/\354\265\234\354\260\275\354\230\201/Main 2294 \353\217\231\354\240\204 2.kt" diff --git "a/2023/06.09/\354\265\234\354\260\275\354\230\201/Main 15903 \354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.kt" "b/2023/06.09/\354\265\234\354\260\275\354\230\201/Main 15903 \354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.kt" new file mode 100644 index 0000000..7c4ffd9 --- /dev/null +++ "b/2023/06.09/\354\265\234\354\260\275\354\230\201/Main 15903 \354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.kt" @@ -0,0 +1,57 @@ +package 자료구조_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 석환이는 자연수가 쓰여진 카드를 N장 가지고 있다. 처음에 i번 카드엔 a + 만들 수 있는 가장 작은 점수 + */ + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 // 카드의 개수 +private var M = 0 // 카드 합체 횟수 + +private var pq = PriorityQueue() + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\이분_탐색_부수기\\15903.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + val sb = StringBuilder() + + input() + + for (i in 0 until M) { + val a = pq.poll() + val b = pq.poll() + pq.offer(a + b) + pq.offer(a + b) + } + + var ans = 0L + while (pq.isNotEmpty()) { + ans += pq.poll() + } + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() + M = st.nextToken().toInt() + + st = StringTokenizer(br.readLine()) + for (i in 0 until N) { + pq.offer(st.nextToken().toLong()) + } +} // End of input diff --git "a/2023/06.09/\354\265\234\354\260\275\354\230\201/Main 2294 \353\217\231\354\240\204 2.kt" "b/2023/06.09/\354\265\234\354\260\275\354\230\201/Main 2294 \353\217\231\354\240\204 2.kt" new file mode 100644 index 0000000..02e94d3 --- /dev/null +++ "b/2023/06.09/\354\265\234\354\260\275\354\230\201/Main 2294 \353\217\231\354\240\204 2.kt" @@ -0,0 +1,65 @@ +package DP_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 첫째 줄에 사용한 동전의 최소 개수를 출력한다. + 불가능한 경우에는 -1을 출력한다. + */ + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 +private var K = 0 +private var coinArr = IntArray(101) + +// 최솟값을 구하는 문제 -> 나올 수 있는 최댓값 보다 더 큰 값으로 초기화 +private var memo = IntArray(10_001) { 10_001 } + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\DP_부수기\\res\\2294.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + DP() + + if (memo[K] == 10001) { + sb.append(-1) + } else { + sb.append(memo[K]) + } + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun DP() { + for (i in 1..N) { + val coin = coinArr[i] + + for (j in coin..K) { + memo[j] = Math.min(memo[j], memo[j - coin] + 1) + } + } +} // End of DP + +private fun input() { + val st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() + K = st.nextToken().toInt() + + for (i in 1..N) { + coinArr[i] = br.readLine().toInt() + } + + memo[0] = 0 +} // End of input From 9c3e0ac7e86933fca5a21f437197ed2b3f089641 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 9 Jun 2023 15:44:35 +0900 Subject: [PATCH 594/822] kihun --- ...51\354\262\264\353\206\200\354\235\264.py" | 22 +++++++++++++++ ...244\200_2294_\353\217\231\354\240\2042.py" | 28 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 "2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15903_\354\271\264\353\223\234\355\225\251\354\262\264\353\206\200\354\235\264.py" create mode 100644 "2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2294_\353\217\231\354\240\2042.py" diff --git "a/2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15903_\354\271\264\353\223\234\355\225\251\354\262\264\353\206\200\354\235\264.py" "b/2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15903_\354\271\264\353\223\234\355\225\251\354\262\264\353\206\200\354\235\264.py" new file mode 100644 index 0000000..55f56a5 --- /dev/null +++ "b/2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15903_\354\271\264\353\223\234\355\225\251\354\262\264\353\206\200\354\235\264.py" @@ -0,0 +1,22 @@ +import sys +import heapq + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, m = map(int, input().split()) +numbers = list(map(int, input().split())) +numbers_queue = [] + +for number in numbers: + heapq.heappush(numbers_queue, number) + +while (m > 0): + a = heapq.heappop(numbers_queue) + b = heapq.heappop(numbers_queue) + + heapq.heappush(numbers_queue, a+b) + heapq.heappush(numbers_queue, a+b) + + m -= 1 + +print(sum(numbers_queue)) diff --git "a/2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2294_\353\217\231\354\240\2042.py" "b/2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2294_\353\217\231\354\240\2042.py" new file mode 100644 index 0000000..0210f0f --- /dev/null +++ "b/2023/06.09/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2294_\353\217\231\354\240\2042.py" @@ -0,0 +1,28 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, k = map(int, input().split()) + +coins = [] + +# 낸 동전의 수를 dp 배열 +# 최소값을 구해야 하므로 기본 값은 큰 값으로 세팅 +dp = [float('inf') for _ in range(k+1)] + +# 0원은 동전 수 0개 +dp[0] = 0 + +for _ in range(n): + coins.append(int(input())) +coins.sort() + +for coin in coins: + for target in range(coin, k+1): + # dp[target]과 dp[target-coin]에서 coin을 하나 더한 것을 비교 + dp[target] = min(dp[target], dp[target-coin]+1) + +if (dp[k] == float('inf')): + print(-1) +else: + print(dp[k]) From b6caa7eb51f1bd475106d5f44366d7c500a9cc3e Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 10 Jun 2023 17:24:09 +0900 Subject: [PATCH 595/822] Create Readme.md --- 2023/06.12/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.12/Readme.md diff --git a/2023/06.12/Readme.md b/2023/06.12/Readme.md new file mode 100644 index 0000000..04334d4 --- /dev/null +++ b/2023/06.12/Readme.md @@ -0,0 +1,5 @@ +# 6.12(월) 스터디 + +- 백준 + - [센서](https://www.acmicpc.net/problem/2212) + - [평범한 배낭](https://www.acmicpc.net/problem/12865) From 2ffd4d2551e13aa0c3056dbc50afec23b342cef7 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 12 Jun 2023 15:42:43 +0900 Subject: [PATCH 596/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=B0=B1?= =?UTF-8?q?=EC=A4=80=202212=EB=B2=88=20=EC=84=BC=EC=84=9C=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\204\274\354\204\234.kt" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/06.12/\354\241\260\354\210\230\354\227\260/\354\204\274\354\204\234.kt" diff --git "a/2023/06.12/\354\241\260\354\210\230\354\227\260/\354\204\274\354\204\234.kt" "b/2023/06.12/\354\241\260\354\210\230\354\227\260/\354\204\274\354\204\234.kt" new file mode 100644 index 0000000..92f06d5 --- /dev/null +++ "b/2023/06.12/\354\241\260\354\210\230\354\227\260/\354\204\274\354\204\234.kt" @@ -0,0 +1,40 @@ +import java.util.* +import java.io.* +import kotlin.collections.ArrayList + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + val k = readLine().toInt() + + if (k >= n) bw.write("0") // 집중국의 갯수가 센서의 개수보다 같거나 많을경우 수신 가능 영역의 길이는 0 + else { + val token = StringTokenizer(readLine()) + val pList = ArrayList() + + repeat(n) { + pList.add(token.nextToken().toInt()) + } + + pList.sort() // 위치순으로 정렬 + + val iList = ArrayList() // 정렬된 좌표 위치 사이의 거리 리스트 + + for (i in 0 until n - 1) { + iList.add(pList[i + 1] - pList[i]) + } + + repeat(k - 1) {// k-1개의 분기점이 생기므로 좌표 위치 사이의 거리 리스트에 k-1개만큼 최대값을 뺀다 + iList.remove(iList.max()) + } + + bw.write("${iList.sum()}") // 최댓값을 빼고 난 후 거리의 합 + } + + + bw.flush() + bw.close() +} + From 1d14cb317191d03679dcd2aac78b47d42765088b Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Mon, 12 Jun 2023 16:04:00 +0900 Subject: [PATCH 597/822] BOJ 2212 Solve --- .../Main 2212 \354\204\274\354\204\234.kt" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "2023/06.12/\354\265\234\354\260\275\354\230\201/Main 2212 \354\204\274\354\204\234.kt" diff --git "a/2023/06.12/\354\265\234\354\260\275\354\230\201/Main 2212 \354\204\274\354\204\234.kt" "b/2023/06.12/\354\265\234\354\260\275\354\230\201/Main 2212 \354\204\274\354\204\234.kt" new file mode 100644 index 0000000..e29efdb --- /dev/null +++ "b/2023/06.12/\354\265\234\354\260\275\354\230\201/Main 2212 \354\204\274\354\204\234.kt" @@ -0,0 +1,65 @@ +package 그리디_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 고속도로 위에 최대 K개의 집중국을 세울 수 있다고 한다. + N개의 센서가 적어도 하나의 집중국과는 통신이 가능해야 하며, 집중국의 유지비 문제로 인해 각 집중국의 수신 가능 영역의 길이의 합을 최소화해야 한다. + + + 첫째 줄에 문제에서 설명한 최대 K개의 집중국의 수신 가능 영역의 길이의 합의 최솟값을 출력한다. + */ + + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 // 센서의 개수 N +private var K = 0 // 집중국의 개수 K +private lateinit var sensorArr: IntArray + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\그리디_부수기\\2212.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + val diffArr = IntArray(N - 1) + for (i in 0 until N - 1) { + diffArr[i] = sensorArr[i + 1] - sensorArr[i] + } + + diffArr.sortDescending() + + var ans = 0 + for (i in K - 1 until N - 1) { + ans += diffArr[i] + } + + sb.append(ans) + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + N = br.readLine().toInt() + K = br.readLine().toInt() + + sensorArr = IntArray(N) + + val st = StringTokenizer(br.readLine()) + for (i in 0 until N) { + val tmp = st.nextToken().toInt() + sensorArr[i] = tmp + } + + sensorArr.sort() +} // End of input \ No newline at end of file From 335dcbf16abe003d0cfb5720675113d35dc01db8 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 12 Jun 2023 16:53:15 +0900 Subject: [PATCH 598/822] kihun --- ...24\355\225\234\353\260\260\353\202\255.py" | 26 +++++++++++++++++++ ...\244\200_2212_\354\204\274\354\204\234.py" | 17 ++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 "2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12865_\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.py" create mode 100644 "2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2212_\354\204\274\354\204\234.py" diff --git "a/2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12865_\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.py" "b/2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12865_\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.py" new file mode 100644 index 0000000..7d51573 --- /dev/null +++ "b/2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_12865_\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.py" @@ -0,0 +1,26 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, k = map(int, input().split()) + +things = [(0, 0)] + +for i in range(n): + w, v = map(int, input().split()) + things.append((w, v)) + +things = sorted(things, key=lambda x: x[0]) + +dp = [[0 for _ in range(k+1)] for _ in range(n+1)] + +for i in range(1, n+1): + w, v = things[i] + for j in range(1, k+1): + if j < w: + # 꺼낸 무게가 j보다 크면 이전 물건의 값으로 대체 + dp[i][j] = dp[i-1][j] + else: + dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v) + +print(dp[n][k]) diff --git "a/2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2212_\354\204\274\354\204\234.py" "b/2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2212_\354\204\274\354\204\234.py" new file mode 100644 index 0000000..7624fa2 --- /dev/null +++ "b/2023/06.12/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2212_\354\204\274\354\204\234.py" @@ -0,0 +1,17 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) +k = int(input()) + +sensor_list = list(map(int, input().split())) +sensor_list.sort() + +distance_list = [] +for i in range(0, n-1): + distance_list.append(sensor_list[i+1] - sensor_list[i]) + +distance_list.sort() + +print(sum(distance_list[:n-k])) From 0f7902ee33740e58c73abbd8081bd7d757fc5460 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 12 Jun 2023 17:18:15 +0900 Subject: [PATCH 599/822] Create Readme.md --- 2023/06.15/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.15/Readme.md diff --git a/2023/06.15/Readme.md b/2023/06.15/Readme.md new file mode 100644 index 0000000..fc7255c --- /dev/null +++ b/2023/06.15/Readme.md @@ -0,0 +1,5 @@ +# 6.15(목) 스터디 + +- 백준 + - [합분해](https://www.acmicpc.net/problem/2225) + - [창영이와 커피](https://www.acmicpc.net/problem/22115) From 52ef2f9e53f5e44a22d4941bdf78fe0580ee3a57 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:20:00 +0900 Subject: [PATCH 600/822] =?UTF-8?q?Create=20=ED=8F=89=EB=B2=94=ED=95=9C?= =?UTF-8?q?=EB=B0=B0=EB=82=AD.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\234\353\260\260\353\202\255.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/06.12/\354\240\225\355\230\270\354\241\260/\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.java" diff --git "a/2023/06.12/\354\240\225\355\230\270\354\241\260/\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.java" "b/2023/06.12/\354\240\225\355\230\270\354\241\260/\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.java" new file mode 100644 index 0000000..43abff3 --- /dev/null +++ "b/2023/06.12/\354\240\225\355\230\270\354\241\260/\355\217\211\353\262\224\355\225\234\353\260\260\353\202\255.java" @@ -0,0 +1,40 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 평범한배낭_12865 { + static int N, K, ans; + static int[] W, V; + static int[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + dp = new int[N + 1][K + 1]; + W = new int[N + 1]; + V = new int[N + 1]; + + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + W[i] = Integer.parseInt(st.nextToken()); + V[i] = Integer.parseInt(st.nextToken()); + } + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= K; j++) { // j가 현재 dp에 담을 무게 + if (W[i] > j) { + dp[i][j] = dp[i - 1][j]; + } else { + dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - W[i]] + V[i]); + } + } + } + + System.out.println(dp[N][K]); + } +} From 521e391495c4b9c64fcfb6c65416e66c8b59a1e3 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:20:16 +0900 Subject: [PATCH 601/822] =?UTF-8?q?Create=20=EC=84=BC=EC=84=9C.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\204\274\354\204\234.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/06.12/\354\240\225\355\230\270\354\241\260/\354\204\274\354\204\234.java" diff --git "a/2023/06.12/\354\240\225\355\230\270\354\241\260/\354\204\274\354\204\234.java" "b/2023/06.12/\354\240\225\355\230\270\354\241\260/\354\204\274\354\204\234.java" new file mode 100644 index 0000000..2cdc0fc --- /dev/null +++ "b/2023/06.12/\354\240\225\355\230\270\354\241\260/\354\204\274\354\204\234.java" @@ -0,0 +1,40 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 센서_2212 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + int K = Integer.parseInt(br.readLine()); + int[] censor = new int[N]; + int[] dif = new int[N - 1]; + int ans = 0; + + if (K >= N) { + System.out.println(0); + return; + } + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + censor[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(censor); + + for (int i = 0; i < N - 1; i++) { + dif[i] = censor[i + 1] - censor[i]; + } + Arrays.sort(dif); + + for (int i = 0; i < N - K; i++) { + ans += dif[i]; + } + + System.out.println(ans); + } +} From e91cbbd670cd672a1ec46c577a59312e14ca969d Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 15 Jun 2023 15:57:02 +0900 Subject: [PATCH 602/822] 0615 kihun --- ...64\354\231\200\354\273\244\355\224\274.py" | 39 +++++++++++++++++++ ...5_\355\225\251\353\266\204\355\225\264.py" | 20 ++++++++++ 2 files changed, 59 insertions(+) create mode 100644 "2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_22115_\354\260\275\354\230\201\354\235\264\354\231\200\354\273\244\355\224\274.py" create mode 100644 "2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2225_\355\225\251\353\266\204\355\225\264.py" diff --git "a/2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_22115_\354\260\275\354\230\201\354\235\264\354\231\200\354\273\244\355\224\274.py" "b/2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_22115_\354\260\275\354\230\201\354\235\264\354\231\200\354\273\244\355\224\274.py" new file mode 100644 index 0000000..48b8635 --- /dev/null +++ "b/2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_22115_\354\260\275\354\230\201\354\235\264\354\231\200\354\273\244\355\224\274.py" @@ -0,0 +1,39 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, k = map(int, input().split()) + +c_list = [0] + list(map(int, input().split())) + +dp = [[0 for _ in range(k+1)] for _ in range(n+1)] + +for i in range(1, k+1): + dp[0][i] = float('inf') + + +for idx in range(1, n+1): + now_caffeine = c_list[idx] + for caffeine in range(1, k+1): + # 현재 커피의 카페인이 dp-카페인보다 크면 이전 값으로 대체 + if caffeine < now_caffeine: + dp[idx][caffeine] = dp[idx-1][caffeine] + else: + dp[idx][caffeine] = min( + dp[idx-1][caffeine], dp[idx-1][caffeine - now_caffeine] + 1) + +if dp[n][k] == float('inf'): + print(-1) +else: + print(dp[n][k]) + +""" +1. c_list에 [0]을 추가한 것 +- dp 2차원 배열에서 0개를 골랐다는 개념을 위해서 필요하다. + +2. dp 2차원 배열은 커피 n개를 골라서 k의 카페인을 만족하는 커피의 수 + +3. dp[0]에서... +- dp[0][0]은 커피 0개를 골라서 카페인이 0인 경우는 커피 "0"개를 먹으면 되니까 0으로 세팅 +- dp[0][1:k+1]은 커피 0개를 골라서 카페인이 i인 경우는 불가능하므로 inf로 세팅 +""" diff --git "a/2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2225_\355\225\251\353\266\204\355\225\264.py" "b/2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2225_\355\225\251\353\266\204\355\225\264.py" new file mode 100644 index 0000000..be0ada5 --- /dev/null +++ "b/2023/06.15/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_2225_\355\225\251\353\266\204\355\225\264.py" @@ -0,0 +1,20 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n, k = map(int, input().split()) + +""" +6 4 +6 = (0 + (6을 4분해)) + (1 + (5를 3분해)) + ... ((6을 4분해) + 0) +""" + +dp = [[0 for _ in range(n+1)] for _ in range(k+1)] + +dp[0][0] = 1 + +for i in range(1, k+1): + for j in range(0, n+1): + dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 1000000000 + +print(dp[k][n]) From e7381c248697cc9912e521f73e46dc22e9f1990a Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 15 Jun 2023 17:27:41 +0900 Subject: [PATCH 603/822] =?UTF-8?q?Create=20=ED=95=A9=EB=B6=84=ED=95=B4.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\251\353\266\204\355\225\264.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "2023/06.15/\354\240\225\355\230\270\354\241\260/\355\225\251\353\266\204\355\225\264.java" diff --git "a/2023/06.15/\354\240\225\355\230\270\354\241\260/\355\225\251\353\266\204\355\225\264.java" "b/2023/06.15/\354\240\225\355\230\270\354\241\260/\355\225\251\353\266\204\355\225\264.java" new file mode 100644 index 0000000..664dc1c --- /dev/null +++ "b/2023/06.15/\354\240\225\355\230\270\354\241\260/\355\225\251\353\266\204\355\225\264.java" @@ -0,0 +1,30 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 합분해_2225 { + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + int[][] dp = new int[K + 1][N + 1]; + + for (int i = 1; i <= K; i++) { + dp[i][0] = 1; + } + + for (int i = 1; i <= K; i++) { + for (int j = 1; j <= N; j++) { + dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000000; + } + } + + System.out.println(dp[K][N]); + } +} From 3b36a70a0e64d6c37ea39a9aab784f77d0e0ee33 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:38:10 +0900 Subject: [PATCH 604/822] Create 06.19 --- 2023/06.19 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.19 diff --git a/2023/06.19 b/2023/06.19 new file mode 100644 index 0000000..06bb5a3 --- /dev/null +++ b/2023/06.19 @@ -0,0 +1,5 @@ +# 6.19(월) 스터디 + +- 백준 + - [돌게임2](https://www.acmicpc.net/problem/9656) + - [톱니바퀴2](https://www.acmicpc.net/problem/15662) From 09aef3abe8a7e3c35a0e39b7eb114ad3519f186f Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:39:42 +0900 Subject: [PATCH 605/822] Delete 06.19 --- 2023/06.19 | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 2023/06.19 diff --git a/2023/06.19 b/2023/06.19 deleted file mode 100644 index 06bb5a3..0000000 --- a/2023/06.19 +++ /dev/null @@ -1,5 +0,0 @@ -# 6.19(월) 스터디 - -- 백준 - - [돌게임2](https://www.acmicpc.net/problem/9656) - - [톱니바퀴2](https://www.acmicpc.net/problem/15662) From 8594c01400dc895511ff36cc2551fa663f5e1e8d Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:40:23 +0900 Subject: [PATCH 606/822] Create Readme.md --- 2023/06.19/Readme.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/06.19/Readme.md diff --git a/2023/06.19/Readme.md b/2023/06.19/Readme.md new file mode 100644 index 0000000..06bb5a3 --- /dev/null +++ b/2023/06.19/Readme.md @@ -0,0 +1,5 @@ +# 6.19(월) 스터디 + +- 백준 + - [돌게임2](https://www.acmicpc.net/problem/9656) + - [톱니바퀴2](https://www.acmicpc.net/problem/15662) From c030dd3913499785beace690d13c3dce9d84e253 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:40:45 +0900 Subject: [PATCH 607/822] =?UTF-8?q?Create=20=EB=8F=8C=EA=B2=8C=EC=9E=842.j?= =?UTF-8?q?ava?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\217\214\352\262\214\354\236\2042.java" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "2023/06.19/\354\240\225\355\230\270\354\241\260/\353\217\214\352\262\214\354\236\2042.java" diff --git "a/2023/06.19/\354\240\225\355\230\270\354\241\260/\353\217\214\352\262\214\354\236\2042.java" "b/2023/06.19/\354\240\225\355\230\270\354\241\260/\353\217\214\352\262\214\354\236\2042.java" new file mode 100644 index 0000000..717dcb7 --- /dev/null +++ "b/2023/06.19/\354\240\225\355\230\270\354\241\260/\353\217\214\352\262\214\354\236\2042.java" @@ -0,0 +1,17 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 돌게임2_9656 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + if(N % 2 == 0){ + System.out.println("SK"); + } else { + System.out.println("CY"); + } + } +} From 66673a2efe46111f887a85cc6d35cf16f397a63b Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 19 Jun 2023 16:10:13 +0900 Subject: [PATCH 608/822] 0619 kihun --- ...1\353\213\210\353\260\224\355\200\2642.py" | 65 +++++++++++ ..._\353\217\214\352\262\214\354\236\2042.py" | 20 ++++ ...353\213\210\353\260\224\355\200\2642.java" | 101 ++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 "2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15662_\355\206\261\353\213\210\353\260\224\355\200\2642.py" create mode 100644 "2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_9656_\353\217\214\352\262\214\354\236\2042.py" create mode 100644 "2023/06.19/\354\206\241\352\270\260\355\233\210/\355\206\261\353\213\210\353\260\224\355\200\2642.java" diff --git "a/2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15662_\355\206\261\353\213\210\353\260\224\355\200\2642.py" "b/2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15662_\355\206\261\353\213\210\353\260\224\355\200\2642.py" new file mode 100644 index 0000000..ae02f54 --- /dev/null +++ "b/2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_15662_\355\206\261\353\213\210\353\260\224\355\200\2642.py" @@ -0,0 +1,65 @@ +import sys +from collections import deque + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + + +def check_right(t_num, t_list, t): + result = [] + i = t_num + while i < t-1: + if t_list[i][2] == t_list[i+1][6]: + break + else: + result.append(i+1) + i += 1 + return result + + +def check_left(t_num, t_list): + result = [] + i = t_num + while i > 0: + if t_list[i][6] == t_list[i-1][2]: + break + else: + result.append(i-1) + i -= 1 + return result + + +t = int(input()) + +t_list = [] +for _ in range(t): + t_list.append(deque(map(int, list(input())))) + +k = int(input()) +for _ in range(k): + t_num, direction = map(int, input().split()) + t_num -= 1 + temp_direction = direction + + right_list = check_right(t_num, t_list, t) + left_list = check_left(t_num, t_list) + + # 처음 것 돌리기 + t_list[t_num].rotate(temp_direction) + + # 오른쪽 것을 방향을 바꿔가며 돌림 + for index in right_list: + temp_direction *= -1 + t_list[index].rotate(temp_direction) + + # 초기 방향으로 초기화하고 왼쪽 것을 방향을 바꿔가며 돌림 + temp_direction = direction + for index in left_list: + temp_direction *= -1 + t_list[index].rotate(temp_direction) + + +count = 0 +for gear in t_list: + if (gear[0] == 1): + count += 1 +print(count) diff --git "a/2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_9656_\353\217\214\352\262\214\354\236\2042.py" "b/2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_9656_\353\217\214\352\262\214\354\236\2042.py" new file mode 100644 index 0000000..3050b2e --- /dev/null +++ "b/2023/06.19/\354\206\241\352\270\260\355\233\210/\353\260\261\354\244\200_9656_\353\217\214\352\262\214\354\236\2042.py" @@ -0,0 +1,20 @@ +import sys + +sys.stdin = open("input.txt", "r", encoding="UTF-8") + +n = int(input()) + +if (n % 2 == 1): + print("CY") +else: + print("SK") + +""" +n = 1 상 -> CY +n = 2 상 창 -> SK +n = 3 상 창 상 -> CY +n = 4 상 상 상 창 -> SK + 상 창 상 창 +n = 5 상 상 상 창 상 -> CY + 상 창 상 창 상 +""" diff --git "a/2023/06.19/\354\206\241\352\270\260\355\233\210/\355\206\261\353\213\210\353\260\224\355\200\2642.java" "b/2023/06.19/\354\206\241\352\270\260\355\233\210/\355\206\261\353\213\210\353\260\224\355\200\2642.java" new file mode 100644 index 0000000..c09e7e9 --- /dev/null +++ "b/2023/06.19/\354\206\241\352\270\260\355\233\210/\355\206\261\353\213\210\353\260\224\355\200\2642.java" @@ -0,0 +1,101 @@ +package baekjoon.gold; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class 톱니바퀴2 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + int[][] gears = new int[T][8]; + + for (int i = 0; i < T; i++) { + String temp = br.readLine(); + for (int j = 0; j < 8; j++) { + gears[i][j] = temp.charAt(j) - 48; + } + } + int K = Integer.parseInt(br.readLine()); + + for (int i = 0; i < K; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int index = Integer.parseInt(st.nextToken()) - 1; + int direction = Integer.parseInt(st.nextToken()); + int tempDirection = direction; + + ArrayList rightList = check(1, index, gears, T); + ArrayList leftList = check(0, index, gears, T); + + // 자기 자신 돌리기 + gears[index] = rotation(tempDirection, gears[index]); + + // 오른쪽 돌리기 + for (Integer rightIndex : rightList) { + tempDirection *= -1; + gears[rightIndex] = rotation(tempDirection, gears[rightIndex]); + } + + // 방향 초기화 후 왼쪽 돌리기 + tempDirection = direction; + for (Integer leftIndex : leftList) { + tempDirection *= -1; + gears[leftIndex] = rotation(tempDirection, gears[leftIndex]); + } + + } + + int count = 0; + for (int[] gear : gears) { + if (gear[0] == 1) { + count += 1; + } + } + System.out.println(count); + } + + public static int[] rotation(int direction, int[] gear) { + int save, index; + + if (direction == -1) { + save = gear[0]; + index = 0; + } else { + save = gear[7]; + index = 7; + } + + for (int i = 0; i < 7; i++) { + gear[index] = gear[index - direction]; + index -= direction; + } + gear[index] = save; + return gear; + } + + public static ArrayList check(int direction, int index, int[][] gears, int T) { + ArrayList result = new ArrayList<>(); + int i = index; + + if (direction == 1) { + // 오른쪽 + while (i < T - 1) { + if (gears[i][2] == gears[i + 1][6]) break; + else result.add(i + 1); + i += 1; + } + } else { + // 왼쪽 + while (i > 0) { + if (gears[i][6] == gears[i - 1][2]) break; + else result.add(i - 1); + i -= 1; + } + } + return result; + } + +} From 95cda4fc5e5bf03bb1cd7c77b74c01c2cce409a4 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 23 Jun 2023 14:20:16 +0900 Subject: [PATCH 609/822] 0622 kihun --- 2023/06.22/Readme.md | 5 +++ .../RGB\352\261\260\353\246\254.java" | 41 +++++++++++++++++ ...353\266\204\354\210\230\354\227\2642.java" | 45 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 2023/06.22/Readme.md create mode 100644 "2023/06.22/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\254.java" create mode 100644 "2023/06.22/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\2642.java" diff --git a/2023/06.22/Readme.md b/2023/06.22/Readme.md new file mode 100644 index 0000000..9fcaf17 --- /dev/null +++ b/2023/06.22/Readme.md @@ -0,0 +1,5 @@ +# 6.22(목) 스터디 + +- 백준 + - [RGB거리2](https://www.acmicpc.net/problem/1149) + - [가장 긴 증가하는 부분 수열 2](https://www.acmicpc.net/problem/12015) diff --git "a/2023/06.22/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\254.java" "b/2023/06.22/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\254.java" new file mode 100644 index 0000000..a3d40bb --- /dev/null +++ "b/2023/06.22/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\254.java" @@ -0,0 +1,41 @@ +package baekjoon.silver; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class RGB거리 { + + final static int RED = 0; + final static int GREEN = 1; + final static int BLUE = 2; + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; + static int[][] dp; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + dp = new int[N + 1][3]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int red = Integer.parseInt(st.nextToken()); + int green = Integer.parseInt(st.nextToken()); + int blue = Integer.parseInt(st.nextToken()); + + dp[i + 1][RED] = Math.min(dp[i][GREEN], dp[i][BLUE]) + red; + dp[i + 1][GREEN] = Math.min(dp[i][RED], dp[i][BLUE]) + green; + dp[i + 1][BLUE] = Math.min(dp[i][RED], dp[i][GREEN]) + blue; + } + + System.out.println( + Math.min( + Math.min(dp[N][RED], dp[N][GREEN]), + dp[N][BLUE] + ) + ); + + } + +} \ No newline at end of file diff --git "a/2023/06.22/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\2642.java" "b/2023/06.22/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\2642.java" new file mode 100644 index 0000000..27b39e2 --- /dev/null +++ "b/2023/06.22/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245\352\270\264\354\246\235\352\260\200\355\225\230\353\212\224\353\266\200\353\266\204\354\210\230\354\227\2642.java" @@ -0,0 +1,45 @@ +package baekjoon.gold; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +// https://dragon-h.tistory.com/2 +// https://loosie.tistory.com/376 + +public class 가장긴증가하는부분수열2 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + int[] numbers = new int[n]; + List LIS = new ArrayList<>(); + LIS.add(0); + + StringTokenizer st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < n; i++) { + int value = numbers[i] = Integer.parseInt(st.nextToken()); + if (value > LIS.get(LIS.size() - 1)) LIS.add(value); + else { + int left = 0; + int right = LIS.size() - 1; + + while (left < right) { + int mid = (int)Math.floor((left + right) / 2); + //int mid = (left + right) >> 1; + if (LIS.get(mid) >= value) { + right = mid; + } else { + left = mid + 1; + } + } + LIS.set(right, value); + } + } + System.out.println(LIS.size() - 1); + } +} From 03de06314821dd0073fcffe8a6ca3614b0d429c2 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Mon, 26 Jun 2023 10:51:38 +0900 Subject: [PATCH 610/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20=EB=AA=B0=EC=95=84?= =?UTF-8?q?=EC=84=9C=20push=20=ED=95=A8=20=E3=85=88=E3=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\231\200 \354\273\244\355\224\274.kt" | 56 ++++++++++++ ...353\217\214 \352\262\214\354\236\204 2.kt" | 48 ++++++++++ ... RGB\352\261\260\353\246\254 Bottom-Up.kt" | 29 ++++++ ...9 RGB\352\261\260\353\246\254 Top-Down.kt" | 47 ++++++++++ ...RGB\352\261\260\353\246\254_BottomUp.java" | 32 +++++++ ..._RGB\352\261\260\353\246\254_TopDown.java" | 57 ++++++++++++ ...6 \354\247\200\353\246\204\352\270\270.kt" | 89 +++++++++++++++++++ 7 files changed, 358 insertions(+) create mode 100644 "2023/06.15/\354\265\234\354\260\275\354\230\201/Main 22115 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.kt" create mode 100644 "2023/06.19/\354\265\234\354\260\275\354\230\201/Main 9656 \353\217\214 \352\262\214\354\236\204 2.kt" create mode 100644 "2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Bottom-Up.kt" create mode 100644 "2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Top-Down.kt" create mode 100644 "2023/06.22/\354\265\234\354\260\275\354\230\201/Main_1149_RGB\352\261\260\353\246\254_BottomUp.java" create mode 100644 "2023/06.22/\354\265\234\354\260\275\354\230\201/Main_1149_RGB\352\261\260\353\246\254_TopDown.java" create mode 100644 "2023/6.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" diff --git "a/2023/06.15/\354\265\234\354\260\275\354\230\201/Main 22115 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.kt" "b/2023/06.15/\354\265\234\354\260\275\354\230\201/Main 22115 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.kt" new file mode 100644 index 0000000..12c6acf --- /dev/null +++ "b/2023/06.15/\354\265\234\354\260\275\354\230\201/Main 22115 \354\260\275\354\230\201\354\235\264\354\231\200 \354\273\244\355\224\274.kt" @@ -0,0 +1,56 @@ +package DP_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 // +private var K = 0 +private var C = 0 + +private const val INF = Int.MAX_VALUE + +private lateinit var caffeines: IntArray +private lateinit var memo: IntArray + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\DP_부수기\\res\\22115.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + println(memo[K]) + + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() + K = st.nextToken().toInt() + + caffeines = IntArray(N) + st = StringTokenizer(br.readLine()) + + memo = IntArray(K + 1) { INF } + memo[0] = 0 + + var index = 0 + repeat(N) { + caffeines[index++] = st.nextToken().toInt() + + for (i in K downTo C) { + Math.min(memo[i], memo[i - C] + 1) + } + } +} // End of input diff --git "a/2023/06.19/\354\265\234\354\260\275\354\230\201/Main 9656 \353\217\214 \352\262\214\354\236\204 2.kt" "b/2023/06.19/\354\265\234\354\260\275\354\230\201/Main 9656 \353\217\214 \352\262\214\354\236\204 2.kt" new file mode 100644 index 0000000..63a67ef --- /dev/null +++ "b/2023/06.19/\354\265\234\354\260\275\354\230\201/Main 9656 \353\217\214 \352\262\214\354\236\204 2.kt" @@ -0,0 +1,48 @@ +package DP_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 +private var memo = IntArray(1_001) + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\DP_부수기\\res\\9656.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + memo[1] = 1 + memo[2] = 2 + memo[3] = 1 + + + DP() + println(memo.contentToString()) + if (memo[N] % 2 == 0) { + sb.append("SK") + } else { + sb.append("CY") + } + + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun DP() { + for (i in 4 .. N) { + memo[i] = Math.min(memo[i - 1], memo[i - 3]) + 1 + } +} // End of DP + +private fun input() { + N = br.readLine().toInt() +} // End of input diff --git "a/2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Bottom-Up.kt" "b/2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Bottom-Up.kt" new file mode 100644 index 0000000..e5ad75e --- /dev/null +++ "b/2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Bottom-Up.kt" @@ -0,0 +1,29 @@ +import java.util.* +import java.io.* + +private const val Red = 0; private const val Green = 1; private const val Blue = 2; +private lateinit var memo : Array +private var N = 0; + +fun main() { + val path = "C:\\Users\\Samsung\\Desktop\\코틀린 알고리즘\\src\\main\\kotlin\\DP 부수기\\res\\1149.txt" + val br = BufferedReader( File(path).bufferedReader() ) + + N = br.readLine().toInt() + memo = Array(N, {IntArray(3)}) + + for(i in 0 until N) { + var st = StringTokenizer(br.readLine()) + memo[i][Red] = st.nextToken().toInt() + memo[i][Green] = st.nextToken().toInt() + memo[i][Blue] = st.nextToken().toInt() + } + + for(i in 1 until N) { + memo[i][Red] += Math.min(memo[i-1][Green], memo[i-1][Blue]); + memo[i][Green] += Math.min(memo[i-1][Red], memo[i-1][Blue]); + memo[i][Blue] += Math.min(memo[i-1][Red], memo[i-1][Green]); + } + + print( Math.min(memo[N-1][Red], Math.min(memo[N-1][Green], memo[N-1][Blue]) )) +} // End of main \ No newline at end of file diff --git "a/2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Top-Down.kt" "b/2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Top-Down.kt" new file mode 100644 index 0000000..cc8683c --- /dev/null +++ "b/2023/06.22/\354\265\234\354\260\275\354\230\201/Main 1149 RGB\352\261\260\353\246\254 Top-Down.kt" @@ -0,0 +1,47 @@ +import java.util.* +import java.io.* + +private const val Red = 0; private const val Green = 1; private const val Blue = 2; +private lateinit var memo : Array +private lateinit var arr : Array +private var N = 0; + +fun main() { + val path = "C:\\Users\\Samsung\\Desktop\\코틀린 알고리즘\\src\\main\\kotlin\\DP 부수기\\res\\1149.txt" + val br = BufferedReader( File(path).bufferedReader() ) + + N = br.readLine().toInt() + memo = Array(N, {IntArray(3)}) + arr = Array(N, {IntArray(3)}) + + for(i in 0 until N) { + var st = StringTokenizer(br.readLine()) + arr[i][Red] = st.nextToken().toInt() + arr[i][Green] = st.nextToken().toInt() + arr[i][Blue] = st.nextToken().toInt() + } + + memo[0][Red] = arr[0][Red] + memo[0][Green] = arr[0][Green] + memo[0][Blue] = arr[0][Blue] + + print( Math.min(DP(N-1, Red), Math.min(DP(N-1, Green), DP(N-1, Blue)))) +} // End of main + +private fun DP(N : Int, color : Int) : Int { + + if(memo[N][color] == 0) { + + if(color == Red) { + memo[N][Red] = Math.min( DP(N-1, Green), DP(N-1, Blue)) + arr[N][Red]; + } + else if(color == Green) { + memo[N][Green] = Math.min( DP(N-1, Red), DP(N-1, Blue)) + arr[N][Green]; + } + else if(color == Blue) { + memo[N][Blue] = Math.min( DP(N-1, Red), DP(N-1, Green)) + arr[N][Blue]; + } + } + + return memo[N][color]; +} // End of DP \ No newline at end of file diff --git "a/2023/06.22/\354\265\234\354\260\275\354\230\201/Main_1149_RGB\352\261\260\353\246\254_BottomUp.java" "b/2023/06.22/\354\265\234\354\260\275\354\230\201/Main_1149_RGB\352\261\260\353\246\254_BottomUp.java" new file mode 100644 index 0000000..c8eb05f --- /dev/null +++ "b/2023/06.22/\354\265\234\354\260\275\354\230\201/Main_1149_RGB\352\261\260\353\246\254_BottomUp.java" @@ -0,0 +1,32 @@ +import java.util.*; +import java.io.*; + +public class Main_1149_RGB거리_BottomUp { + final static int Red = 0; + final static int Green = 1; + final static int Blue = 2; + + public static void main(String[] args) throws Exception{ + System.setIn(new FileInputStream("res/1149.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + int memo[][] = new int[N][3]; + + for(int i=0; i> +private var dist = IntArray(10001) { INF } + +private data class Road(var location: Int, var dist: Int) : Comparable { + override fun compareTo(other: Road): Int { + return dist - other.dist + } // End of compareTo +} // End of Road class + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\다익스트라_부수기\\1446.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + dijkstra() + sb.append(dist[D]) + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun dijkstra() { + val pque = PriorityQueue() + pque.offer(Road(0, 0)) + dist[0] = 0 + + while (pque.isNotEmpty()) { + val poll = pque.poll() + + if (poll.dist != dist[poll.location]) continue + if(poll.location >= D) continue + + val size = adjList[poll.location].size + for (i in 0 until size) { + val nextRoad = adjList[poll.location][i] + + if (dist[nextRoad.location] > dist[poll.location] + nextRoad.dist) { + dist[nextRoad.location] = dist[poll.location] + nextRoad.dist + pque.offer(Road(nextRoad.location, dist[nextRoad.location])) + } + } + } +} // End of dijkstra + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() // 지름길의 개수 + D = st.nextToken().toInt() // 고속도로의 길이 + + adjList = ArrayList() + for(i in 0 until D) { + adjList.add(ArrayList()) + adjList[i].add(Road(i + 1, 1)) + } + + for (i in 0 until N) { + st = StringTokenizer(br.readLine()) + val startLocation = st.nextToken().toInt() // u + val endLocation = st.nextToken().toInt() // v + val dist = st.nextToken().toInt() // w + + // 역주행 불가 + if (endLocation > D) continue + + // 원래 가는 길이보다 지름길의 길이가 같거나 큰 경우 + if (dist >= (endLocation - startLocation)) continue + adjList[startLocation].add(Road(endLocation, dist)) + } + +} // End of input From 5439a8a520a011863ac91dc0da44b6af89e5e6a7 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 26 Jun 2023 10:59:31 +0900 Subject: [PATCH 611/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=A4=84?= =?UTF-8?q?=EC=96=B4=EB=93=A4=EC=A7=80=20=EC=95=8A=EC=95=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\247\200_\354\225\212\354\225\204.java" | 37 +++++++++++++++++++ ...4\354\247\200_\354\225\212\354\225\204.kt" | 29 +++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 "2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" create mode 100644 "2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" diff --git "a/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" "b/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" new file mode 100644 index 0000000..7b3d5c0 --- /dev/null +++ "b/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" @@ -0,0 +1,37 @@ +import java.io.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int t = Integer.parseInt(br.readLine()); + long[][] dp = new long[65][10]; + + for (int i = 0; i <= 9; i++) { + dp[1][i] = 1; + } + + for (int i = 2; i < dp.length; i++) { + for (int j = 0; j < dp.length; j++) { + for (int k = j; k <= 9; k++) { + dp[i][j] += dp[i-1][k]; + } + } + } + + for (int i = 0; i < t; i++) { + int n = Integer.parseInt(br.readLine()); + long sum = 0; + + for (int j = 0; j <= 9; j++) { + sum += dp[n][j]; + } + + bw.write(sum+"\n"); + } + + bw.flush(); + bw.close(); + } +} \ No newline at end of file diff --git "a/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" "b/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" new file mode 100644 index 0000000..732491d --- /dev/null +++ "b/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" @@ -0,0 +1,29 @@ +import java.io.* + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val t = readLine().toInt() + val dp = Array(65){LongArray(10)} + + for (i in 0 .. 9){ + dp[1][i] = 1 + } + + for (i in 2 until dp.size){ + for (j in dp[i].indices){ // ex) dp[2][0]에는 0 ~ 9까지 들어갈 수 있으므로 += dp[i-1][k]에서 k가 0~9까지 들어갈 수 있다. + for (k in j .. 9) // 해당 숫자부터 9까지 들어갈 수 있다. + { + dp[i][j] += dp[i-1][k] + } + } + } + + repeat(t){ + bw.write("${dp[readLine().toInt() ].sum()}\n") + } + + bw.flush() + bw.close() +} \ No newline at end of file From 9031b02b78fde61401c7c63bc17cc460b37bd0c3 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 26 Jun 2023 11:00:45 +0900 Subject: [PATCH 612/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=20=EC=A4=84?= =?UTF-8?q?=EC=96=B4=EB=93=A4=EC=A7=80=20=EC=95=8A=EC=95=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" | 0 ...4\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename "2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" => "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" (100%) rename "2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" => "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" (100%) diff --git "a/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" "b/2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" similarity index 100% rename from "2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" rename to "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" diff --git "a/2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" "b/2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" similarity index 100% rename from "2023/06.23/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" rename to "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" From e563b48e4e21c4a942286a0843070ff1979607cb Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 26 Jun 2023 11:01:41 +0900 Subject: [PATCH 613/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=20=EC=A4=84?= =?UTF-8?q?=EC=96=B4=EB=93=A4=EC=A7=80=20=EC=95=8A=EC=95=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" | 0 ...4\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" => "2023/06.26/\354\241\260\354\210\230\354\227\260/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" (100%) rename "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" => "2023/06.26/\354\241\260\354\210\230\354\227\260/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" (100%) diff --git "a/2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" "b/2023/06.26/\354\241\260\354\210\230\354\227\260/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" similarity index 100% rename from "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" rename to "2023/06.26/\354\241\260\354\210\230\354\227\260/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.java" diff --git "a/2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" "b/2023/06.26/\354\241\260\354\210\230\354\227\260/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" similarity index 100% rename from "2023/06.26/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" rename to "2023/06.26/\354\241\260\354\210\230\354\227\260/\354\244\204\354\226\264\353\223\244\354\247\200_\354\225\212\354\225\204.kt" From 37a2b0592ec18d823921dcc4dae36dc957b0e51e Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Mon, 26 Jun 2023 23:56:31 +0900 Subject: [PATCH 614/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20modify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main 1446 \354\247\200\353\246\204\352\270\270.kt" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "2023/6.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" => "2023/06.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" (100%) diff --git "a/2023/6.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" "b/2023/06.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" similarity index 100% rename from "2023/6.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" rename to "2023/06.26/\354\265\234\354\260\275\354\230\201/Main 1446 \354\247\200\353\246\204\352\270\270.kt" From 4f6cd746894ea9af881a1a3e38c3ed81f046db3c Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Tue, 27 Jun 2023 10:38:24 +0900 Subject: [PATCH 615/822] 0626 kihun --- 2023/06.26/Readme.md | 5 ++ ...\354\247\200\354\225\212\354\225\204.java" | 47 ++++++++++++ ...\354\247\200\353\246\204\352\270\270.java" | 73 +++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 2023/06.26/Readme.md create mode 100644 "2023/06.26/\354\206\241\352\270\260\355\233\210/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" create mode 100644 "2023/06.26/\354\206\241\352\270\260\355\233\210/\354\247\200\353\246\204\352\270\270.java" diff --git a/2023/06.26/Readme.md b/2023/06.26/Readme.md new file mode 100644 index 0000000..e5022db --- /dev/null +++ b/2023/06.26/Readme.md @@ -0,0 +1,5 @@ +# 6.26(월) 스터디 + +- 백준 + - [줄어들지 않아](https://www.acmicpc.net/problem/2688) + - [지름길](https://www.acmicpc.net/problem/1446) diff --git "a/2023/06.26/\354\206\241\352\270\260\355\233\210/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" "b/2023/06.26/\354\206\241\352\270\260\355\233\210/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" new file mode 100644 index 0000000..857297a --- /dev/null +++ "b/2023/06.26/\354\206\241\352\270\260\355\233\210/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" @@ -0,0 +1,47 @@ +package baekjoon.silver; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class 줄어들지않아 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + int maxValue = Integer.MIN_VALUE; + int[] arr = new int[N]; + + for (int i = 0; i < N; i++) { + int value = arr[i] = Integer.parseInt(br.readLine()); + maxValue = Math.max(value, maxValue); + } + + // j로 시작하는 i 자리 수 + long[][] dp = new long[maxValue + 1][10]; + + // index로 시작하는 1 자리 수는 1개 뿐 + for (int index = 0; index < 10; index++) { + dp[1][index] = 1; + } + + for (int i = 2; i < maxValue + 1; i++) { + for (int j = 0; j <= 9; j++) { + for (int k = j; k <= 9; k++) { + dp[i][j] += dp[i - 1][k]; + } + } + } + + for (int number : arr) { + long answer = 0; + for (int i = 0; i < 10; i++) { + answer += dp[number][i]; + } + System.out.println(answer); + } + + } +} diff --git "a/2023/06.26/\354\206\241\352\270\260\355\233\210/\354\247\200\353\246\204\352\270\270.java" "b/2023/06.26/\354\206\241\352\270\260\355\233\210/\354\247\200\353\246\204\352\270\270.java" new file mode 100644 index 0000000..9e4decd --- /dev/null +++ "b/2023/06.26/\354\206\241\352\270\260\355\233\210/\354\247\200\353\246\204\352\270\270.java" @@ -0,0 +1,73 @@ +package baekjoon.silver; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 지름길 { + + static class Shortcut { + int start; + int end; + int distance; + public Shortcut(int start, int end, int distance) { + this.start = start; + this.end = end; + this.distance = distance; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int D = Integer.parseInt(st.nextToken()); + + List shortcuts = new ArrayList(); + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + int distance = Integer.parseInt(st.nextToken()); + Shortcut temp = new Shortcut(start, end, distance); + shortcuts.add(temp); + } + + // start 오름차순으로 정렬, 같으면 end 오름차순 + Collections.sort(shortcuts, new Comparator() { + @Override + public int compare(Shortcut s1, Shortcut s2) { + if (s1.start == s2.start) { + return s1.end - s2.end; + } else { + return s1.start - s2.start; + } + } + }); + + int[] road = new int[10001]; + Arrays.fill(road, Integer.MAX_VALUE); + road[0] = 0; + + int index = 0; + int now = 0; + while (now < D) { + if (index < shortcuts.size()) { + Shortcut temp = shortcuts.get(index); + if (now == temp.start) { + road[temp.end] = Math.min(road[now] + temp.distance, road[temp.end]); + index += 1; + } else { + road[now + 1] = Math.min(road[now + 1], road[now] + 1); + now += 1; + } + } else { + road[now + 1] = Math.min(road[now + 1], road[now] + 1); + now += 1; + } + } + System.out.println(road[D]); + } +} From 4dc27fa81eafefbcf07c14804910bc39e0ab0d81 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 27 Jun 2023 10:51:48 +0900 Subject: [PATCH 616/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=A7=80?= =?UTF-8?q?=EB=A6=84=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\247\200\353\246\204\352\270\270.kt" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "2023/06.26/\354\241\260\354\210\230\354\227\260/\354\247\200\353\246\204\352\270\270.kt" diff --git "a/2023/06.26/\354\241\260\354\210\230\354\227\260/\354\247\200\353\246\204\352\270\270.kt" "b/2023/06.26/\354\241\260\354\210\230\354\227\260/\354\247\200\353\246\204\352\270\270.kt" new file mode 100644 index 0000000..cd574f6 --- /dev/null +++ "b/2023/06.26/\354\241\260\354\210\230\354\227\260/\354\247\200\353\246\204\352\270\270.kt" @@ -0,0 +1,52 @@ +import java.io.* +import java.util.StringTokenizer +import kotlin.math.min + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + var token = StringTokenizer(readLine()) + val n = token.nextToken().toInt() + val d = token.nextToken().toInt() + val shortcutList = ArrayList>() + + repeat(n) { + token = StringTokenizer(readLine()) + val start = token.nextToken().toInt() + val end = token.nextToken().toInt() + val cost = token.nextToken().toInt() + + // 목표 위치보다 도착 지점이 작고 지름길 비용이 원래 소요되는 거리보다 작을 경우 추가 + if (d >= end && end - start > cost) shortcutList.add(Triple(start, end, cost)) + } + + // 시작위치(오름차순) -> 도착 위치(내림차순) -> 비용 (오름차순) 정렬 + shortcutList.sortWith(compareBy> { it.first }.thenByDescending { it.second }.thenBy { it.third }) + + var moveD = 0 + var index = 0 + val distanceArr = IntArray(10001) { Integer.MAX_VALUE } + distanceArr[0] = 0 + + while (moveD < d) { + if (index < shortcutList.size) { // 지름길을 다 검색했으면 나머지 이동 거리는 기존에 소요되는 거리 비용 + val shortcut = shortcutList[index] + if (moveD == shortcut.first) { // 지름길의 시작위치를 기점으로 최소거리를 갱신 + distanceArr[shortcut.second] = min(distanceArr[moveD] + shortcut.third, distanceArr[shortcut.second]) + index++ + } else { + distanceArr[moveD + 1] = min(distanceArr[moveD + 1], distanceArr[moveD] + 1) + moveD++ + } + }else{ + distanceArr[moveD + 1] = min(distanceArr[moveD+1],distanceArr[moveD]+1) + moveD++ + } + } + + bw.write("${distanceArr[moveD]}") + + bw.flush() + bw.close() +} \ No newline at end of file From 4cd12a0479640a0bb972f8228b764536f5001e94 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:32:41 +0900 Subject: [PATCH 617/822] =?UTF-8?q?Create=20=EC=A4=84=EC=96=B4=EB=93=A4?= =?UTF-8?q?=EC=A7=80=EC=95=8A=EC=95=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\247\200\354\225\212\354\225\204.java" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "2023/06.26/\354\240\225\355\230\270\354\241\260/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" diff --git "a/2023/06.26/\354\240\225\355\230\270\354\241\260/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" "b/2023/06.26/\354\240\225\355\230\270\354\241\260/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" new file mode 100644 index 0000000..963ca93 --- /dev/null +++ "b/2023/06.26/\354\240\225\355\230\270\354\241\260/\354\244\204\354\226\264\353\223\244\354\247\200\354\225\212\354\225\204.java" @@ -0,0 +1,39 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class 줄어들지않아_2688 { + static long[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int tc = Integer.parseInt(br.readLine()); + dp = new long[65][10]; //타입 주의 + Arrays.fill(dp[1], 1); + + int maxTc = 1; + for (int i = 0; i < tc; i++) { + int n = Integer.parseInt(br.readLine()); + + if (maxTc < n) { + for (int j = maxTc + 1; j <= n; j++) { + for (int k = 0; k <= 9; k++) { + for (int l = k; l <= 9; l++) { + dp[j][k] += dp[j - 1][l]; + } + } + } + maxTc = n; + } + + long ans = 0; + for (int j = 0; j <= 9; j++) { + ans += dp[n][j]; + } + + System.out.println(ans); + } + } +} From a5ad01b4a49efc6c6676f5e3e9d41610b6a737dd Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:33:09 +0900 Subject: [PATCH 618/822] =?UTF-8?q?Create=20=EC=A7=80=EB=A6=84=EA=B8=B8.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\247\200\353\246\204\352\270\270.java" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "2023/06.26/\354\240\225\355\230\270\354\241\260/\354\247\200\353\246\204\352\270\270.java" diff --git "a/2023/06.26/\354\240\225\355\230\270\354\241\260/\354\247\200\353\246\204\352\270\270.java" "b/2023/06.26/\354\240\225\355\230\270\354\241\260/\354\247\200\353\246\204\352\270\270.java" new file mode 100644 index 0000000..4588293 --- /dev/null +++ "b/2023/06.26/\354\240\225\355\230\270\354\241\260/\354\247\200\353\246\204\352\270\270.java" @@ -0,0 +1,62 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 지름길_1446 { + static int N, D; + static int[][] roadInfo; + static int[] dist; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + + roadInfo = new int[N][3]; + dist = new int[10001]; + Arrays.fill(dist, Integer.MAX_VALUE); + dist[0] = 0; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + roadInfo[i][j] = Integer.parseInt(st.nextToken()); + } + } + + Arrays.sort(roadInfo, (o1, o2) -> o1[0] != o2[0] ? o1[0] - o2[0] : o1[1] - o2[1]); + + int now = 0; + int idx = 0; + while (now < D) { + if (idx < roadInfo.length) { + if (now == roadInfo[idx][0]) { + dist[roadInfo[idx][1]] = Math.min(dist[now] + roadInfo[idx][2], dist[roadInfo[idx][1]]); + idx++; + } else { + dist[now + 1] = Math.min(dist[now + 1], dist[now] + 1); + now++; + } + } else { + dist[now + 1] = Math.min(dist[now + 1], dist[now] + 1); + now++; + } + } + + System.out.println(dist[D]); + } + + public static class Road { + int start, end, distance; + + public Road(int start, int end, int distance) { + this.start = start; + this.end = end; + this.distance = distance; + } + } +} From 5fdc0160fd0f30d3584d59b60ff27bd3069c508d Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 28 Jun 2023 11:01:07 +0900 Subject: [PATCH 619/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=20=EB=B6=80=EB=B6=84=20=EB=AC=B8=EC=9E=90=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4_\353\254\270\354\236\220\354\227\264.kt" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "2023/06.29/\354\241\260\354\210\230\354\227\260/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.kt" diff --git "a/2023/06.29/\354\241\260\354\210\230\354\227\260/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.kt" "b/2023/06.29/\354\241\260\354\210\230\354\227\260/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.kt" new file mode 100644 index 0000000..9fab289 --- /dev/null +++ "b/2023/06.29/\354\241\260\354\210\230\354\227\260/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.kt" @@ -0,0 +1,27 @@ +import java.io.* +import kotlin.math.max + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val str = readLine() + val str2 = readLine() + + val arr = Array(str.length+1){IntArray(str2.length+1)} + var length = 0 + + for (i in 1..str.length){ + for (j in 1..str2.length){ + if (str[i-1] == str2[j-1]){ // 해당 위치에 문자가 서로 같을 때 + arr[i][j] = arr[i-1][j-1] + 1 // 해당 인덱스의 값은 그 전의 인덱스값 + 1 -> 현재 위치 -1의 위치에 문자 비교값 + 1 + length = max(length,arr[i][j]) + } + } + } + + bw.write("$length") + + bw.flush() + bw.close() +} \ No newline at end of file From 9cbfd9b7b1140beaebfc1d076649add249db751d Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 29 Jun 2023 02:36:54 +0900 Subject: [PATCH 620/822] 0629 Readme.md --- 2023/06.29/Readme.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 2023/06.29/Readme.md diff --git a/2023/06.29/Readme.md b/2023/06.29/Readme.md new file mode 100644 index 0000000..5a7dede --- /dev/null +++ b/2023/06.29/Readme.md @@ -0,0 +1,6 @@ +# 6.29(목) 스터디 + +- 백준 + - [소문난 칠공주](https://www.acmicpc.net/problem/1941) + - [공통 부분 문자열](https://www.acmicpc.net/problem/5582) + - [서강그라운드](https://www.acmicpc.net/problem/14938) From c4f7903e62506df8c58769bd6541e8bc71231bcf Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 29 Jun 2023 02:37:05 +0900 Subject: [PATCH 621/822] 0629 kihun --- ...\353\254\270\354\236\220\354\227\264.java" | 33 ++++++ ...\235\274\354\232\264\353\223\234_BFS.java" | 95 +++++++++++++++ ...274\354\232\264\353\223\234_Dijkstra.java" | 108 ++++++++++++++++++ ...\354\271\240\352\263\265\354\243\274.java" | 91 +++++++++++++++ 4 files changed, 327 insertions(+) create mode 100644 "2023/06.29/\354\206\241\352\270\260\355\233\210/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" create mode 100644 "2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_BFS.java" create mode 100644 "2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_Dijkstra.java" create mode 100644 "2023/06.29/\354\206\241\352\270\260\355\233\210/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" diff --git "a/2023/06.29/\354\206\241\352\270\260\355\233\210/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" new file mode 100644 index 0000000..9381de8 --- /dev/null +++ "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" @@ -0,0 +1,33 @@ +package baekjoon.gold; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 공통부분문자열 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public static void main(String[] args) throws IOException { + String s1 = br.readLine(); + String s2 = br.readLine(); + + int l1 = s1.length(); + int l2 = s2.length(); + int maxValue = 0; + + int[][] dp = new int[l1+1][l2+1]; + + for (int i = 1; i < l1+1; i++) { + for (int j = 1; j < l2+1; j++) { + if (s1.charAt(i-1) == s2.charAt(j-1)) { + dp[i][j] = dp[i-1][j-1] + 1; + maxValue = Math.max(dp[i][j], maxValue); + } + } + } + + System.out.println(maxValue); + + } +} diff --git "a/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_BFS.java" "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_BFS.java" new file mode 100644 index 0000000..823a2ab --- /dev/null +++ "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_BFS.java" @@ -0,0 +1,95 @@ +package baekjoon.gold; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +// https://dingdingmin-back-end-developer.tistory.com/entry/%EB%B0%B1%EC%A4%80-14938-%EC%9E%90%EB%B0%94-java-%EC%84%9C%EA%B0%95%EA%B7%B8%EB%9D%BC%EC%9A%B4%EB%93%9C + +public class 서강그라운드_BFS { + + static class Node implements Comparable { + int destination; + int distance; + + public Node(int destination, int distance) { + this.destination = destination; + this.distance = distance; + } + + @Override + public int compareTo(Node node) { + return this.distance - node.distance; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M, R; + static int[] items; + static ArrayList> nodes; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 지역 + M = Integer.parseInt(st.nextToken()); // 탐색범위 + R = Integer.parseInt(st.nextToken()); // 길의 수 + + st = new StringTokenizer(br.readLine()); + items = new int[N+1]; // 각 지역의 아이템의 수 + nodes = new ArrayList<>(); + for (int i = 1; i < N+1; i++) { + items[i] = Integer.parseInt(st.nextToken()); + nodes.add(new ArrayList<>()); + } + + // nodes와 items index 맞춰주기 위한 작업 + nodes.add(new ArrayList<>()); + + for(int i = 0; i < R; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + nodes.get(a).add(new Node(b, c)); + nodes.get(b).add(new Node(a, c)); + } + + int maxValue = Integer.MIN_VALUE; + for (int i = 1; i < N+1; i++) { + maxValue = Math.max(bfs(i), maxValue); + } + + System.out.println(maxValue); + } + + static int bfs(int index) { + // 거리가 짧은 순으로 정렬 + PriorityQueue queue = new PriorityQueue<>(); + boolean[] visited= new boolean[N+1]; + int result = 0; + + queue.add(new Node(index, 0)); + while (!queue.isEmpty()) { + Node now = queue.poll(); + + // 이미 최단 거리로 방문한 노드를 거른다 (PQ 이슈) + if (visited[now.destination]) continue; + + visited[now.destination] = true; + result += items[now.destination]; + + ArrayList nodeList = nodes.get(now.destination); + + for (Node node: nodeList) { + if (!visited[node.destination] && (now.distance + node.distance) <= M) { + queue.add(new Node(node.destination, now.distance + node.distance)); + } + } + } + + return result; + } + +} \ No newline at end of file diff --git "a/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_Dijkstra.java" "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_Dijkstra.java" new file mode 100644 index 0000000..ab4dab6 --- /dev/null +++ "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234_Dijkstra.java" @@ -0,0 +1,108 @@ +package baekjoon.gold; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +// 1. 각 노드에 도달할 수 있는 최소 거리를 다익스트라로 구하기 +// 2. 모든 노드에 대해서 조건에 부합하는 총 아이템 구하기 + +public class 서강그라운드_Dijkstra { + + static class Node implements Comparable { + int destination; + int distance; + + public Node(int destination, int distance) { + this.destination = destination; + this.distance = distance; + } + + @Override + public int compareTo(Node node) { + return this.distance - node.distance; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M, R; + static int[] items; + static int[] distances; + static ArrayList> nodes; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 지역 + M = Integer.parseInt(st.nextToken()); // 탐색범위 + R = Integer.parseInt(st.nextToken()); // 길의 수 + + st = new StringTokenizer(br.readLine()); + items = new int[N + 1]; // 각 지역의 아이템의 수 + distances = new int[N + 1]; + nodes = new ArrayList<>(); + for (int i = 1; i < N + 1; i++) { + items[i] = Integer.parseInt(st.nextToken()); + nodes.add(new ArrayList<>()); + } + + // nodes와 items index 맞춰주기 위한 작업 + nodes.add(new ArrayList<>()); + + for (int i = 0; i < R; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + nodes.get(a).add(new Node(b, c)); + nodes.get(b).add(new Node(a, c)); + } + + int maxValue = Integer.MIN_VALUE; + int tempSum = 0; + for (int i = 1; i < N + 1; i++) { + dijkstra(i); + + for (int j = 1; j < N + 1; j++) { + int num = distances[j]; + + if (num <= M) { + tempSum += items[j]; + } + } + + maxValue = Math.max(maxValue, tempSum); + tempSum = 0; + } + + System.out.println(maxValue); + } + + static void dijkstra(int index) { + Arrays.fill(distances, Integer.MAX_VALUE); + PriorityQueue queue = new PriorityQueue<>(); + queue.add(new Node(index, 0)); + + // 자기 자신으로 가는 경로는 0 + distances[index] = 0; + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + ArrayList nodeList = nodes.get(now.destination); + + for (Node node : nodeList) { + if (distances[node.destination] > distances[now.destination] + node.distance) { + distances[node.destination] = distances[now.destination] + node.distance; + queue.add(new Node(node.destination, distances[node.destination])); + } + } + } + + } + +} diff --git "a/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" new file mode 100644 index 0000000..1f5d829 --- /dev/null +++ "b/2023/06.29/\354\206\241\352\270\260\355\233\210/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" @@ -0,0 +1,91 @@ +package baekjoon.gold; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; + +public class 소문난칠공주 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static char[][] matrix = new char[5][5]; + + // 우 하 좌 상 + static int[] dY = {0, 1, 0, -1}; + static int[] dX = {1, 0, -1, 0}; + static boolean[] visited = new boolean[25]; + static int answer = 0; + + + public static void main(String[] args) throws IOException { + for (int i = 0; i < 5; i++) { + matrix[i] = br.readLine().toCharArray(); + } + + dfs(0, 0, new int[7]); + + System.out.println(answer); + + } + + static void dfs(int index, int depth, int[] selected) { + if (depth == 7) { + if (check(selected)) { + answer += 1; + } + return; + } + + for (int i = index; i < 25; i++) { + if (!visited[i]) { + selected[depth] = i; + visited[i] = true; + dfs(i + 1, depth + 1, selected); + visited[i] = false; + } + } + } + + static boolean check(int[] selected) { + int sCount = 0; + + for (int loc : selected) { + if (matrix[loc / 5][loc % 5] == 'S') { + sCount += 1; + } + } + + if (sCount < 4) { + return false; + } + + // BFS로 연결되어 있는지 확인 + ArrayList selectedList = new ArrayList<>(); + for (int loc : selected) { + selectedList.add(loc); + } + Queue queue = new LinkedList<>(); + queue.offer(selectedList.get(0)); + while (!queue.isEmpty()) { + int loc = queue.poll(); + + for (int i = 0; i < 4; i++) { + int nY = loc / 5 + dY[i]; + int nX = loc % 5 + dX[i]; + + if (nY < 0 || nY > 4 || nX < 0 || nX > 4) { + continue; + } + + Integer value = nY * 5 + nX; + if (selectedList.contains(value)) { + selectedList.remove(value); + queue.offer(value); + } + } + } + return selectedList.isEmpty(); + } + +} From a15d10c1cd5d8e457a6c8e47037514cd38158904 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 29 Jun 2023 10:04:38 +0900 Subject: [PATCH 622/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=84=9C?= =?UTF-8?q?=EA=B0=95=EA=B7=B8=EB=9D=BC=EC=9A=B4=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\353\235\274\354\232\264\353\223\234.kt" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "2023/06.29/\354\241\260\354\210\230\354\227\260/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" diff --git "a/2023/06.29/\354\241\260\354\210\230\354\227\260/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" "b/2023/06.29/\354\241\260\354\210\230\354\227\260/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" new file mode 100644 index 0000000..25d1c0d --- /dev/null +++ "b/2023/06.29/\354\241\260\354\210\230\354\227\260/\354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" @@ -0,0 +1,63 @@ +import java.io.* +import java.util.* +import kotlin.math.max + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + var token = StringTokenizer(readLine()) + val n = token.nextToken().toInt() + val m = token.nextToken().toInt() + val r = token.nextToken().toInt() + + val maxValue = 1000000 + val items = IntArray(n + 1) + val weight = Array(n + 1) { IntArray(n + 1) { maxValue } } // 이동거리에 대한 배열 + + token = StringTokenizer(readLine()) + + repeat(n) { items[it + 1] = token.nextToken().toInt() } + repeat(n) { weight[it + 1][it + 1] = 0 } // 자기 자신에게 가는 번호는 없다고 했으니 0으로 초기화 + + for (i in 1..r) { + token = StringTokenizer(readLine()) + + val start = token.nextToken().toInt() + val end = token.nextToken().toInt() + val distance = token.nextToken().toInt() + + weight[start][end] = distance + weight[end][start] = distance + } + + // 플로이드 워셜 알고리즘 + for (i in 1..n) { + for (j in 1..n) { + for (k in 1..n) { + if (weight[j][i] + weight[i][k] < weight[j][k]) { // 1 -> 2 -> 3 거리 비용이 1 -> 3 보다 적으면 1 -> 2 -> 3 비용으로 갱신 + weight[j][k] = weight[j][i] + weight[i][k] + } + } + } + } + + var answer = 0 + + for (i in 1..n) { + + var itemCount = 0 + + for (j in 1..n) { + if (weight[i][j] <= m) { + itemCount += items[j] + } + } + answer = max(answer, itemCount) + } + + bw.write("$answer") + + bw.flush() + bw.close() +} From 908781fa724d75788ed23ea35ef224ba0fef1e1b Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 30 Jun 2023 23:16:12 +0900 Subject: [PATCH 623/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=86=8C?= =?UTF-8?q?=EB=AC=B8=EB=82=9C=20=EC=B9=A0=EA=B3=B5=EC=A3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4_\354\271\240\352\263\265\354\243\274.kt" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "2023/06.29/\354\241\260\354\210\230\354\227\260/\354\206\214\353\254\270\353\202\234_\354\271\240\352\263\265\354\243\274.kt" diff --git "a/2023/06.29/\354\241\260\354\210\230\354\227\260/\354\206\214\353\254\270\353\202\234_\354\271\240\352\263\265\354\243\274.kt" "b/2023/06.29/\354\241\260\354\210\230\354\227\260/\354\206\214\353\254\270\353\202\234_\354\271\240\352\263\265\354\243\274.kt" new file mode 100644 index 0000000..2c9c0fc --- /dev/null +++ "b/2023/06.29/\354\241\260\354\210\230\354\227\260/\354\206\214\353\254\270\353\202\234_\354\271\240\352\263\265\354\243\274.kt" @@ -0,0 +1,70 @@ +import java.io.* +import java.util.* + +var answer = 0 +val visited = BooleanArray(25) +val students = Array(25) { CharArray(5) } +val dy = intArrayOf(-1,1,0,0) +val dx = intArrayOf(0,0,-1,1) + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + repeat(5) { students[it] = readLine().toCharArray() } + + dfs(0, 0, IntArray(7) { -1 }) + + bw.write( "$answer") + + bw.flush() + bw.close() +} + +fun dfs(size: Int, start:Int, members: IntArray) { + + if (size == 7) { + if (check(members)) answer++ + return + } + + for (i in start until 25){ + if(!visited[i]){ + visited[i] = true + members[size] = i + dfs(size+1,i+1,members) + visited[i] = false + } + } +} + +fun check(members: IntArray) : Boolean{ + var yCount = 0 + for (index in members){ + if (students[index / 5][index % 5] == 'Y') yCount++ + } + + if (yCount > 3) return false // S가 적어도 4개이상 있어야한다. + + val queue : Queue = LinkedList() + queue.offer(members[0]) + var memberList = members.toMutableList() + + while (queue.isNotEmpty()){ + val location = queue.poll() // 현재 위치 + for (i in 0 until 4){ + val nextX = location % 5 + dx[i] + val nextY = location / 5 + dy[i] + + if (nextX in 0 ..4 && nextY in 0..4){ + if (memberList.contains(nextY*5+nextX)){ // 이동한 위치에 memberList에 멤버가 있으면 다음 탐색 + memberList.remove(nextY*5+nextX) + queue.offer(nextY*5+nextX) + } + } + } + } + + if (memberList.isNotEmpty()) return false // 인접한 멤버가 아니면 false + return true +} \ No newline at end of file From 9bc2e4f1e1c8a5f97a83f05fb0c108a8ee1ff1e6 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sat, 1 Jul 2023 14:05:04 +0900 Subject: [PATCH 624/822] BOJ 1941 Solve --- .idea/.name | 1 + ...4 \354\271\240\352\263\265\354\243\274.kt" | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 .idea/.name create mode 100644 "2023/06.29/\354\265\234\354\260\275\354\230\201/Main 1941 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.kt" diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..f465029 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +뱀.kt \ No newline at end of file diff --git "a/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 1941 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.kt" "b/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 1941 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.kt" new file mode 100644 index 0000000..1478812 --- /dev/null +++ "b/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 1941 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.kt" @@ -0,0 +1,111 @@ +package 백트래킹_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter + +/* + 7명의 자리는 가로나 세로로 인접해 있어야 한다. + 화합과 번영을 위해서 반드시 이다솜파의 학생들로만 구성될 필요는 없다. + 그러나 생존을 위해서 이다솜파가 반드시 우위를 점해야 한다. + 7명의 학생 중 이다솜파의 학생이 적어도 4명 이상은 반드시 포함되어야 한다. + + S가 최소 4개 이상 즉, Y는 최대 3개 + 7개를 인접 + + 5*5 행렬 + S는 이다솜파의 학생 + Y는 임도연파의 학생을 나타냄 + */ + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 5 +private var ans = 0 + +private var map = Array(N) { CharArray(N) } +private var isVisited = Array(N) { BooleanArray(N) } +private var checkArray = CharArray(7) +private var dirX = arrayOf(-1, 1, 0, 0) +private var dirY = arrayOf(0, 0, -1, 1) +private var set = HashSet() + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\백트래킹_부수기\\res\\1941.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + DFS(0) + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun DFS(depth: Int) { + if (depth == 7) { + var cnt = 0 + val sb = StringBuilder() + + for (i in 0 until N) { + for (j in 0 until N) { + if (isVisited[i][j]) { + sb.append(i).append(j) + if (map[i][j] == 'S') { + cnt++ + } + } + } + } + + if (cnt >= 4 && !set.contains(sb.toString())) { + set.add(sb.toString()) + ans++ + return + } + + return + } + + for (i in 0 until N) { + for (j in 0 until N) { + + if (depth != 0) { + var cnt = 0 + for (k in 0 until 4) { + val nextX = dirX[k] + i + val nextY = dirY[k] + j + + if (!rangeCheck(nextX, nextY)) continue + if (isVisited[nextX][nextY]) cnt++ + } + if (cnt == 0) continue + } + + if (isVisited[i][j]) continue + + isVisited[i][j] = true + // 백트래킹의 핵심은 가지치기 + // 25C7 조합 + checkArray[depth] = map[i][j] + DFS(depth + 1) + isVisited[i][j] = false + } + } +} // End of DFS + +private fun rangeCheck(nextX: Int, nextY: Int): Boolean { + return nextX < N && nextX >= 0 && nextY < N && nextY >= 0 +} // End of rangeCheck + +private fun input() { + for (i in 0 until N) { + map[i] = br.readLine().toCharArray() + } +} // End of input From 36e9423b51b29da10e9627828f6a0b1a279627c5 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 2 Jul 2023 18:16:51 +0900 Subject: [PATCH 625/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20:=20BOJ=205582=20S?= =?UTF-8?q?olve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\254\270\354\236\220\354\227\264.kt" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "2023/06.29/\354\265\234\354\260\275\354\230\201/Main 5582 \352\263\265\355\206\265 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264.kt" diff --git "a/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 5582 \352\263\265\355\206\265 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264.kt" "b/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 5582 \352\263\265\355\206\265 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264.kt" new file mode 100644 index 0000000..eb5d751 --- /dev/null +++ "b/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 5582 \352\263\265\355\206\265 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264.kt" @@ -0,0 +1,53 @@ +package 문자열_부수기 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter + +/* + 두 문자열에 모두 포함된 가장 긴 공통 부분 문자열을 찾는 프로그램을 작성하라. + */ + +// input +private lateinit var br: BufferedReader + +// variables +private var str = "" +private var str2 = "" + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\문자열_부수기\\5582.txt" + br = BufferedReader(File(path).bufferedReader()) + val sb = StringBuilder() + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + input() + var ans = 0 + val len1 = str.length + val len2 = str2.length + val memo = Array(len1 + 2) { IntArray(len2 + 2) } + + for (i in 1..len1) { + for (j in 1..len2) { + if (str[i - 1] == str2[j - 1]) { + // 글자가 같으면 다음 부분의 배열 위치에 같은 길이의 값을 저장한다. + memo[i][j] = memo[i - 1][j - 1] + 1 + ans = Math.max(ans, memo[i][j]) + } + } + } + + memo.forEach { + println(it.contentToString()) + } + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + str = br.readLine() + str2 = br.readLine() +} // End of input From eb53d6154360c3fd26157107c3b1a5f5cbc28228 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 4 Jul 2023 00:01:40 +0900 Subject: [PATCH 626/822] =?UTF-8?q?Create=20=EC=86=8C=EB=AC=B8=EB=82=9C?= =?UTF-8?q?=EC=B9=A0=EA=B3=B5=EC=A3=BC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\271\240\352\263\265\354\243\274.java" | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 "2023/06.29/\354\240\225\355\230\270\354\241\260/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" diff --git "a/2023/06.29/\354\240\225\355\230\270\354\241\260/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" "b/2023/06.29/\354\240\225\355\230\270\354\241\260/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" new file mode 100644 index 0000000..3d928d0 --- /dev/null +++ "b/2023/06.29/\354\240\225\355\230\270\354\241\260/\354\206\214\353\254\270\353\202\234\354\271\240\352\263\265\354\243\274.java" @@ -0,0 +1,100 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; + +/** + * 조합으로 7개의 좌표를 먼저 뽑음 + * 7개가 서로 인접해있는지 체크하면서 S의 개수 count + * S의 개수가 4개 이상이고 서로 인접해있으면 ans++ + */ +public class 소문난칠공주_1941 { + static int[] dr = {0, 1, 0, -1}; + static int[] dc = {1, 0, -1, 0}; + static int[] pointR, pointC, com; + static char[][] arr; + static boolean[] comVis; + static boolean[][] vis; + static int ans; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + pointR = new int[25]; + pointC = new int[25]; + com = new int[7]; + comVis = new boolean[25]; + arr = new char[5][5]; + ans = 0; + + for (int i = 0; i < 25; i++) { + pointR[i] = i / 5; + pointC[i] = i % 5; + } + + for (int i = 0; i < 5; i++) { + String temp = br.readLine(); + for (int j = 0; j < 5; j++) { + arr[i][j] = temp.charAt(j); + } + } + + combination(0, 0); + System.out.println(ans); + } + + static void combination(int idx, int start) { + if (idx == 7) { + vis = new boolean[5][5]; + bfs(); + return; + } + + for (int i = start; i < 25; i++) { + if (!comVis[i]) { + comVis[i] = true; + com[idx] = i; + combination(idx + 1, i + 1); + comVis[i] = false; + } + } + } + + static void bfs() { + int cnt = 1; + int countS = 0; + Queue queue = new LinkedList<>(); + queue.add(com[0]); + + while (!queue.isEmpty()) { + + int idx = queue.poll(); + int r = pointR[idx]; + int c = pointC[idx]; + vis[r][c] = true; + + if (arr[r][c] == 'S') { + countS++; + } + + for (int i = 0; i < 4; i++) { + int rr = r + dr[i]; + int cc = c + dc[i]; + if (0 <= rr && rr < 5 && 0 <= cc && cc < 5 && !vis[rr][cc]) { + for (int j = 1; j < 7; j++) { + if(rr == pointR[com[j]] && cc == pointC[com[j]]){ + vis[rr][cc] = true; + queue.add(com[j]); + cnt++; + } + } + } + } + } + + if(cnt == 7 && countS >= 4){ + ans++; + } + } +} From 01d904d8fadb41db3fe317586a67e1e39d11cfe8 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 4 Jul 2023 00:02:52 +0900 Subject: [PATCH 627/822] =?UTF-8?q?Create=20=EA=B3=B5=ED=86=B5=EB=B6=80?= =?UTF-8?q?=EB=B6=84=EB=AC=B8=EC=9E=90=EC=97=B4.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\254\270\354\236\220\354\227\264.java" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "2023/06.29/\354\240\225\355\230\270\354\241\260/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" diff --git "a/2023/06.29/\354\240\225\355\230\270\354\241\260/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" "b/2023/06.29/\354\240\225\355\230\270\354\241\260/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" new file mode 100644 index 0000000..56772cf --- /dev/null +++ "b/2023/06.29/\354\240\225\355\230\270\354\241\260/\352\263\265\355\206\265\353\266\200\353\266\204\353\254\270\354\236\220\354\227\264.java" @@ -0,0 +1,25 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 공통부분문자열_5582 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String str1 = br.readLine(); + String str2 = br.readLine(); + int[][] arr = new int[str1.length() + 1][str2.length() + 1]; + int ans = 0; + + for (int i = 1; i <= str1.length(); i++) { + for (int j = 1; j <= str2.length(); j++) { + if (str1.charAt(i - 1) == str2.charAt(j - 1)) { + arr[i][j] = arr[i - 1][j - 1] + 1; + ans = Math.max(ans, arr[i][j]); + } + } + } + + System.out.println(ans); + } +} From f1aa47f915e1de91bab72aa6e2438cb5f8a1a194 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 4 Jul 2023 11:39:24 +0900 Subject: [PATCH 628/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=A3=BC?= =?UTF-8?q?=EA=B0=84=20=EB=AF=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\260\204_\353\257\270\355\214\205.kt" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "2023/07.06/\354\241\260\354\210\230\354\227\260/\354\243\274\352\260\204_\353\257\270\355\214\205.kt" diff --git "a/2023/07.06/\354\241\260\354\210\230\354\227\260/\354\243\274\352\260\204_\353\257\270\355\214\205.kt" "b/2023/07.06/\354\241\260\354\210\230\354\227\260/\354\243\274\352\260\204_\353\257\270\355\214\205.kt" new file mode 100644 index 0000000..41b637c --- /dev/null +++ "b/2023/07.06/\354\241\260\354\210\230\354\227\260/\354\243\274\352\260\204_\353\257\270\355\214\205.kt" @@ -0,0 +1,75 @@ +import java.io.* +import java.util.* + +lateinit var graph: ArrayList>> +lateinit var minDistance: IntArray +lateinit var visited : BooleanArray + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (n, v, e) = readLine().trim().split(" ").map { it.toInt() } + val (a, b) = readLine().trim().split(" ").map { it.toInt() } + + val houses = IntArray(n) + var token = StringTokenizer(readLine()) + + repeat(n) { houses[it] = token.nextToken().toInt() } + + graph = ArrayList() + + for (i in 0..v) { + graph.add(ArrayList()) + } + + repeat(e) { + token = StringTokenizer(readLine()) + val start = token.nextToken().toInt() + val end = token.nextToken().toInt() + val distance = token.nextToken().toInt() + graph[start].add(Pair(end,distance)) + graph[end].add(Pair(start,distance)) + } + + var answer = 0 + + for (house in houses){ + minDistance = IntArray(v+1){Integer.MAX_VALUE} + visited = BooleanArray(v+1) + dijkstarta(house) + + for (i in 1 until minDistance.size){ + if (minDistance[i] == Integer.MAX_VALUE) minDistance[i] = -1 + } + + answer += minDistance[a] + minDistance[b] + } + + println(answer) + + bw.flush() + bw.close() +} + +fun dijkstarta(start:Int){ + val q = PriorityQueue>(compareBy { it.second }) + + q.add(Pair(start,0)) + minDistance[start] = 0 + + while (q.isNotEmpty()){ + val (now,distance) = q.poll() + if (minDistance[now] < distance) continue // 최소 거리를 만족 못하면 pass + + for (next in graph[now]){ + if (!visited[next.first]){ + val cost = distance + next.second + if (cost < minDistance[next.first]){ // 다음 노드까지의 거리가 최소 거리일 경우 + minDistance[next.first] = cost + q.add(Pair(next.first,cost)) + } + } + } + } +} From 41bfd9d39eae92d8efe266532de3bc59fdd77905 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Tue, 4 Jul 2023 17:10:31 +0900 Subject: [PATCH 629/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20BOJ=2014938=20Solv?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\353\235\274\354\232\264\353\223\234.kt" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "2023/06.29/\354\265\234\354\260\275\354\230\201/Main 14938 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" diff --git "a/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 14938 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" "b/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 14938 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" new file mode 100644 index 0000000..68dde5f --- /dev/null +++ "b/2023/06.29/\354\265\234\354\260\275\354\230\201/Main 14938 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.kt" @@ -0,0 +1,108 @@ +package BOJ_서강그라운드 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 얻을 수 있는 최대 아이템의 개수 + */ + +// input +private lateinit var br: BufferedReader + +// variables +private const val INF = Int.MAX_VALUE + +private var N = 0 +private var M = 0 +private var R = 0 +private var ans = 0 + +private lateinit var items: IntArray +private lateinit var adjList: MutableList> + +private data class Node(var num: Int, var weight: Int) : Comparable { // End of Node class + override fun compareTo(other: Node): Int { + return weight - other.weight + } // End of weight +} // End of Node class + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_서강그라운드\\res\\14938.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + for (i in 1..N) { + ans = Math.max(dijkstra(startNode = i), ans) + } + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun dijkstra(startNode: Int): Int { + val pque = PriorityQueue() + val dist = IntArray(N + 1) { INF } + val isVisited = BooleanArray(N + 1) { false } + + pque.offer(Node(startNode, 0)) + dist[startNode] = 0 + + while (pque.isNotEmpty()) { + val pollNode = pque.poll() + + if (isVisited[pollNode.num]) continue + //isVisited[pollNode.num] = true + + adjList[pollNode.num].forEach { nextNode -> + if (!isVisited[pollNode.num] && dist[nextNode.num] > dist[pollNode.num] + nextNode.weight) { + pque.offer(Node(nextNode.num, nextNode.weight)) + dist[nextNode.num] = dist[pollNode.num] + nextNode.weight + } + } + } + + var res = 0 + for (i in 1..N) { + if (dist[i] <= M) { + res += items[i] + } + } + + return res +} // End of dijkstra + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() // 지역의 개수 + M = st.nextToken().toInt() // 수색범위 + R = st.nextToken().toInt() // 길의 개수 + + adjList = ArrayList() + repeat(N + 1) { + adjList.add(ArrayList()) + } + items = IntArray(N + 1) + + st = StringTokenizer(br.readLine()) + for (i in 1..N) { + items[i] = st.nextToken().toInt() + } + + for (i in 0 until R) { + st = StringTokenizer(br.readLine()) + + val start = st.nextToken().toInt() + val end = st.nextToken().toInt() + val weight = st.nextToken().toInt() + adjList[start].add(Node(end, weight)) + adjList[end].add(Node(start, weight)) + } +} // End of input From 7352599c6e9f00e2e15263053da5f242482a336b Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 5 Jul 2023 10:44:57 +0900 Subject: [PATCH 630/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=B5=9C?= =?UTF-8?q?=EC=86=9F=EA=B0=92=EA=B3=BC=20=EC=B5=9C=EB=8C=93=EA=B0=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4_\354\265\234\353\214\223\352\260\222.kt" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "2023/07.06/\354\241\260\354\210\230\354\227\260/\354\265\234\354\206\237\352\260\222\352\263\274_\354\265\234\353\214\223\352\260\222.kt" diff --git "a/2023/07.06/\354\241\260\354\210\230\354\227\260/\354\265\234\354\206\237\352\260\222\352\263\274_\354\265\234\353\214\223\352\260\222.kt" "b/2023/07.06/\354\241\260\354\210\230\354\227\260/\354\265\234\354\206\237\352\260\222\352\263\274_\354\265\234\353\214\223\352\260\222.kt" new file mode 100644 index 0000000..234ea39 --- /dev/null +++ "b/2023/07.06/\354\241\260\354\210\230\354\227\260/\354\265\234\354\206\237\352\260\222\352\263\274_\354\265\234\353\214\223\352\260\222.kt" @@ -0,0 +1,68 @@ +import java.awt.Point +import java.io.* +import java.util.* +import kotlin.math.* + +lateinit var numArr: IntArray +lateinit var tree: Array + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (n, m) = readLine().trim().split(" ").map { it.toInt() } + + numArr = IntArray(n + 1) + tree = Array(n * 4) { Point() } + + repeat(n) { numArr[it + 1] = readLine().toInt() } + + init(1, n, 1) + + val sb = StringBuilder() + + repeat(m) { + val token = StringTokenizer(readLine()) + val l = token.nextToken().toInt() + val r = token.nextToken().toInt() + + val result = find(1,n,l,r,1) + + sb.append("${result.y} ${result.x}\n") + } + + bw.write(sb.toString()) + + bw.flush() + bw.close() +} + +// 구간 합 트리 생성 +fun init(start: Int, end: Int, node: Int): Point { + + if (start == end) { + tree[node] = Point(numArr[start], numArr[end]) + return tree[node] + } + + val mid = (start + end) / 2 + val left = init(start, mid, node * 2) + val right = init(mid+1, end, node * 2 + 1) + + tree[node] = Point(max(left.x, right.x), min(left.y, right.y)) + + return tree[node] +} + +fun find(start: Int, end: Int, l : Int, r : Int, node : Int) : Point{ + // 범위 밖에 있는 경우 + if (end < l || start > r) return Point(Integer.MIN_VALUE,Integer.MAX_VALUE) + // 범위 안에 있는 경우 + if (l <= start && end <= r) return tree[node] + + // 그렇지 않으면 left, right 두 부분으로 나누어서 찾기 + val mid = (start + end) / 2 + val left = find(start, mid,l,r, node * 2) + val right = find(mid+1, end,l,r, node * 2 + 1) + return Point(max(left.x,right.x),min(left.y,right.y)) +} \ No newline at end of file From cd0319ff8332855744bc4f1135f23b19215830c0 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:31:52 +0900 Subject: [PATCH 631/822] =?UTF-8?q?Create=20=EC=A3=BC=EA=B0=84=EB=AF=B8?= =?UTF-8?q?=ED=8C=85.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\260\204\353\257\270\355\214\205.java" | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 "2023/07.06/\354\240\225\355\230\270\354\241\260/\354\243\274\352\260\204\353\257\270\355\214\205.java" diff --git "a/2023/07.06/\354\240\225\355\230\270\354\241\260/\354\243\274\352\260\204\353\257\270\355\214\205.java" "b/2023/07.06/\354\240\225\355\230\270\354\241\260/\354\243\274\352\260\204\353\257\270\355\214\205.java" new file mode 100644 index 0000000..1ce56c8 --- /dev/null +++ "b/2023/07.06/\354\240\225\355\230\270\354\241\260/\354\243\274\352\260\204\353\257\270\355\214\205.java" @@ -0,0 +1,97 @@ +import java.io.*; +import java.util.*; + +/** + * 기본적인 다익스트라 문제 + * 집의 수만큼 다익스트라를 돌려서 집에서부터 KIST와 씨알푸드까지의 최소 거리를 구한 후 ans에 더해줌 + * */ +public class 주간미팅_12834 { + static int N, V, E, ans, KIST, CR; + static int[] home, dist; + static boolean[] vis; + static ArrayList> roadInfo; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + V = Integer.parseInt(st.nextToken()); + E = Integer.parseInt(st.nextToken()); + home = new int[N]; + dist = new int[V + 1]; + vis = new boolean[V + 1]; + + st = new StringTokenizer(br.readLine()); + KIST = Integer.parseInt(st.nextToken()); + CR = Integer.parseInt(st.nextToken()); + ans = 0; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + home[i] = Integer.parseInt(st.nextToken()); + } + + roadInfo = new ArrayList<>(); + for (int i = 0; i < E; i++) { + roadInfo.add(new ArrayList<>()); + } + + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + int distance = Integer.parseInt(st.nextToken()); + roadInfo.get(start).add(new Node(end, distance)); + roadInfo.get(end).add(new Node(start, distance)); + } + + for (int i = 0; i < N; i++) { + dijkstra(home[i]); + } + + System.out.println(ans); + } + + static void dijkstra(int start) { + Arrays.fill(dist, Integer.MAX_VALUE); + Arrays.fill(vis, false); + + PriorityQueue queue = new PriorityQueue<>(((o1, o2) -> o1.distance - o2.distance)); + queue.offer(new Node(start, 0)); + dist[start] = 0; + + while (!queue.isEmpty()) { + Node curNode = queue.poll(); + int curNodeNum = curNode.nodeNum; + + if (!vis[curNodeNum]) { + vis[curNodeNum] = true; + + for (Node nextNode : roadInfo.get(curNodeNum)) { + if (!vis[nextNode.nodeNum] && dist[nextNode.nodeNum] > dist[curNodeNum] + nextNode.distance) { + dist[nextNode.nodeNum] = dist[curNodeNum] + nextNode.distance; + queue.add(new Node(nextNode.nodeNum, dist[nextNode.nodeNum])); + } + } + } + } + ans += getDistance(); + } + + static int getDistance() { + int distKIST = dist[KIST] != Integer.MAX_VALUE ? dist[KIST] : -1; + int distCR = dist[CR] != Integer.MAX_VALUE ? dist[CR] : -1; + + return distKIST + distCR; + } + + static class Node { + int nodeNum, distance; + + public Node(int nodeNum, int distance) { + this.nodeNum = nodeNum; + this.distance = distance; + } + } +} From 14ad46d44eebd68cfbfd397bec1340188221002e Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 6 Jul 2023 00:02:47 +0900 Subject: [PATCH 632/822] 0706 kihun --- 2023/07.06/Readme.md | 5 + ...\352\260\204\353\257\270\355\214\205.java" | 107 ++++++++++++++++++ ...\354\265\234\353\214\223\352\260\222.java" | 98 ++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 2023/07.06/Readme.md create mode 100644 "2023/07.06/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204\353\257\270\355\214\205.java" create mode 100644 "2023/07.06/\354\206\241\352\270\260\355\233\210/\354\265\234\354\206\237\352\260\222\352\263\274\354\265\234\353\214\223\352\260\222.java" diff --git a/2023/07.06/Readme.md b/2023/07.06/Readme.md new file mode 100644 index 0000000..23dbdb3 --- /dev/null +++ b/2023/07.06/Readme.md @@ -0,0 +1,5 @@ +# 7.6(월) 스터디 + +- 백준 + - [최솟값과 최댓값](https://www.acmicpc.net/problem/2357) + - [주간 미팅](https://www.acmicpc.net/problem/12834) diff --git "a/2023/07.06/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204\353\257\270\355\214\205.java" "b/2023/07.06/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204\353\257\270\355\214\205.java" new file mode 100644 index 0000000..27b286b --- /dev/null +++ "b/2023/07.06/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204\353\257\270\355\214\205.java" @@ -0,0 +1,107 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class 주간미팅 { + + static class Node implements Comparable { + int end, distance; + + public Node(int end, int distance) { + this.end = end; + this.distance = distance; + } + + @Override + public int compareTo(Node o) { + return this.distance - o.distance; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; // 팀원 수 + static int V; // 장소 수 + static int E; // 도로 수 + static int A; // KIST 위치 + static int B; // 씨알푸드 위치 + static ArrayList> nodes; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + V = Integer.parseInt(st.nextToken()); + E = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + A = Integer.parseInt(st.nextToken()); + B = Integer.parseInt(st.nextToken()); + + int[] houses = new int[N + 1]; + st = new StringTokenizer(br.readLine()); + for (int i = 1; i < N + 1; i++) { + houses[i] = Integer.parseInt(st.nextToken()); + } + + + // nodes ArrayList 초기화 + nodes = new ArrayList<>(); + for (int i = 0; i < V + 1; i++) { + nodes.add(new ArrayList<>()); + } + + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int l = Integer.parseInt(st.nextToken()); + + nodes.get(a).add(new Node(b, l)); + nodes.get(b).add(new Node(a, l)); + } + + int[] kistDistances = dijkstra(A); + int[] foodDistances = dijkstra(B); + + int sum = 0; + for (int i = 1; i < N + 1; i++) { + int houseLocation = houses[i]; + int kistDistance = kistDistances[houseLocation] == Integer.MAX_VALUE ? -1 : kistDistances[houseLocation]; + int foodDistance = foodDistances[houseLocation] == Integer.MAX_VALUE ? -1 : foodDistances[houseLocation]; + + sum += kistDistance + foodDistance; + } + System.out.println(sum); + } + + static int[] dijkstra(int index) { + int[] distances = new int[V + 1]; + Arrays.fill(distances, Integer.MAX_VALUE); + + PriorityQueue queue = new PriorityQueue<>(); + queue.add(new Node(index, 0)); + + distances[index] = 0; + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + ArrayList nodeList = nodes.get(now.end); + + for (Node node : nodeList) { + if (distances[node.end] > distances[now.end] + node.distance) { + distances[node.end] = distances[now.end] + node.distance; + queue.add(new Node(node.end, distances[node.end])); + } + } + } + + return distances; + } + +} diff --git "a/2023/07.06/\354\206\241\352\270\260\355\233\210/\354\265\234\354\206\237\352\260\222\352\263\274\354\265\234\353\214\223\352\260\222.java" "b/2023/07.06/\354\206\241\352\270\260\355\233\210/\354\265\234\354\206\237\352\260\222\352\263\274\354\265\234\353\214\223\352\260\222.java" new file mode 100644 index 0000000..4ac63c4 --- /dev/null +++ "b/2023/07.06/\354\206\241\352\270\260\355\233\210/\354\265\234\354\206\237\352\260\222\352\263\274\354\265\234\353\214\223\352\260\222.java" @@ -0,0 +1,98 @@ +package baekjoon.gold.one; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +// 세그먼트 트리 개념 https://yoongrammer.tistory.com/103 +public class 최솟값과최댓값 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M; + static int[] numbers, minTree, maxTree; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + numbers = new int[N + 1]; + for (int i = 1; i < N + 1; i++) { + numbers[i] = Integer.parseInt(br.readLine()); + } + + minTree = new int[N * 4]; + maxTree = new int[N * 4]; + + initMin(1, N, 1); + initMax(1, N, 1); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + System.out.println(min(1, N, 1, a, b) + " " + max(1, N, 1, a, b)); + } + } + + static int initMin(int start, int end, int node) { + if (start == end) { + return minTree[node] = numbers[start]; + } + int mid = (start + end) / 2; + + return minTree[node] = Math.min( + initMin(start, mid, node * 2), + initMin(mid + 1, end, node * 2 + 1) + ); + } + + static int initMax(int start, int end, int node) { + if (start == end) { + return maxTree[node] = numbers[start]; + } + int mid = (start + end) / 2; + + return maxTree[node] = Math.max( + initMax(start, mid, node * 2), + initMax(mid + 1, end, node * 2 + 1) + ); + } + + public static int min(int start, int end, int node, int left, int right) { + if (left > end || right < start) { + return Integer.MAX_VALUE; + } + if (start == end) { + return numbers[start]; + } + if (left <= start && end <= right) { + return minTree[node]; + } + int mid = (start + end) / 2; + return Math.min( + min(start, mid, node * 2, left, right), + min(mid + 1, end, node * 2 + 1, left, right) + ); + } + + public static int max(int start, int end, int node, int left, int right) { + if (left > end || right < start) { + return 0; + } + if (start == end) { + return numbers[start]; + } + if (left <= start && end <= right) { + return maxTree[node]; + } + int mid = (start + end) / 2; + return Math.max( + max(start, mid, node * 2, left, right), + max(mid + 1, end, node * 2 + 1, left, right) + ); + } + +} From 39602651087c39de411192fa726bfb10458870ca Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Thu, 6 Jul 2023 14:22:58 +0900 Subject: [PATCH 633/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20BOJ=202357=20Solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\265\234\353\214\223\352\260\222.kt" | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 "2023/07.06/\354\265\234\354\260\275\354\230\201/Main 2357 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.kt" diff --git "a/2023/07.06/\354\265\234\354\260\275\354\230\201/Main 2357 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.kt" "b/2023/07.06/\354\265\234\354\260\275\354\230\201/Main 2357 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.kt" new file mode 100644 index 0000000..1b1671b --- /dev/null +++ "b/2023/07.06/\354\265\234\354\260\275\354\230\201/Main 2357 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.kt" @@ -0,0 +1,109 @@ +package BOJ_2357 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 +private var M = 0 + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_2357\\res\\2357.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + val arr = IntArray(N + 1) + for (i in 1..N) { + arr[i] = br.readLine().toInt() + } + + val minTree = IntArray(N * 4) + val maxTree = IntArray(N * 4) + + makeTree(arr, maxTree, 1, 1, N, "max") // 최대 트리 만들기 + makeTree(arr, minTree, 1, 1, N, "min") // 최소 트리 만들기 + + while (M-- > 0) { + val st = StringTokenizer(br.readLine()) + val a = st.nextToken().toInt() + val b = st.nextToken().toInt() + + sb.append(findVal(minTree, 1, 1, N, a, b, "min")) + .append(' ') + .append(findVal(maxTree, 1, 1, N, a, b, "max")) + .append('\n') + } + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun makeTree(arr: IntArray, tree: IntArray, node: Int, start: Int, end: Int, mode: String): Int { + if (start == end) { + tree[node] = arr[start] + return tree[node] + } + + val mid = (start + end) / 2 + val left = makeTree(arr, tree, node * 2, start, mid, mode) + val right = makeTree(arr, tree, node * 2 + 1, mid + 1, end, mode) + + return when (mode) { + "max" -> { + tree[node] = Math.max(left, right) + tree[node] + } + + else -> { + tree[node] = Math.min(left, right) + tree[node] + } + } +} // End of makeTree + +private fun findVal(tree: IntArray, node: Int, start: Int, end: Int, left: Int, right: Int, mode: String): Int { + // 범위 밖 + if (end < left || start > right) { + return when (mode) { + "min" -> { + Int.MAX_VALUE + } + + else -> { + 0 + } + } + } + + // 범위 안 + if (left <= start && end <= right) return tree[node] + + val mid = (start + end) / 2 + val leftVal = findVal(tree, node * 2, start, mid, left, right, mode) + val rightVal = findVal(tree, node * 2 + 1, mid + 1, end, left, right, mode) + + return when (mode) { + "min" -> { + Math.min(leftVal, rightVal) + } + + else -> { + Math.max(leftVal, rightVal) + } + } +} // End of findVal + +private fun input() { + val st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() // 정수의 개수 + M = st.nextToken().toInt() +} // End of input From c4046a57f3cc4b82e4e6afe8c2dd150d4f655d34 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 6 Jul 2023 19:26:30 +0900 Subject: [PATCH 634/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=8F=84?= =?UTF-8?q?=EC=98=81=EC=9D=B4=EA=B0=80=20=EB=A7=8C=EB=93=A0=20=EB=A7=9B?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=9D=8C=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\212\224_\354\235\214\354\213\235.kt" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/07.10/\354\241\260\354\210\230\354\227\260/\353\217\204\354\230\201\354\235\264\352\260\200_\353\247\214\353\223\240_\353\247\233\354\236\210\353\212\224_\354\235\214\354\213\235.kt" diff --git "a/2023/07.10/\354\241\260\354\210\230\354\227\260/\353\217\204\354\230\201\354\235\264\352\260\200_\353\247\214\353\223\240_\353\247\233\354\236\210\353\212\224_\354\235\214\354\213\235.kt" "b/2023/07.10/\354\241\260\354\210\230\354\227\260/\353\217\204\354\230\201\354\235\264\352\260\200_\353\247\214\353\223\240_\353\247\233\354\236\210\353\212\224_\354\235\214\354\213\235.kt" new file mode 100644 index 0000000..f63e0f1 --- /dev/null +++ "b/2023/07.10/\354\241\260\354\210\230\354\227\260/\353\217\204\354\230\201\354\235\264\352\260\200_\353\247\214\353\223\240_\353\247\233\354\236\210\353\212\224_\354\235\214\354\213\235.kt" @@ -0,0 +1,44 @@ +import java.io.* +import java.util.StringTokenizer +import kotlin.math.* + +lateinit var taste: Array +lateinit var checked: BooleanArray +var answer = Integer.MAX_VALUE + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + taste = Array(n) { IntArray(2) } + checked = BooleanArray(n) + + repeat(n) { + val token = StringTokenizer(readLine()) + taste[it][0] = token.nextToken().toInt() + taste[it][1] = token.nextToken().toInt() + } + + repeat(n) { + minDiff(0, it + 1, 0, 1, 0) + } + + bw.write("$answer") + + bw.flush() + bw.close() +} + +fun minDiff(size: Int, maxSize: Int, start: Int, sourness: Int, bitterness: Int) { + if (answer == 0) return + + if (size == maxSize) { + answer = min(answer, abs(sourness - bitterness)) + return + } + + for (i in start until taste.size) { + minDiff(size + 1, maxSize, i + 1, sourness * taste[i][0], bitterness + taste[i][1]) + } +} \ No newline at end of file From 8a763ca181348391ca67f0e4a06c66a074e57096 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 6 Jul 2023 20:48:36 +0900 Subject: [PATCH 635/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=EC=9D=98=20=EC=A7=80=EB=A6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230_\354\247\200\353\246\204.kt" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "2023/07.10/\354\241\260\354\210\230\354\227\260/\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.kt" diff --git "a/2023/07.10/\354\241\260\354\210\230\354\227\260/\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.kt" "b/2023/07.10/\354\241\260\354\210\230\354\227\260/\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.kt" new file mode 100644 index 0000000..55af3c7 --- /dev/null +++ "b/2023/07.10/\354\241\260\354\210\230\354\227\260/\355\212\270\353\246\254\354\235\230_\354\247\200\353\246\204.kt" @@ -0,0 +1,70 @@ +import java.io.* +import java.util.StringTokenizer +import kotlin.math.* + +lateinit var tree: ArrayList>> +lateinit var checked: BooleanArray // 리프 노드 체크 배열 +lateinit var visited: BooleanArray // 중복 방문 체크 배열 +lateinit var finished: BooleanArray // 리프 노드 중복 방문 체크 배열 +var answer = 0 + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + + tree = ArrayList() + + for (i in 0..n) { + tree.add(ArrayList()) + } + + checked = BooleanArray(n + 1){true} + finished = BooleanArray(n + 1) + + repeat(n - 1) { + val token = StringTokenizer(readLine()) + val parent = token.nextToken().toInt() + val child = token.nextToken().toInt() + val weight = token.nextToken().toInt() + + tree[parent].add(Pair(child, weight)) + tree[child].add(Pair(parent, weight)) + + checked[parent] = false + } + + val leaves = ArrayList() + + for (i in checked.indices) { + if (checked[i]) leaves.add(i) + } + + for (i in leaves.indices) { + visited = BooleanArray(n + 1) + checked[leaves[i]] = false + maxDiameter(leaves[i],0) + finished[leaves[i]] = true + } + + bw.write("$answer") + + bw.flush() + bw.close() +} + +// dfs 접근 +fun maxDiameter(start: Int, weight:Int) { + + visited[start] = true + + for (next in tree[start]) { + if (!visited[next.first] && !finished[next.first]) { + maxDiameter(next.first,weight + next.second) + } + } + + answer = max(answer,weight) + return +} \ No newline at end of file From da3b8bba1bdbe27b0eddccf18b4e4d3b03c20e52 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Fri, 7 Jul 2023 16:29:11 +0900 Subject: [PATCH 636/822] BOJ 12834 Solve & BOJ 14618 Solve --- ...4\352\260\204 \353\257\270\355\214\205.kt" | 121 ++++++++++++++++ ...35\352\271\241\354\264\235\352\271\241.kt" | 133 ++++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 "2023/07.06/\354\265\234\354\260\275\354\230\201/Main 12834 \354\243\274\352\260\204 \353\257\270\355\214\205.kt" create mode 100644 "2023/07.10/\354\265\234\354\260\275\354\230\201/Main 14618 \354\264\235\352\271\241\354\264\235\352\271\241.kt" diff --git "a/2023/07.06/\354\265\234\354\260\275\354\230\201/Main 12834 \354\243\274\352\260\204 \353\257\270\355\214\205.kt" "b/2023/07.06/\354\265\234\354\260\275\354\230\201/Main 12834 \354\243\274\352\260\204 \353\257\270\355\214\205.kt" new file mode 100644 index 0000000..26f4ae2 --- /dev/null +++ "b/2023/07.06/\354\265\234\354\260\275\354\230\201/Main 12834 \354\243\274\352\260\204 \353\257\270\355\214\205.kt" @@ -0,0 +1,121 @@ +package BOJ_12834_주간_미팅 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 장소를 노드로 생각. + 연결된 도로를 간선으로 생각. -> 그래프로 구성 + + + 예외 : KIST나 씨알푸드로 갈 수 없는 경우에는 -1로 처리한다. + */ + +// input +private lateinit var br: BufferedReader + +// vairables +private const val INF = Int.MAX_VALUE +private var N = 0 +private var V = 0 +private var E = 0 +private var A = 0 +private var B = 0 + +private lateinit var adjList: MutableList> +private lateinit var homes: IntArray + +private data class Node(var num: Int, var weight: Int) + + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_12834_주간_미팅\\res\\12834.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + var ans = 0 + ans += dijkstra(A) + ans += dijkstra(B) + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun dijkstra(startNodeNum: Int): Int { + val comp = Comparator { o1, o2 -> + o1.weight - o2.weight + } + val pque = PriorityQueue(comp) + val dist = IntArray(V + 1) { INF } + + dist[startNodeNum] = 0 + pque.offer(Node(startNodeNum, 0)) + + for (i in generateSequence {}) { + if (pque.isEmpty()) break + + val poll = pque.poll() + + adjList[poll.num].forEach { nextNode -> + if (dist[nextNode.num] > dist[poll.num] + nextNode.weight) { + dist[nextNode.num] = dist[poll.num] + nextNode.weight + pque.offer(Node(nextNode.num, dist[nextNode.num])) + } + } + } + + var sum = 0 + homes.forEach { + val temp = dist[it] + when (temp) { + INF -> { + sum-- + } + + else -> { + sum += temp + } + } + } + + return sum +} // End of dijkstra + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() // 팀원의 수 + V = st.nextToken().toInt() // 장소의 수 (노드) + E = st.nextToken().toInt() // 도로의 수 (간선) + + adjList = ArrayList() + repeat(V + 1) { + adjList.add(ArrayList()) + } + + st = StringTokenizer(br.readLine()) + A = st.nextToken().toInt() + B = st.nextToken().toInt() + + homes = IntArray(N) + st = StringTokenizer(br.readLine()) + for (i in 0 until N) { + homes[i] = st.nextToken().toInt() + } + + repeat(E) { + st = StringTokenizer(br.readLine()) + val a = st.nextToken().toInt() + val b = st.nextToken().toInt() + val l = st.nextToken().toInt() + + adjList[a].add(Node(b, l)) + adjList[b].add(Node(a, l)) + } +} // End of input diff --git "a/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 14618 \354\264\235\352\271\241\354\264\235\352\271\241.kt" "b/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 14618 \354\264\235\352\271\241\354\264\235\352\271\241.kt" new file mode 100644 index 0000000..8833f5f --- /dev/null +++ "b/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 14618 \354\264\235\352\271\241\354\264\235\352\271\241.kt" @@ -0,0 +1,133 @@ +package BOJ_14618_총깡총깡 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 어디에 살던 상관이 없는 경우 -1을 출력한다. + + 집의 종류를 말한 뒤에 거리를 출력한다. + A를 출력한 뒤 다음줄에 거리를 출력 B형 집에서만 진서의 집에 갈 수 있는 경우 B를 출력한 뒤 다음 줄에 거리를 출력, 둘다 진서의 집에 갈 수 없는 경우 -1을 출력 + */ + +// input +private lateinit var br: BufferedReader + +// variables +private const val INF = Int.MAX_VALUE +private var N = 0 +private var M = 0 +private var J = 0 +private var K = 0 + +private lateinit var houseTypeA: IntArray +private lateinit var houseTypeB: IntArray +private lateinit var adjList: MutableList> +private lateinit var dist: IntArray + +private data class Node(var num: Int, var weight: Int) + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_14618_총깡총깡\\res\\14618.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + dijkstra(J) + + var aMin = INF + var bMin = INF + houseTypeA.forEach { houseNum -> + val d = dist[houseNum] + aMin = Math.min(aMin, d) + } + + houseTypeB.forEach { houseNum -> + val d = dist[houseNum] + bMin = Math.min(bMin, d) + } + + + // A형 집과 B형 집의 거리가 같으면 A형의 집에 산다 + if (aMin == INF && bMin == INF) { + sb.append(-1) + } else { + if (aMin <= bMin) { + sb.append('A').append('\n').append(aMin) + } else { + sb.append('B').append('\n').append(bMin) + } + } + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun dijkstra(startNodeNum: Int) { + val comp = Comparator { o1, o2 -> o1.weight - o2.weight } + val pque = PriorityQueue(comp) + val isVisited = BooleanArray(N + 1) + + pque.offer(Node(startNodeNum, 0)) + dist[startNodeNum] = 0 + + for (i in generateSequence { }) { + if (pque.isEmpty()) break + + val pollNode = pque.poll() + if (isVisited[pollNode.num]) continue + isVisited[pollNode.num] = true + + adjList[pollNode.num].forEach { nextNode -> + val nextNum = nextNode.num + val nextWeight = nextNode.weight + + if (dist[nextNum] > nextWeight + dist[pollNode.num]) { + dist[nextNum] = nextWeight + dist[pollNode.num] + pque.offer(Node(nextNum, dist[nextNum])) + } + } + } +} // End of dijkstra + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() // 집의 수 + M = st.nextToken().toInt() // 집과 집 사이의 도로 수 + J = br.readLine().toInt() // 진서의 집 + + K = br.readLine().toInt() // 종류별 동물의 수 + houseTypeA = IntArray(K) // A 형의 집 + houseTypeB = IntArray(K) // B 형의 집 + + st = StringTokenizer(br.readLine()) + for (i in 0 until K) { + houseTypeA[i] = st.nextToken().toInt() + } + + st = StringTokenizer(br.readLine()) + for (i in 0 until K) { + houseTypeB[i] = st.nextToken().toInt() + } + + adjList = ArrayList() + repeat(N + 1) { + adjList.add(ArrayList()) + } + dist = IntArray(N + 1) { INF } + + for (i in 0 until M) { + st = StringTokenizer(br.readLine()) + val x = st.nextToken().toInt() + val y = st.nextToken().toInt() + val z = st.nextToken().toInt() + + adjList[x].add(Node(y, z)) + adjList[y].add(Node(x, z)) + } +} // End of input From ede1a9877aad348c8c8525eb220b86e16da14adc Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:54:35 +0900 Subject: [PATCH 637/822] =?UTF-8?q?Create=20=ED=8A=B8=EB=A6=AC=EC=9D=98?= =?UTF-8?q?=EC=A7=80=EB=A6=84=5F1967.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...235\230\354\247\200\353\246\204_1967.java" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "2023/07.10/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204_1967.java" diff --git "a/2023/07.10/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204_1967.java" "b/2023/07.10/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204_1967.java" new file mode 100644 index 0000000..9af6559 --- /dev/null +++ "b/2023/07.10/\354\240\225\355\230\270\354\241\260/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204_1967.java" @@ -0,0 +1,90 @@ +import java.io.*; +import java.util.*; + +/** + * 두 노드 사이의 경로는 하나이기 때문에 트리의 특성상 각 노드에서 가장 먼 거리에 위치한 노드는 + * 두 노드 사이의 거리가 가장 먼 노드 중 한 개를 반드시 포함하고 있음. + * 따라서 각 노드로부터 모든 노드까지의 거리를 구할 필요가 없고(메모리 초과 발생) + * 임의의 한 노드로부터 가장 먼 노드를 찾은 후, 그 노드로 부터 가장 먼 노드까지의 거리를 구하면 정답 + */ + +public class 트리의지름_1967 { + static int n, ans; + static ArrayList> list; + static int[] dist; + static boolean[] vis; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + n = Integer.parseInt(br.readLine()); + dist = new int[n + 1]; + vis = new boolean[n + 1]; + list = new ArrayList<>(); + for (int i = 0; i <= n; i++) { + list.add(new ArrayList<>()); + } + + for (int i = 0; i < n - 1; i++) { + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + int dist = Integer.parseInt(st.nextToken()); + + list.get(start).add(new Node(end, dist)); + list.get(end).add(new Node(start, dist)); + } + + int farthestNodeNum = dijkstra(1, true); + ans = dijkstra(farthestNodeNum, false); + + System.out.println(ans); + } + + static int dijkstra(int start, boolean findNodeNum) { + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> o1.distance - o2.distance); + Arrays.fill(dist, Integer.MAX_VALUE); + Arrays.fill(vis, false); + dist[start] = 0; + pq.add(new Node(start, 0)); + + while (!pq.isEmpty()) { + Node curNode = pq.poll(); + int curNodeNum = curNode.nodeNum; + + if (!vis[curNodeNum]) { + vis[curNodeNum] = true; + for (Node nextNode : list.get(curNodeNum)) { + if (!vis[nextNode.nodeNum] && dist[nextNode.nodeNum] > dist[curNodeNum] + nextNode.distance) { + dist[nextNode.nodeNum] = dist[curNodeNum] + nextNode.distance; + pq.add(new Node(nextNode.nodeNum, dist[nextNode.nodeNum])); + } + } + } + } + + int maxLen = 0; + int nodeNum = 0; + for (int i = 1; i < dist.length; i++) { + if (dist[i] != Integer.MAX_VALUE && maxLen < dist[i]) { + maxLen = dist[i]; + nodeNum = i; + } + } + if (findNodeNum) { + return nodeNum; + } else { + return maxLen; + } + } + + static class Node { + int nodeNum, distance; + + public Node(int nodeNum, int distance) { + this.nodeNum = nodeNum; + this.distance = distance; + } + } +} From 65e240c4250427bda2b0fceeee61f8c27dff72cf Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:55:34 +0900 Subject: [PATCH 638/822] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=EC=97=90=20=EB=8F=84=EC=9B=80=EC=9D=84=20=EC=A3=BC=EC=8B=A0=20?= =?UTF-8?q?=EC=86=A1=EA=B8=B0=ED=9B=88=EB=8B=98=EA=BB=98=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=ED=95=9C=20=EB=B2=88=20=EB=AC=B4=ED=95=9C=ED=95=9C?= =?UTF-8?q?=20=EA=B0=90=EC=82=AC=EB=A5=BC=20=ED=91=9C=ED=95=A9=EB=8B=88?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\271\241\354\264\235\352\271\241.java" | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 "2023/07.10/\354\240\225\355\230\270\354\241\260/\354\264\235\352\271\241\354\264\235\352\271\241.java" diff --git "a/2023/07.10/\354\240\225\355\230\270\354\241\260/\354\264\235\352\271\241\354\264\235\352\271\241.java" "b/2023/07.10/\354\240\225\355\230\270\354\241\260/\354\264\235\352\271\241\354\264\235\352\271\241.java" new file mode 100644 index 0000000..d9f59d2 --- /dev/null +++ "b/2023/07.10/\354\240\225\355\230\270\354\241\260/\354\264\235\352\271\241\354\264\235\352\271\241.java" @@ -0,0 +1,115 @@ +import java.io.*; +import java.util.*; + +/*문제 풀이에 도움을 주신 송기훈님께 다시 한 번 무한한 감사를 표합니다.*/ + +public class 총깡총깡_14618 { + static int N, M, J, K; + static long ansDist; + static String ansHome; + static int[] dist, home; + static boolean[] vis; + static ArrayList> list; + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + J = Integer.parseInt(br.readLine()); + K = Integer.parseInt(br.readLine()); + + dist = new int[N + 1]; + vis = new boolean[N + 1]; + ansDist = -1; + ansHome = ""; + StringTokenizer stA = new StringTokenizer(br.readLine()); + StringTokenizer stB = new StringTokenizer(br.readLine()); + home = new int[N + 1]; + + for (int i = 0; i < K; i++) { + home[Integer.parseInt(stA.nextToken())] = 1; + home[Integer.parseInt(stB.nextToken())] = 2; + } + + list = new ArrayList<>(); + for (int i = 0; i <= N; i++) { + list.add(new ArrayList<>()); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int X = Integer.parseInt(st.nextToken()); + int Y = Integer.parseInt(st.nextToken()); + int Z = Integer.parseInt(st.nextToken()); + + list.get(X).add(new Node(Y, Z)); + list.get(Y).add(new Node(X, Z)); + } + + dijkstra(J); + } + + static void dijkstra(int start) { + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> o1.distance - o2.distance); + Arrays.fill(dist, Integer.MAX_VALUE); + Arrays.fill(vis, false); + dist[start] = 0; + pq.add(new Node(start, 0)); + + while (!pq.isEmpty()) { + Node curNode = pq.poll(); + int curNodeNum = curNode.nodeNum; + + if (!vis[curNodeNum]) { + vis[curNodeNum] = true; + for (Node nextNode : list.get(curNodeNum)) { + if (!vis[nextNode.nodeNum] && dist[nextNode.nodeNum] > dist[curNodeNum] + nextNode.distance) { + dist[nextNode.nodeNum] = dist[curNodeNum] + nextNode.distance; + pq.add(new Node(nextNode.nodeNum, dist[nextNode.nodeNum])); + } + } + } + } + findClosestHome(); + } + + static void findClosestHome() { + int min = Integer.MAX_VALUE; + for (int homeNum = 1; homeNum <= N; homeNum++) { + if (homeNum == J) continue; + if (home[homeNum] == 0) continue; + + if(min != Integer.MAX_VALUE && min == dist[homeNum] && home[homeNum] == 1){ + ansHome = "A"; + ansDist = dist[homeNum]; + } else if(min > dist[homeNum]){ + min = dist[homeNum]; + ansDist = dist[homeNum]; + if(home[homeNum] == 1){ + //A형 집 + ansHome = "A"; + } else if(home[homeNum] == 2) { + //B형 집 + ansHome = "B"; + } + } + } + if (ansHome.equals("")) { + System.out.println(-1); + } else { + System.out.println(ansHome + "\n" + ansDist); + } + } + + static class Node { + int nodeNum, distance; + + public Node(int nodeNum, int distance) { + this.nodeNum = nodeNum; + this.distance = distance; + } + } +} From e5bb2e1e87d6d41436109ad58a7ab18b9edf6ade Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 9 Jul 2023 13:43:19 +0900 Subject: [PATCH 639/822] BOJ 1967 Solve --- ...4\354\235\230 \354\247\200\353\246\204.kt" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "2023/07.10/\354\265\234\354\260\275\354\230\201/Main 1967 \355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.kt" diff --git "a/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 1967 \355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.kt" "b/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 1967 \355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.kt" new file mode 100644 index 0000000..ae3fb85 --- /dev/null +++ "b/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 1967 \355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.kt" @@ -0,0 +1,89 @@ +package BOJ_1967_트리의_지름 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +/* + 트리는 양방향 그래프가 된다. + 그래프의 구조가 트리의 특성 -> 트리의 특성을 활용할 수 있다. + */ + +// input +private lateinit var br: BufferedReader + +// variables +private var N = 0 +private lateinit var adjList: MutableList> +private lateinit var isVisited: BooleanArray +private lateinit var dist: IntArray + +data class Node(var num: Int = 0, var weight: Int = 0) + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_1967_트리의_지름\\res\\1967.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + // 루트에서 시작해서 가장 먼 노드를 찾기 + var ans = 0 + ans = dijkstra(1) + ans = dijkstra(dist.indexOf(ans)) + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun dijkstra(startNodeNum: Int): Int { + val comp = Comparator { o1, o2 -> o1.weight - o2.weight } + val que = PriorityQueue(comp) + isVisited = BooleanArray(N + 1) + dist = IntArray(N + 1) { -1 } + + dist[startNodeNum] = 0 + que.offer(Node(startNodeNum, 0)) + + for (i in generateSequence { 0 }) { + if (que.isEmpty()) break + val pollNode = que.poll() + + if (isVisited[pollNode.num]) continue + isVisited[pollNode.num] = true + + adjList[pollNode.num].forEach { nextNode -> + + // 다익스트라의 개념을 적용하되 가장짧은 거리로 최신화 하는 것이 아닌, 가장 먼 거리로 최신화를 함. + if (!isVisited[nextNode.num] && dist[nextNode.num] < nextNode.weight + dist[pollNode.num]) { + dist[nextNode.num] = nextNode.weight + dist[pollNode.num] + que.offer(Node(nextNode.num, dist[nextNode.num])) + } + } + } + + return dist.max() +} // End of dijkstra + +fun input() { + N = br.readLine().toInt() + + adjList = ArrayList() + repeat(N + 1) { + adjList.add(ArrayList()) + } + + repeat(N - 1) { + val st = StringTokenizer(br.readLine()) + val parentNode = st.nextToken().toInt() + val childNode = st.nextToken().toInt() + val weight = st.nextToken().toInt() + + adjList[parentNode].add(Node(childNode, weight)) + adjList[childNode].add(Node(parentNode, weight)) + } +} // End of input From 84a7b285c482439dcc908f5f2d32473caeb13002 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 9 Jul 2023 16:10:22 +0900 Subject: [PATCH 640/822] BOJ 2961 Solve --- ...0\353\212\224 \354\235\214\354\213\235.kt" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "2023/07.10/\354\265\234\354\260\275\354\230\201/Main 2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235.kt" diff --git "a/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235.kt" "b/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235.kt" new file mode 100644 index 0000000..2ddcda4 --- /dev/null +++ "b/2023/07.10/\354\265\234\354\260\275\354\230\201/Main 2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235.kt" @@ -0,0 +1,75 @@ +package BOJ_2961_도영이가_만든_맛있는_음식 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// variables +private lateinit var br: BufferedReader + +// input +private var N = 0 +private var ans = Int.MAX_VALUE + +private lateinit var arr: Array +private lateinit var isVisited: BooleanArray +private var comb: MutableList = ArrayList() + +private data class Taste(var sour: Int, var bitter: Int) + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_2961_도영이가_만든_맛있는_음식\\res\\2961.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + DFS(0, 0) + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun DFS(depth: Int, idx: Int) { + if (depth != 0) { + var sSum = 1 + var bSum = 0 + comb.forEach { + sSum *= it.sour + bSum += it.bitter + } + + ans = Math.min(ans, Math.abs(sSum - bSum)) + + if (depth == N) { + return + } + } + + for (i in idx until N) { + if (isVisited[i]) continue + + isVisited[i] = true + comb.add(arr[i]) + DFS(depth + 1, i) + comb.removeAt(depth) + isVisited[i] = false + } +} // End of DFS + +private fun input() { + N = br.readLine().toInt() + + arr = Array(N) { Taste(0, 0) } + isVisited = BooleanArray(N) + + for (i in 0 until N) { + val st = StringTokenizer(br.readLine()) + arr[i].sour = st.nextToken().toInt() + arr[i].bitter = st.nextToken().toInt() + } +} // End of input From 09334c93601d6bd4054e904a0aa2bfd4f5569d58 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 10 Jul 2023 10:23:01 +0900 Subject: [PATCH 641/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=B4=9D?= =?UTF-8?q?=EA=B9=A1=20=EC=B4=9D=EA=B9=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\352\271\241_\354\264\235\352\271\241.kt" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "2023/07.10/\354\241\260\354\210\230\354\227\260/\354\264\235\352\271\241_\354\264\235\352\271\241.kt" diff --git "a/2023/07.10/\354\241\260\354\210\230\354\227\260/\354\264\235\352\271\241_\354\264\235\352\271\241.kt" "b/2023/07.10/\354\241\260\354\210\230\354\227\260/\354\264\235\352\271\241_\354\264\235\352\271\241.kt" new file mode 100644 index 0000000..c2ca7dd --- /dev/null +++ "b/2023/07.10/\354\241\260\354\210\230\354\227\260/\354\264\235\352\271\241_\354\264\235\352\271\241.kt" @@ -0,0 +1,88 @@ +import java.io.* +import java.util.* +import kotlin.math.* + +lateinit var graph: ArrayList>> +lateinit var visited: BooleanArray +lateinit var dist: IntArray +lateinit var answer: IntArray + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + answer = IntArray(2) { Integer.MAX_VALUE } + + val (n, m) = readLine().trim().split(" ").map { it.toInt() } + val j = readLine().toInt() + val k = readLine().toInt() + + val a = IntArray(k) + + var token = StringTokenizer(readLine()) + repeat(k) { + a[it] = token.nextToken().toInt() + } + + val b = IntArray(k) + + token = StringTokenizer(readLine()) + repeat(k) { + b[it] = token.nextToken().toInt() + } + + graph = ArrayList() + + for (i in 0..n) { + graph.add(ArrayList()) + } + + repeat(m) { + val token = StringTokenizer(readLine()) + val s = token.nextToken().toInt() + val e = token.nextToken().toInt() + val d = token.nextToken().toInt() + + graph[s].add(Pair(e, d)) + graph[e].add(Pair(s, d)) + } + + dist = IntArray(n + 1) { Integer.MAX_VALUE } + visited = BooleanArray(n + 1) + dijkstra(j) + + for (i in a.indices) answer[0] = min(answer[0],dist[a[i]]) + for (i in b.indices) answer[1] = min(answer[1],dist[b[i]]) + + if (answer[0] == Integer.MAX_VALUE && answer[1] == Integer.MAX_VALUE) bw.write("-1") + else{ + if (answer[0] <= answer[1]) bw.write("A\n${answer[0]}") + else bw.write("B\n${answer[1]}") + } + + bw.flush() + bw.close() +} + +fun dijkstra(start: Int) { + val pq = PriorityQueue>(compareBy { it.second }) + + pq.offer(Pair(start, 0)) + dist[start] = 0 + + while (pq.isNotEmpty()) { + val (now, distance) = pq.poll() + + if (dist[now] < distance) continue + + for (next in graph[now]) { + if (!visited[next.first]) { + val cost = distance + next.second + if (cost < dist[next.first]) { + dist[next.first] = cost + pq.offer(Pair(next.first, cost)) + } + } + } + } +} \ No newline at end of file From 20a11620a427c663f9e8dc3195e379be622c5ede Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 10 Jul 2023 11:54:42 +0900 Subject: [PATCH 642/822] 0710 kihun --- 2023/07.10/Readme.md | 6 + ...\353\212\224\354\235\214\354\213\235.java" | 67 ++++++++++ ...\352\271\241\354\264\235\352\271\241.java" | 122 ++++++++++++++++++ ...\354\235\230\354\247\200\353\246\204.java" | 83 ++++++++++++ 4 files changed, 278 insertions(+) create mode 100644 2023/07.10/Readme.md create mode 100644 "2023/07.10/\354\206\241\352\270\260\355\233\210/\353\217\204\354\230\201\354\235\264\352\260\200\353\247\214\353\223\240\353\247\233\354\236\210\353\212\224\354\235\214\354\213\235.java" create mode 100644 "2023/07.10/\354\206\241\352\270\260\355\233\210/\354\264\235\352\271\241\354\264\235\352\271\241.java" create mode 100644 "2023/07.10/\354\206\241\352\270\260\355\233\210/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.java" diff --git a/2023/07.10/Readme.md b/2023/07.10/Readme.md new file mode 100644 index 0000000..335f6c8 --- /dev/null +++ b/2023/07.10/Readme.md @@ -0,0 +1,6 @@ +# 7.10(월) 스터디 + +- 백준 + - [트리의 지름](https://www.acmicpc.net/problem/1967) + - [도영이가 만든 맛있는 음식](https://www.acmicpc.net/problem/2961) + - [총깡 총깡](https://www.acmicpc.net/problem/14618) diff --git "a/2023/07.10/\354\206\241\352\270\260\355\233\210/\353\217\204\354\230\201\354\235\264\352\260\200\353\247\214\353\223\240\353\247\233\354\236\210\353\212\224\354\235\214\354\213\235.java" "b/2023/07.10/\354\206\241\352\270\260\355\233\210/\353\217\204\354\230\201\354\235\264\352\260\200\353\247\214\353\223\240\353\247\233\354\236\210\353\212\224\354\235\214\354\213\235.java" new file mode 100644 index 0000000..0c98833 --- /dev/null +++ "b/2023/07.10/\354\206\241\352\270\260\355\233\210/\353\217\204\354\230\201\354\235\264\352\260\200\353\247\214\353\223\240\353\247\233\354\236\210\353\212\224\354\235\214\354\213\235.java" @@ -0,0 +1,67 @@ +package baekjoon.silver.two; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 도영이가만든맛있는음식 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; + static boolean[] visited; + static int[] sourness; + static int[] bitterness; + static int minValue; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + + visited = new boolean[N]; + sourness = new int[N]; + bitterness = new int[N]; + minValue = Integer.MAX_VALUE; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + sourness[i] = Integer.parseInt(st.nextToken()); + bitterness[i] = Integer.parseInt(st.nextToken()); + } + + dfs(0); + System.out.println(minValue); + } + + public static void dfs(int depth) { + if (depth == N) { + int sour = 1; + int bitter = 0; + int count = 0; + for (int i = 0; i < N; i++) { + if (visited[i]) { + sour *= sourness[i]; + bitter += bitterness[i]; + count += 1; + } + } + + // 공집합 + if (count == 0) { + return; + } + int value = Math.abs(sour - bitter); + if (minValue > value) { + minValue = value; + } + return; + } + + // 원소를 포함하고 dfs, 포함하지 않고 dfs + visited[depth] = true; + dfs(depth + 1); + visited[depth] = false; + dfs(depth + 1); + + } + +} diff --git "a/2023/07.10/\354\206\241\352\270\260\355\233\210/\354\264\235\352\271\241\354\264\235\352\271\241.java" "b/2023/07.10/\354\206\241\352\270\260\355\233\210/\354\264\235\352\271\241\354\264\235\352\271\241.java" new file mode 100644 index 0000000..aaae54e --- /dev/null +++ "b/2023/07.10/\354\206\241\352\270\260\355\233\210/\354\264\235\352\271\241\354\264\235\352\271\241.java" @@ -0,0 +1,122 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 총깡총깡 { + + static class Node implements Comparable { + int point; + int distance; + + public Node(int point, int distance) { + this.point = point; + this.distance = distance; + } + + @Override + public int compareTo(Node node) { + return this.distance - node.distance; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + static int N, M, J, K; + static int[] houseType; + static ArrayList> nodeList; + static int[] distances; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + J = Integer.parseInt(br.readLine()); + K = Integer.parseInt(br.readLine()); + + houseType = new int[N + 1]; + StringTokenizer stA = new StringTokenizer(br.readLine()); + StringTokenizer stB = new StringTokenizer(br.readLine()); + for (int i = 0; i < K; i++) { + int indexA = Integer.parseInt(stA.nextToken()); + int indexB = Integer.parseInt(stB.nextToken()); + houseType[indexA] = 1; + houseType[indexB] = 2; + } + + nodeList = new ArrayList<>(); + for (int i = 0; i < N + 1; i++) { + nodeList.add(new ArrayList()); + } + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + int z = Integer.parseInt(st.nextToken()); + + nodeList.get(x).add(new Node(y, z)); + nodeList.get(y).add(new Node(x, z)); + } + + distances = new int[N + 1]; + dijkstra(J); + + // 최솟값 찾기 + int minValue = Integer.MAX_VALUE; + int minIndex = -1; + for (int i = 1; i < N + 1; i++) { + // 진서 집 넘기기 + if (i == J) continue; + + // 아무것도 아닌 집도 넘기기 + if (houseType[i] == 0) continue; + + if (minValue == distances[i]) { + // 최솟값과 같은데 A형이면 minIndex 교체 + if (houseType[i] == 1) { + minIndex = i; + } + } else if (minValue > distances[i]) { + minValue = distances[i]; + minIndex = i; + } + } + + // 결과값 출력 + if (minValue == Integer.MAX_VALUE) { + System.out.println(-1); + } else { + if (houseType[minIndex] == 1) { + System.out.println("A"); + } else { + System.out.println("B"); + } + System.out.println(minValue); + } + + } + + static void dijkstra(int index) { + Arrays.fill(distances, Integer.MAX_VALUE); + PriorityQueue queue = new PriorityQueue<>(); + queue.add(new Node(index, 0)); + + distances[index] = 0; + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + ArrayList nodes = nodeList.get(now.point); + + for (Node node : nodes) { + if (distances[node.point] > distances[now.point] + node.distance) { + distances[node.point] = distances[now.point] + node.distance; + queue.add(new Node(node.point, distances[node.point])); + } + } + } + } + +} diff --git "a/2023/07.10/\354\206\241\352\270\260\355\233\210/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.java" "b/2023/07.10/\354\206\241\352\270\260\355\233\210/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.java" new file mode 100644 index 0000000..3529991 --- /dev/null +++ "b/2023/07.10/\354\206\241\352\270\260\355\233\210/\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.java" @@ -0,0 +1,83 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class 트리의지름 { + + static class Node { + int point; + int distance; + + public Node(int point, int distance) { + this.point = point; + this.distance = distance; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; + static ArrayList> connections; + static boolean[] visited; + static int maxValue, maxIndex; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + + connections = new ArrayList<>(); + + for (int i = 0; i < N + 1; i++) { + connections.add(new ArrayList()); + } + + for (int i = 0; i < N - 1; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int parent = Integer.parseInt(st.nextToken()); + int child = Integer.parseInt(st.nextToken()); + int distance = Integer.parseInt(st.nextToken()); + + connections.get(parent).add(new Node(child, distance)); + connections.get(child).add(new Node(parent, distance)); + } + + maxValue = Integer.MIN_VALUE; + maxIndex = -1; + // 어떤 경로든 1을 거쳐가야 하므로 + // 1에서 제일 먼 곳 탐색하면 답을 구할 수 있다. + visited = new boolean[N + 1]; + visited[1] = true; + dfs(1, 0); + + // maxIndex에서 제일 먼 곳 탐색 + maxValue = Integer.MIN_VALUE; + visited = new boolean[N + 1]; + visited[maxIndex] = true; + dfs(maxIndex, 0); + + System.out.println(maxValue); + + } + + + static void dfs(int index, int distance) { + if (maxValue < distance) { + maxValue = distance; + maxIndex = index; + } + + ArrayList nodeList = connections.get(index); + + for (Node node : nodeList) { + if (!visited[node.point]) { + visited[node.point] = true; + dfs(node.point, distance + node.distance); + } + } + + } + +} From 9a4775b4dfc7aefb2fdd5031cb40b8aad4f7b175 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Mon, 10 Jul 2023 17:49:45 +0900 Subject: [PATCH 643/822] BOJ 1322 Solve --- .../BOJ 1322.kt" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ 1322.kt" diff --git "a/2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ 1322.kt" "b/2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ 1322.kt" new file mode 100644 index 0000000..5f79f05 --- /dev/null +++ "b/2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ 1322.kt" @@ -0,0 +1,46 @@ +package BOJ_1322_X와_K + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// input +private lateinit var br: BufferedReader + +// variables +private var X = 0L +private var K = 0L + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_1322_X와_K\\1322.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + val sb = StringBuilder() + + input() + + X = X.inv() + var j: Long = 0 + var ans: Long = 0 + + for (i in 0 until 64) { + if ((1L shl i) and X != 0L) { + if ((1L shl j.toInt()) and K != 0L) + ans += (1L shl i) + + j++ + } + } + + sb.append(ans) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun input() { + val st = StringTokenizer(br.readLine()) + X = st.nextToken().toLong() + K = st.nextToken().toLong() +} // End of input From 4e43bb382c923e8dae5f3b0fafe5dcddd81dfb24 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 11 Jul 2023 10:42:15 +0900 Subject: [PATCH 644/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EA=B0=9C?= =?UTF-8?q?=EB=AF=B8=EA=B5=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\352\260\234\353\257\270\352\265\264.kt" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "2023/07.13/\354\241\260\354\210\230\354\227\260/\352\260\234\353\257\270\352\265\264.kt" diff --git "a/2023/07.13/\354\241\260\354\210\230\354\227\260/\352\260\234\353\257\270\352\265\264.kt" "b/2023/07.13/\354\241\260\354\210\230\354\227\260/\352\260\234\353\257\270\352\265\264.kt" new file mode 100644 index 0000000..3d7c0e0 --- /dev/null +++ "b/2023/07.13/\354\241\260\354\210\230\354\227\260/\352\260\234\353\257\270\352\265\264.kt" @@ -0,0 +1,41 @@ +import java.io.* +import java.util.* +import kotlin.collections.HashMap + +data class Node(val children: HashMap = HashMap()) + +val bw = BufferedWriter(OutputStreamWriter(System.out)) + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val n = readLine().toInt() + val root = Node() + + repeat(n) { + val token = StringTokenizer(readLine()) + val k = token.nextToken().toInt() + var current = root + + repeat(k) { + val word = token.nextToken() + if (!current.children.containsKey(word)) { // 해당 층에 word가 없으면 추가 + current.children[word] = Node() + } + current = current.children[word]!! // 층 갱신 + } + } + + printNode(root, "") + + bw.flush() + bw.close() +} + +fun printNode(root: Node, bars: String) { + val keys = root.children.keys.sorted() + + for (i in keys.indices) { + bw.write("$bars${keys[i]}\n") + printNode(root.children[keys[i]]!!, "$bars--") + } +} From a7303c04529f098e6d72a7e96f8877f149016d96 Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 12 Jul 2023 09:35:38 +0900 Subject: [PATCH 645/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20X=EC=99=80?= =?UTF-8?q?=20K?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../X\354\231\200_K.kt" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "2023/07.13/\354\241\260\354\210\230\354\227\260/X\354\231\200_K.kt" diff --git "a/2023/07.13/\354\241\260\354\210\230\354\227\260/X\354\231\200_K.kt" "b/2023/07.13/\354\241\260\354\210\230\354\227\260/X\354\231\200_K.kt" new file mode 100644 index 0000000..78277ac --- /dev/null +++ "b/2023/07.13/\354\241\260\354\210\230\354\227\260/X\354\231\200_K.kt" @@ -0,0 +1,37 @@ +import java.io.* +import kotlin.math.pow + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (x,k) = readLine().trim().split(" ").map { it.toInt() } + + val binaryX = x.toString(2) + val binaryK = k.toString(2) + + var answer = 0L + var c = ' ' + var idx = binaryK.length-1 + var i = 0 + + while (idx >= 0){ + // 이진수 x의 오른쪽부터 탐색 + c = if (i < binaryX.length) binaryX[binaryX.length-1-i] + else '0' + + if (c == '0'){ // 1인 비트는 넘어가고 0인 비트일 경우에 체크 + if (binaryK[idx] == '1'){ // 이진수 k의 idx가 1이면 조건을 만족 + val a : Long = 2.0.pow(i.toDouble()).toLong() + answer += a + } + idx-- + } + i++ + } + + bw.write("$answer") + + bw.flush() + bw.close() +} \ No newline at end of file From e4302042dd916f3c559c840610ce7642977ec73d Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Wed, 12 Jul 2023 14:28:37 +0900 Subject: [PATCH 646/822] BOJ 14725 Solve --- ...5_\352\260\234\353\257\270\352\265\264.kt" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ_14725_\352\260\234\353\257\270\352\265\264.kt" diff --git "a/2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ_14725_\352\260\234\353\257\270\352\265\264.kt" "b/2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ_14725_\352\260\234\353\257\270\352\265\264.kt" new file mode 100644 index 0000000..9d22057 --- /dev/null +++ "b/2023/07.13/\354\265\234\354\260\275\354\230\201/BOJ_14725_\352\260\234\353\257\270\352\265\264.kt" @@ -0,0 +1,84 @@ +package BOJ_14725_개미굴 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// input +private lateinit var br: BufferedReader + +// variables +private const val FLOOR = "--" +private var N = 0 +private var K = 0 +private var ans = StringBuilder() + +private data class Trie(var name: String, var edge: ArrayList) + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_14725_개미굴\\res.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + input() + + solve() + + bw.write(ans.toString()) + bw.close() +} // End of main + +private fun DFS(trie: Trie, depth: Int) { + val comp = Comparator { o1, o2 -> o1!!.name.compareTo(o2!!.name) } + trie.edge.sortWith(comp) + + if (depth != -1) { + for (i in 0 until depth) { + ans.append(FLOOR) + } + ans.append(trie.name).append('\n') + } + + trie.edge.forEach { + DFS(it, depth + 1) + } +} // End of DFS + +private fun solve() { + var trie = Trie("", ArrayList()) + var node: Trie + + while (N-- > 0) { + val st = StringTokenizer(br.readLine()) + K = st.nextToken().toInt() + node = trie + + while (K-- > 0) { + var name = st.nextToken() + var idx = -1 + + var size = node.edge.size + for (i in 0 until size) { + if (node.edge[i].name == name) { + idx = i + break + } + } + + if (idx == -1) { + node.edge.add(Trie(name, ArrayList())) + node = node.edge[node.edge.size - 1] + } else { + node = node.edge[idx] + } + } + } + + DFS(trie, -1) +} // End of solve + +private fun input() { + N = br.readLine().toInt() +} // End of input From aa2ff4c0c4d456050e95d23911cebc79ee07aa3f Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 13 Jul 2023 16:54:46 +0900 Subject: [PATCH 647/822] 0713 kihun --- 2023/07.13/Readme.md | 5 ++ .../X\354\231\200K.java" | 52 +++++++++++++++++++ ...\352\260\234\353\257\270\352\265\264.java" | 50 ++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 2023/07.13/Readme.md create mode 100644 "2023/07.13/\354\206\241\352\270\260\355\233\210/X\354\231\200K.java" create mode 100644 "2023/07.13/\354\206\241\352\270\260\355\233\210/\352\260\234\353\257\270\352\265\264.java" diff --git a/2023/07.13/Readme.md b/2023/07.13/Readme.md new file mode 100644 index 0000000..b932ea2 --- /dev/null +++ b/2023/07.13/Readme.md @@ -0,0 +1,5 @@ +# 7.13(목) 스터디 + +- 백준 + - [X와 K](https://www.acmicpc.net/problem/1322) + - [개미굴](https://www.acmicpc.net/problem/14725) diff --git "a/2023/07.13/\354\206\241\352\270\260\355\233\210/X\354\231\200K.java" "b/2023/07.13/\354\206\241\352\270\260\355\233\210/X\354\231\200K.java" new file mode 100644 index 0000000..c11b190 --- /dev/null +++ "b/2023/07.13/\354\206\241\352\270\260\355\233\210/X\354\231\200K.java" @@ -0,0 +1,52 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +// X 이진수 중 1인 곳은 0으로, 나머지는 K 이진수로 표현한 것을 넣어준다. +public class X와K { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + String sX = Integer.toBinaryString(x); + String sK = Integer.toBinaryString(k); + + + StringBuilder sb = new StringBuilder(); + int kIndex = sK.length() - 1; + + // sX의 끝에서 시작으로 + for (int i = sX.length()-1; i >= 0; i--) { + char c = sX.charAt(i); + + // c가 1이면 결과값에 0을 추가 + if (c == '1') { + sb.insert(0, 0); + } + // c가 0이면 kIndex를 하나 줄이고 0 추가 + else { + if (kIndex == -1) { + continue; + }; + sb.insert(0, sK.charAt(kIndex)); + kIndex--; + } + } + + // sX가 끝났는데도 kIndex가 남아있다면 sK를 넣어준다 + while (kIndex >= 0) { + sb.insert(0, sK.charAt(kIndex)); + kIndex--; + } + + System.out.println(Long.parseLong(sb.toString(), 2)); + + } + +} diff --git "a/2023/07.13/\354\206\241\352\270\260\355\233\210/\352\260\234\353\257\270\352\265\264.java" "b/2023/07.13/\354\206\241\352\270\260\355\233\210/\352\260\234\353\257\270\352\265\264.java" new file mode 100644 index 0000000..679e63b --- /dev/null +++ "b/2023/07.13/\354\206\241\352\270\260\355\233\210/\352\260\234\353\257\270\352\265\264.java" @@ -0,0 +1,50 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +import java.util.TreeMap; + +public class 개미굴 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; + + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + + TreeMap root = new TreeMap<>(); + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int K = Integer.parseInt(st.nextToken()); + + TreeMap targetNode = root; + + for (int j = 0; j < K; j++) { + String node = st.nextToken(); + + if (!targetNode.containsKey(node)) { + targetNode.put(node, new TreeMap<>()); + } + + targetNode = (TreeMap) targetNode.get(node); + + } + } + printResult(root, 0); + + } + + static void printResult(TreeMap treeMap, int depth) { + for (Object object : treeMap.keySet()) { + for (int i = 0; i < depth; i++) { + System.out.print("--"); + } + System.out.println(object); + printResult((TreeMap) treeMap.get(object), depth + 1); + } + } + +} From e3d3eb2dec10af0e0265df1aa113bd122d6b34f1 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 13 Jul 2023 22:13:23 +0900 Subject: [PATCH 648/822] =?UTF-8?q?Create=20X=EC=99=80K.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../X\354\231\200K.java" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "2023/07.13/\354\240\225\355\230\270\354\241\260/X\354\231\200K.java" diff --git "a/2023/07.13/\354\240\225\355\230\270\354\241\260/X\354\231\200K.java" "b/2023/07.13/\354\240\225\355\230\270\354\241\260/X\354\231\200K.java" new file mode 100644 index 0000000..9455906 --- /dev/null +++ "b/2023/07.13/\354\240\225\355\230\270\354\241\260/X\354\231\200K.java" @@ -0,0 +1,45 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/** + * X + Y == X | Y 이기 위해서는 X를 이진수로 변환했을 때 X의 n번째 자리가 1이면 Y의 n번째 자리는 0이어야함 + * -> 둘 다 1이게 되면 덧셈 시 자릿수가 넘어가게 되어 OR 연산의 결과값과 같아질 수 없기 때문 + * 나머지 자리는 K를 이진수로 변환한 후 0번째 자리수 부터 차례로 넣어주면 됨 + * */ + +public class X와K_1322 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + long x = Long.parseLong(st.nextToken()); + long k = Long.parseLong(st.nextToken()); + String binaryX = Long.toBinaryString(x); + String binaryK = Long.toBinaryString(k); + StringBuilder result = new StringBuilder(); + int idx = binaryK.length() - 1; + + for (int i = binaryX.length() - 1; i >= 0; i--) { + char cur = binaryX.charAt(i); + + if(cur == '0'){ + if(idx == -1) continue; + + result.insert(0, binaryK.charAt(idx)); + idx--; + } else { + result.insert(0, 0); + } + } + + while(idx >= 0){ + result.insert(0, binaryK.charAt(idx)); + idx--; + } + + Long ans = Long.parseLong(result.toString(), 2); + System.out.println(ans); + } +} From 2933ae00acb18d1396b743328c62d24a9d8daa0a Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 14 Jul 2023 10:09:40 +0900 Subject: [PATCH 649/822] [SOLVE] @josooyeon11 : ABCDE --- .../ABCDE.kt" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "2023/07.17/\354\241\260\354\210\230\354\227\260/ABCDE.kt" diff --git "a/2023/07.17/\354\241\260\354\210\230\354\227\260/ABCDE.kt" "b/2023/07.17/\354\241\260\354\210\230\354\227\260/ABCDE.kt" new file mode 100644 index 0000000..8c38a08 --- /dev/null +++ "b/2023/07.17/\354\241\260\354\210\230\354\227\260/ABCDE.kt" @@ -0,0 +1,59 @@ +import java.io.* +import java.util.* +import kotlin.system.exitProcess + +lateinit var graph: ArrayList> +lateinit var visited: BooleanArray + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (n, m) = readLine().trim().split(" ").map { it.toInt() } + + graph = ArrayList() + + for (i in 0 until n) { + graph.add(ArrayList()) + } + + visited = BooleanArray(n) + + repeat(m) { + val token = StringTokenizer(readLine()) + val s = token.nextToken().toInt() + val e = token.nextToken().toInt() + + graph[s].add(e) + graph[e].add(s) + } + + for (i in 0 until n) { + visited = BooleanArray(n) + (dfs(i, 0)) + } + + bw.write("0") + + + bw.flush() + bw.close() +} + +fun dfs(start: Int, depth: Int): Boolean { + if (depth == 4) { + print(1) + exitProcess(0) + } + + visited[start] = true + + for (next in graph[start]) { + if (!visited[next]) { + dfs(next, depth + 1) + visited[next] = false + } + } + + return false +} \ No newline at end of file From 37d736e06fc5e6dca32c2875c44fa645f3e9a0f6 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:48:56 +0900 Subject: [PATCH 650/822] Create ABCDE.java --- .../ABCDE.java" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "2023/07.17/\354\240\225\355\230\270\354\241\260/ABCDE.java" diff --git "a/2023/07.17/\354\240\225\355\230\270\354\241\260/ABCDE.java" "b/2023/07.17/\354\240\225\355\230\270\354\241\260/ABCDE.java" new file mode 100644 index 0000000..907011a --- /dev/null +++ "b/2023/07.17/\354\240\225\355\230\270\354\241\260/ABCDE.java" @@ -0,0 +1,63 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class ABCDE_13023 { + static int N, M, ans; + static boolean check; + static int[] dist; + static boolean[] vis; + static ArrayList> list; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + ans = 0; + list = new ArrayList<>(); + for (int i = 0; i < N; i++) { + list.add(new ArrayList<>()); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list.get(a).add(b); + list.get(b).add(a); + } + + for (int i = 0; i < N; i++) { + vis = new boolean[N]; + check = false; + vis[i] = true; + getResult(i, 0); + if (check) { + ans = 1; + break; + } + } + + System.out.println(ans); + } + + static void getResult(int start, int cnt) { + if (cnt >= 4) { + check = true; + return; + } + + for (int i : list.get(start)) { + if(!vis[i]){ + vis[i] = true; + getResult(i, cnt + 1); + vis[i] = false; + } + } + + } +} From 17cd36030d1ddfc0c39961e7994312dca4323e45 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:51:13 +0900 Subject: [PATCH 651/822] Create ReadMe.md --- 2023/07.17/ReadMe.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 2023/07.17/ReadMe.md diff --git a/2023/07.17/ReadMe.md b/2023/07.17/ReadMe.md new file mode 100644 index 0000000..09192f2 --- /dev/null +++ b/2023/07.17/ReadMe.md @@ -0,0 +1,6 @@ +# 7.17() 스터디 + +- 백준 + - [XOR 삼형제1](https://www.acmicpc.net/problem/10728) + - [ABCDE](https://www.acmicpc.net/board/view/58474) + - [잘못 구현한 에라토스테네스의 체](https://www.acmicpc.net/problem/15897) From 878470e4bad0c6745cd30ae021e4f71ee0e0511a Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 14 Jul 2023 13:13:40 +0900 Subject: [PATCH 652/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=20=EA=B5=AC=ED=98=84=ED=95=9C=20=EC=97=90=EB=9D=BC?= =?UTF-8?q?=ED=86=A0=EC=8A=A4=ED=85=8C=EB=84=A4=EC=8A=A4=EC=9D=98=20?= =?UTF-8?q?=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\212\244\354\235\230_\354\262\264.kt" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "2023/07.17/\354\241\260\354\210\230\354\227\260/\354\236\230\353\252\273_\352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230_\354\262\264.kt" diff --git "a/2023/07.17/\354\241\260\354\210\230\354\227\260/\354\236\230\353\252\273_\352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230_\354\262\264.kt" "b/2023/07.17/\354\241\260\354\210\230\354\227\260/\354\236\230\353\252\273_\352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230_\354\262\264.kt" new file mode 100644 index 0000000..608b4b6 --- /dev/null +++ "b/2023/07.17/\354\241\260\354\210\230\354\227\260/\354\236\230\353\252\273_\352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230_\354\262\264.kt" @@ -0,0 +1,27 @@ +import java.io.* + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + + var sum = n.toLong() + var i = 2 + + // 조화수열 + while (i < n) { + val j = (n - 1) / ((n - 1) / i) // i 구간에서 j까지의 구간의 숫자는 같은 연산의 횟수를 가짐 + val num = 1 + (n - 1) / i // i마다 연산의 횟수 + sum += (j - i + 1) * num + + i = j + 1 // 다음 구간으로 세팅 + } + + if (n != 1) sum++ // n이 1이 아닐 때 i가 n일 때 가지는 연산은 무조건 1 + + bw.write("$sum") + + bw.flush() + bw.close() +} \ No newline at end of file From 64f368f7e454a6d662955853b445d2b4afb2fefa Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Fri, 14 Jul 2023 13:26:35 +0900 Subject: [PATCH 653/822] BOJ 13023 ABCDE Solve --- .../BOJ 13023 ABCDE.kt" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 13023 ABCDE.kt" diff --git "a/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 13023 ABCDE.kt" "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 13023 ABCDE.kt" new file mode 100644 index 0000000..acecc7b --- /dev/null +++ "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 13023 ABCDE.kt" @@ -0,0 +1,81 @@ +package BOJ_13023_ABCDE + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// input +private lateinit var br: BufferedReader +private lateinit var sb: StringBuilder + +// variables +private var N = 0 +private var M = 0 + +private lateinit var isVisited: BooleanArray +private lateinit var adjList: MutableList> + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_13023_ABCDE\\res.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + sb = StringBuilder() + + input() + + solve() + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun solve() { + for (i in 0 until N) { + if (DFS(i, 0)) { + sb.append(1) + return + } + } + + sb.append(0) +} // End of sovle + +private fun DFS(cur: Int, depth: Int): Boolean { + if (depth == 4) return true + isVisited[cur] = true + var ret = false + + for (nextCur in adjList[cur]) { + if (isVisited[nextCur]) continue + if (DFS(nextCur, depth + 1)) { + ret = true + break + } + } + + isVisited[cur] = false + return ret +} // End of DFS + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() + M = st.nextToken().toInt() + isVisited = BooleanArray(N) + + adjList = ArrayList() + for (i in 0 until N) { + adjList.add(ArrayList()) + } + + for (i in 0 until M) { + st = StringTokenizer(br.readLine()) + val a = st.nextToken().toInt() + val b = st.nextToken().toInt() + + adjList[a].add(b) + adjList[b].add(a) + } +} // End of input From 2edb5f65147aa9bd6044ce529c86ff26f742ad30 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 16 Jul 2023 17:38:15 +0900 Subject: [PATCH 654/822] BOJ 10218 Solve --- ...\354\202\274\355\230\225\354\240\234 1.kt" | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" diff --git "a/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" new file mode 100644 index 0000000..03004a3 --- /dev/null +++ "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" @@ -0,0 +1,76 @@ +package BOJ_10728 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter + +// input +private lateinit var br: BufferedReader +private lateinit var sb: StringBuilder + +// variables +private var N = 0 + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_10728\\res.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + sb = StringBuilder() + + var T = br.readLine().toInt() + while (T-- > 0) { + input() + + solve() + } + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun solve() { + var max = 0 + val resultList = mutableListOf() + + for (i in 1 until (1 shl N)) { + val list = mutableListOf() + + for (j in 0 until N) { + if ((1 shl j and i) != 0) { + list.add(j + 1) + } + } + + val size = list.size + if (check(list, size)) { + + if (size > max) { + max = size + resultList.clear() + resultList.addAll(list) + } + } + } + + sb.append(resultList.size).append('\n') + resultList.forEach { + sb.append(it).append(' ') + } + sb.append('\n') +} // End of solve + +private fun check(list: List, size: Int): Boolean { + for (i in list.indices) { + for (j in i + 1 until size) { + for (k in j + 1 until size) { + if ((list[i] xor list[j] xor list[k]) == 0) return false + } + } + } + return true +} // End of check + +private fun input() { + N = br.readLine().toInt() +} // End of input From 269ec851d14f9678b052d03b196f7df9c4c158e4 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 16 Jul 2023 17:40:45 +0900 Subject: [PATCH 655/822] BOJ 10728 Solve --- .../BOJ 10728 XOR\354\202\274\355\230\225\354\240\234 1.kt" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" => "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10728 XOR\354\202\274\355\230\225\354\240\234 1.kt" (100%) diff --git "a/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10728 XOR\354\202\274\355\230\225\354\240\234 1.kt" similarity index 100% rename from "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10218 XOR\354\202\274\355\230\225\354\240\234 1.kt" rename to "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 10728 XOR\354\202\274\355\230\225\354\240\234 1.kt" From dd10e9d399989a0afe9adf1f9e5573a30255934c Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sun, 16 Jul 2023 17:46:34 +0900 Subject: [PATCH 656/822] add Readme --- .../\354\265\234\354\260\275\354\230\201/ReadMe.md" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "2023/07.17/\354\265\234\354\260\275\354\230\201/ReadMe.md" diff --git "a/2023/07.17/\354\265\234\354\260\275\354\230\201/ReadMe.md" "b/2023/07.17/\354\265\234\354\260\275\354\230\201/ReadMe.md" new file mode 100644 index 0000000..2bde2ff --- /dev/null +++ "b/2023/07.17/\354\265\234\354\260\275\354\230\201/ReadMe.md" @@ -0,0 +1,9 @@ +## BOJ 10728 XOR삼형제 1 + +임의의 수 3개를 선택하는 문제였으니까, 그냥 3중 for문 돌리면 되나 생각함 -> 카테고리도 완탐이었음 + + +시간보니까 5초, N도 20이 max면 가능할 것 같다고 생각함 + +문제 자료를 찾아보니까 +이 문제의 원래 풀이 목적은 백트래킹 완탐으로 풀라고 만들어진 문제라고 되어있었다. \ No newline at end of file From e51b4a586df8bde4d9ec11e68e67165faedd6bd2 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 16 Jul 2023 23:55:32 +0900 Subject: [PATCH 657/822] 0717 kihun --- .../ABCDE.java" | 71 +++++++++++++++ ...354\202\274\355\230\225\354\240\2341.java" | 91 +++++++++++++++++++ ...\354\212\244\354\235\230\354\262\264.java" | 54 +++++++++++ 3 files changed, 216 insertions(+) create mode 100644 "2023/07.17/\354\206\241\352\270\260\355\233\210/ABCDE.java" create mode 100644 "2023/07.17/\354\206\241\352\270\260\355\233\210/XOR\354\202\274\355\230\225\354\240\2341.java" create mode 100644 "2023/07.17/\354\206\241\352\270\260\355\233\210/\354\236\230\353\252\273\352\265\254\355\230\204\355\225\234\354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230\354\262\264.java" diff --git "a/2023/07.17/\354\206\241\352\270\260\355\233\210/ABCDE.java" "b/2023/07.17/\354\206\241\352\270\260\355\233\210/ABCDE.java" new file mode 100644 index 0000000..c0cf178 --- /dev/null +++ "b/2023/07.17/\354\206\241\352\270\260\355\233\210/ABCDE.java" @@ -0,0 +1,71 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class ABCDE { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M; + static ArrayList> nodeList; + static boolean flag; + static boolean[] visited; + + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + nodeList = new ArrayList<>(); + + for (int i = 0; i < N; i++) { + nodeList.add(new ArrayList<>()); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + nodeList.get(a).add(b); + nodeList.get(b).add(a); + } + + for (int i = 0; i < N; i++) { + visited = new boolean[N]; + visited[i] = true; + dfs(i, 0); + visited[i] = false; + if (flag) { + break; + } + } + + if (flag) { + System.out.println(1); + } else { + System.out.println(0); + } + } + + static void dfs(int index, int depth) { + if (depth == 4) { + flag = true; + return; + } + + ArrayList tempList = nodeList.get(index); + for (int tempIndex : tempList) { + if (!visited[tempIndex]) { + visited[tempIndex] = true; + dfs(tempIndex, depth + 1); + visited[tempIndex] = false; + } + } + } + +} diff --git "a/2023/07.17/\354\206\241\352\270\260\355\233\210/XOR\354\202\274\355\230\225\354\240\2341.java" "b/2023/07.17/\354\206\241\352\270\260\355\233\210/XOR\354\202\274\355\230\225\354\240\2341.java" new file mode 100644 index 0000000..2772aca --- /dev/null +++ "b/2023/07.17/\354\206\241\352\270\260\355\233\210/XOR\354\202\274\355\230\225\354\240\2341.java" @@ -0,0 +1,91 @@ +package baekjoon.silver.one; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; + +public class XOR삼형제1 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int T, N; + static boolean flag; + static boolean[] visited; + + + public static void main(String[] args) throws IOException { + T = Integer.parseInt(br.readLine()); + + ArrayList inputs = new ArrayList<>(); + for (int i = 0; i < T; i++) { + int n = Integer.parseInt(br.readLine()); + inputs.add(n); + } + + for (int input : inputs) { + flag = false; + N = input; + for (int target = input; target > 0; target--) { + visited = new boolean[input + 1]; + + dfs(1, 0, target); + + if (flag) { + break; + } + } + } + + + } + + static boolean check(ArrayList numbers) { + for (int i = 0; i < numbers.size() - 2; i++) { + for (int j = i + 1; j < numbers.size() - 1; j++) { + for (int k = j + 1; k < numbers.size(); k++) { + if ((numbers.get(i) ^ numbers.get(j) ^ numbers.get(k)) == 0) { + return false; + } + } + } + } + return true; + } + + static void dfs(int index, int depth, int target) { + if (flag) { + return; + } + + if (depth == target) { + ArrayList numbers = new ArrayList<>(); + for (int i = 0; i <= N; i++) { + if (visited[i]) { + numbers.add(i); + } + } + if (check(numbers)) { + flag = true; + System.out.println(numbers.size()); + StringBuilder sb = new StringBuilder(); + for (int e : numbers) { + sb.append(e); + sb.append(" "); + } + sb.deleteCharAt(sb.length() - 1); + System.out.println(sb); + } + return; + } + + for (int i = index; i <= N; i++) { + if (!visited[i]) { + visited[i] = true; + dfs(i + 1, depth + 1, target); + visited[i] = false; + } + } + } + +} diff --git "a/2023/07.17/\354\206\241\352\270\260\355\233\210/\354\236\230\353\252\273\352\265\254\355\230\204\355\225\234\354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230\354\262\264.java" "b/2023/07.17/\354\206\241\352\270\260\355\233\210/\354\236\230\353\252\273\352\265\254\355\230\204\355\225\234\354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230\354\262\264.java" new file mode 100644 index 0000000..1cfaeda --- /dev/null +++ "b/2023/07.17/\354\206\241\352\270\260\355\233\210/\354\236\230\353\252\273\352\265\254\355\230\204\355\225\234\354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230\354\262\264.java" @@ -0,0 +1,54 @@ +package baekjoon.gold.two; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 잘못구현한에라토스테네스의체 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + + long result = N; + for (int i = 2, temp; i < N; i = temp + 1) { + int j = (N - 1) / i + 1; + + // j값을 만족하는 최대값 + temp = (N - 1) / ((N - 1) / i); + result += (long) (temp - i + 1) * j; + } + + if (N != 1) { + System.out.println(result + 1); + } else { + System.out.println(result); + } + + } + + /* + (N-1) / i = (N-1) / temp + temp = (N-1) / ((N-1) / i)) + */ + +} + +/* +i: 2 j: 5 +i: 3 j: 4 +i: 4 j: 3 +i: 5 j: 2 +i: 6 j: 2 +i: 7 j: 2 +i: 8 j: 2 +i: 9 j: 2 +i: 10 j: 1 +****************** +i: 2 temp: 2 +i: 3 temp: 3 +i: 4 temp: 4 +i: 5 temp: 9 +* */ \ No newline at end of file From 3926d2b17267be60fdb0a22f1301bc2de553cec6 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Mon, 17 Jul 2023 14:47:11 +0900 Subject: [PATCH 658/822] BOJ 15897 Solve --- ...4\354\212\244\354\235\230 \354\262\264.kt" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 15897 \354\236\230\353\252\273 \352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230 \354\262\264.kt" diff --git "a/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 15897 \354\236\230\353\252\273 \352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230 \354\262\264.kt" "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 15897 \354\236\230\353\252\273 \352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230 \354\262\264.kt" new file mode 100644 index 0000000..ce20930 --- /dev/null +++ "b/2023/07.17/\354\265\234\354\260\275\354\230\201/BOJ 15897 \354\236\230\353\252\273 \352\265\254\355\230\204\355\225\234 \354\227\220\353\235\274\355\206\240\354\212\244\355\205\214\353\204\244\354\212\244\354\235\230 \354\262\264.kt" @@ -0,0 +1,62 @@ +package BOJ_15897 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter + +// input +private lateinit var br: BufferedReader +private lateinit var sb: StringBuilder + +// variables +private var N = 0L + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_15897\\res.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.`out`)) + sb = StringBuilder() + + input() + + test() + + sb.append(solve()) + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun solve(): Long { + var ans: Long = 1 + + var i = 1 + var j = 0 + while(i < N){ + j = ((N - 1) % i / ((N - 1) / i) + 1).toInt() + ans += ((N - 1) / i + 1) * j + i += j + } + + return ans +} // End of solve + +private fun test() { + var n = 1560 + var count = 0 + + var arr = IntArray(n + 1) + for(i in 1 .. n) { + for(j in 1 .. n step i) { + count++ + println("i : $i , j : $j , count : $count") + arr[j] += 1 + } + } + println("count : $count") + println(arr.contentToString()) +} // End of test + +private fun input() { + N = br.readLine().toLong() +} // End of input From 928df89fceab08c9bdf9d197a0a597087d229d6c Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Tue, 18 Jul 2023 19:19:10 +0900 Subject: [PATCH 659/822] BOJ 9372 Solve --- ...4\354\235\230 \354\227\254\355\226\211.kt" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "2023/07.20/\354\265\234\354\260\275\354\230\201/BOJ 9372 \354\203\201\352\267\274\354\235\264\354\235\230 \354\227\254\355\226\211.kt" diff --git "a/2023/07.20/\354\265\234\354\260\275\354\230\201/BOJ 9372 \354\203\201\352\267\274\354\235\264\354\235\230 \354\227\254\355\226\211.kt" "b/2023/07.20/\354\265\234\354\260\275\354\230\201/BOJ 9372 \354\203\201\352\267\274\354\235\264\354\235\230 \354\227\254\355\226\211.kt" new file mode 100644 index 0000000..9794b8a --- /dev/null +++ "b/2023/07.20/\354\265\234\354\260\275\354\230\201/BOJ 9372 \354\203\201\352\267\274\354\235\264\354\235\230 \354\227\254\355\226\211.kt" @@ -0,0 +1,82 @@ +package BOJ_9372 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* + +// input +private lateinit var br: BufferedReader +private lateinit var sb: StringBuilder + +// variables +private const val INF = Int.MAX_VALUE +private var N = 0 +private var M = 0 + +private lateinit var adjList: MutableList> + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_9372\\res.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + sb = StringBuilder() + + val t = br.readLine().toInt() + repeat(t) { + input() + + solve() + } + + bw.write(sb.toString()) + bw.close() +} // End of main + +private fun BFS(startNode: Int): Int { + val isVisited = BooleanArray(N + 1) + val que: Queue = LinkedList() + + que.offer(startNode) + var result = 0 + isVisited[startNode] = true + + while (que.isNotEmpty()) { + result++ + val poll = que.poll() + + adjList[poll].forEach { nextNode -> + if (!isVisited[nextNode]) { + que.offer(nextNode) + isVisited[nextNode] = true + } + } + } + + return result - 1 +} // End of BFS + +private fun solve() { + sb.append(BFS(1)).append('\n') +} // End of solve + +private fun input() { + var st = StringTokenizer(br.readLine()) + N = st.nextToken().toInt() + M = st.nextToken().toInt() + + adjList = ArrayList() + repeat(N + 1) { + adjList.add(ArrayList()) + } + + repeat(M) { + st = StringTokenizer(br.readLine()) + val a = st.nextToken().toInt() + val b = st.nextToken().toInt() + + adjList[a].add(b) + adjList[b].add(a) + } +} // End of input \ No newline at end of file From 6dd55c7fa35506646bb95c2a3a5d2e4dd03270ee Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 20 Jul 2023 22:51:18 +0900 Subject: [PATCH 660/822] =?UTF-8?q?Create=20=EC=83=81=EA=B7=BC=EC=9D=B4?= =?UTF-8?q?=EC=9D=98=EC=97=AC=ED=96=89.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\230\354\227\254\355\226\211.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/07.20/\354\240\225\355\230\270\354\241\260/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" diff --git "a/2023/07.20/\354\240\225\355\230\270\354\241\260/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" "b/2023/07.20/\354\240\225\355\230\270\354\241\260/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" new file mode 100644 index 0000000..3936eb5 --- /dev/null +++ "b/2023/07.20/\354\240\225\355\230\270\354\241\260/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" @@ -0,0 +1,44 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +/**모든 국가는 연결되어있으므로 (간선의 개수) == (노드의 개수) - 1 -> 최소 신장 트리*/ +public class 상근이의여행_9372 { + static int N, M, ans; + static int[] dist; + static boolean[] vis; + static ArrayList> list; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + ans = Integer.MAX_VALUE; + dist = new int[N + 1]; + vis = new boolean[N + 1]; + list = new ArrayList<>(); + for (int i = 0; i <= N; i++) { + list.add(new ArrayList<>()); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + list.get(a).add(b); + list.get(b).add(a); + } + + System.out.println(N-1); + } + } +} From 4e29fa3672a3e8960a6bdf83a31cdd77f94019ec Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 21 Jul 2023 09:17:22 +0900 Subject: [PATCH 661/822] 0720 kihun --- 2023/07.20/Readme.md | 5 ++ ...\353\230\245\353\262\214\353\240\210.java" | 64 +++++++++++++++++++ ...\354\235\230\354\227\254\355\226\211.java" | 63 ++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 2023/07.20/Readme.md create mode 100644 "2023/07.20/\354\206\241\352\270\260\355\233\210/\352\260\234\353\230\245\353\262\214\353\240\210.java" create mode 100644 "2023/07.20/\354\206\241\352\270\260\355\233\210/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" diff --git a/2023/07.20/Readme.md b/2023/07.20/Readme.md new file mode 100644 index 0000000..8ad9df9 --- /dev/null +++ b/2023/07.20/Readme.md @@ -0,0 +1,5 @@ +# 7.20(목) 스터디 + +- 백준 + - [개똥벌레](https://www.acmicpc.net/problem/3020) + - [상근이의 여행](https://www.acmicpc.net/problem/9372) diff --git "a/2023/07.20/\354\206\241\352\270\260\355\233\210/\352\260\234\353\230\245\353\262\214\353\240\210.java" "b/2023/07.20/\354\206\241\352\270\260\355\233\210/\352\260\234\353\230\245\353\262\214\353\240\210.java" new file mode 100644 index 0000000..a81fcdf --- /dev/null +++ "b/2023/07.20/\354\206\241\352\270\260\355\233\210/\352\260\234\353\230\245\353\262\214\353\240\210.java" @@ -0,0 +1,64 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +// https://kunduz.tistory.com/entry/BAEKJOON-%EB%B0%B1%EC%A4%80-3020-%EA%B0%9C%EB%98%A5%EB%B2%8C%EB%A0%88-JAVA +// https://jjong2.tistory.com/60 +public class 개똥벌레 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, H; + static int[] lowObstacles, highObstacles; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 동굴의 길이 + H = Integer.parseInt(st.nextToken()); // 동굴의 높이 + lowObstacles = new int[H + 1]; // 석순 + highObstacles = new int[H + 1]; // 종유석 + + // 석순과 종유석 + for (int i = 1; i <= N; i++) { + int obstacleHeight = Integer.parseInt(br.readLine()); + + // 홀수는 석순 + if (i % 2 == 1) { + lowObstacles[obstacleHeight] += 1; + } + // 짝수는 종유석 + else { + highObstacles[obstacleHeight] += 1; + } + } + + // 누적합으로 전환 + for (int i = 2; i <= H; i++) { + // 높이 i 이하인 것의 석순, 종유석 + lowObstacles[i] += lowObstacles[i - 1]; + highObstacles[i] += highObstacles[i - 1]; + } + + // 각 높이마다 부딪히는 곳을 계산 + int minValue = Integer.MAX_VALUE; + int count = 1; + for (int i = 1; i <= H; i++) { + int temp = 0; + // 높이 i의 장애물 갯수 + temp += lowObstacles[H] - lowObstacles[i - 1]; + temp += highObstacles[H] - highObstacles[H - i]; + + if (minValue > temp) { + minValue = temp; + count = 1; + } else if (minValue == temp) { + count += 1; + } + } + System.out.println(minValue + " " + count); + } +} \ No newline at end of file diff --git "a/2023/07.20/\354\206\241\352\270\260\355\233\210/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" "b/2023/07.20/\354\206\241\352\270\260\355\233\210/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" new file mode 100644 index 0000000..5f4faa4 --- /dev/null +++ "b/2023/07.20/\354\206\241\352\270\260\355\233\210/\354\203\201\352\267\274\354\235\264\354\235\230\354\227\254\355\226\211.java" @@ -0,0 +1,63 @@ +package baekjoon.silver.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class 상근이의여행 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int T, N, M; + + public static void main(String[] args) throws IOException { + T = Integer.parseInt(br.readLine()); + + for (int t = 0; t < T; t++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 국가의 수 + M = Integer.parseInt(st.nextToken()); // 비행기의 종류 + + int[][] graph = new int[N+1][N+1]; + boolean[] visited = new boolean[N+1]; + + for (int m = 0; m < M; m++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + graph[a][b] = 1; + graph[b][a] = 1; + } + + int result = bfs(graph, visited) - 1; + System.out.println(result); + } + + } + + static int bfs(int[][] graph, boolean[] visited) { + Queue queue = new LinkedList<>(); + queue.add(1); + visited[1] = true; + int result = 0; + while (!queue.isEmpty()) { + result += 1; + int node = queue.poll(); + for (int i = 1; i <= N; i++) { + if (!visited[i] && graph[node][i] == 1) { + visited[i] = true; + queue.add(i); + } + } + } + + return result; + } +} + +/* +연결 그래프를 만족한다 -> 신장 트리를 만들 수 있다 -> 최소 신장 트리의 간선은 (노드 수 - 1) + */ From 65a2d9d0a00807ba5651f7084d6ccfa04b65b5f8 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 24 Jul 2023 10:26:24 +0900 Subject: [PATCH 662/822] 0724 kihun --- 2023/07.24/Readme.md | 5 ++ ...\354\240\204\352\271\203\354\244\204.java" | 43 ++++++++++++++++ ...\353\254\264\354\204\234\354\233\214.java" | 50 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 2023/07.24/Readme.md create mode 100644 "2023/07.24/\354\206\241\352\270\260\355\233\210/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" create mode 100644 "2023/07.24/\354\206\241\352\270\260\355\233\210/\354\226\264\353\221\220\354\232\264\352\261\264\353\254\264\354\204\234\354\233\214.java" diff --git a/2023/07.24/Readme.md b/2023/07.24/Readme.md new file mode 100644 index 0000000..249be1e --- /dev/null +++ b/2023/07.24/Readme.md @@ -0,0 +1,5 @@ +# 7.24(목) 스터디 + +- 백준 + - [꼬인 전깃줄](https://www.acmicpc.net/problem/1365) + - [어두운 건 무서워](https://www.acmicpc.net/problem/16507) diff --git "a/2023/07.24/\354\206\241\352\270\260\355\233\210/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" "b/2023/07.24/\354\206\241\352\270\260\355\233\210/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" new file mode 100644 index 0000000..990da47 --- /dev/null +++ "b/2023/07.24/\354\206\241\352\270\260\355\233\210/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" @@ -0,0 +1,43 @@ +package baekjoon.gold.two; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 꼬인전깃줄 { + // 가장긴증가하는부분수열2 참고 + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + StringTokenizer st = new StringTokenizer(br.readLine()); + int[] line = new int[N]; + for (int i = 0; i < N; i++) { + line[i] = Integer.parseInt(st.nextToken()); + } + + ListLIS = new ArrayList<>(); + LIS.add(line[0]); + + for (int i = 1; i < N; i++) { + int value = line[i]; + + // LIS 마지막 원소보다 value가 크면 LIS에 추가 + if (value > LIS.get(LIS.size() - 1)) { + LIS.add(value); + } + // 아니라면 이분 탐색으로 위치 찾기 + else { + int pos = -Collections.binarySearch(LIS, value) - 1; + // Collections.binarySearch(List, key); + // 못 찾았을 경우엔 key가 있었을 경우 (-(삽입 위치) - 1)를 return + LIS.set(pos, value); + } + } + + System.out.println(N - LIS.size()); + + } +} diff --git "a/2023/07.24/\354\206\241\352\270\260\355\233\210/\354\226\264\353\221\220\354\232\264\352\261\264\353\254\264\354\204\234\354\233\214.java" "b/2023/07.24/\354\206\241\352\270\260\355\233\210/\354\226\264\353\221\220\354\232\264\352\261\264\353\254\264\354\204\234\354\233\214.java" new file mode 100644 index 0000000..4e2dff2 --- /dev/null +++ "b/2023/07.24/\354\206\241\352\270\260\355\233\210/\354\226\264\353\221\220\354\232\264\352\261\264\353\254\264\354\204\234\354\233\214.java" @@ -0,0 +1,50 @@ +package baekjoon.silver.one; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 어두운건무서워 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int R, C, Q; + static int[][] matrix; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + Q = Integer.parseInt(st.nextToken()); + + matrix = new int[R + 1][C + 1]; + + for (int r = 1; r <= R; r++) { + st = new StringTokenizer(br.readLine()); + int sum = 0; + + for (int c = 1; c <= C; c++) { + sum += Integer.parseInt(st.nextToken()); + matrix[r][c] = matrix[r - 1][c] + sum; + } + } + + for (int i = 0; i < Q; i++) { + st = new StringTokenizer(br.readLine()); + int r1 = Integer.parseInt(st.nextToken()); + int c1 = Integer.parseInt(st.nextToken()); + int r2 = Integer.parseInt(st.nextToken()); + int c2 = Integer.parseInt(st.nextToken()); + + int a = matrix[r2][c2] - matrix[r1 - 1][c2] - matrix[r2][c1 - 1] + matrix[r1 - 1][c1 - 1]; + int b = (r2 - r1 + 1) * (c2 - c1 + 1); + + System.out.println(a / b); + + + } + + } + +} \ No newline at end of file From d68f54cacd92ede1ce6002ff40d2b4bb4196e84f Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Tue, 25 Jul 2023 19:31:01 +0900 Subject: [PATCH 663/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20BOJ=209024=20Solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_9024.java" | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 "2023/07.27/\354\265\234\354\260\275\354\230\201/BOJ_9024.java" diff --git "a/2023/07.27/\354\265\234\354\260\275\354\230\201/BOJ_9024.java" "b/2023/07.27/\354\265\234\354\260\275\354\230\201/BOJ_9024.java" new file mode 100644 index 0000000..09d50bf --- /dev/null +++ "b/2023/07.27/\354\265\234\354\260\275\354\230\201/BOJ_9024.java" @@ -0,0 +1,109 @@ +package BOJ_9024; + +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + + +public class BOJ_9024 { + // input + private static BufferedReader br; + private static StringBuilder sb; + + // variables + private static int N = 0; + private static int K = 0; + private static int ans; + + private static int[] arr; + + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("C:\\Users\\bigyo\\Desktop\\Java Algorithm\\JavaAlgorithm\\src\\BOJ_9024\\res\\res.txt")); + br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + sb = new StringBuilder(); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + while (T-- > 0) { + input(); + + int minIndex = 0; + int maxIndex = N - 1; + solve2(minIndex, maxIndex, 0, Integer.MAX_VALUE); + sb.append(ans).append('\n'); + + //solve(); + } + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void solve() { + int count = 0; + int minIndex = 0; + int maxIndex = N - 1; + int ret = Integer.MAX_VALUE; + + while (minIndex < maxIndex) { + System.out.println("minIndex" + minIndex + ", maxIndex : " + maxIndex); + + int sum = arr[minIndex] + arr[maxIndex]; + int temp = Math.abs(K - sum); + + if (temp < ret) { + ret = temp; + count = 1; + } else if (temp == ret) { + count++; + } + + if (sum > K) { + maxIndex--; + } else { + minIndex++; + } + } + + sb.append(count).append('\n'); + } // End of solve + + private static void solve2(int lower, int upper, int sum, int ret) { + if (lower >= upper) { + return; + } + + sum = arr[lower] + arr[upper]; + int temp = Math.abs(K - sum); + + if (temp < ret) { + ret = temp; + ans = 1; + } else if (temp == ret) { + ans++; + } + + if (sum > K) { + solve2(lower, upper - 1, sum, ret); + } else { + solve2(lower + 1, upper, sum, ret); + } + } // End of solve2 + + private static void input() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + ans = 0; + + arr = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(arr); + } // End of input +} // End of BOJ_9024 class From 2fdec60d1ecf0745beac30687c51e31716bfd1a8 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 27 Jul 2023 09:39:50 +0900 Subject: [PATCH 664/822] 0727 kihun --- 2023/07.27/Readme.md | 5 + ...\354\210\230\354\235\230\355\225\251.java" | 51 ++++++++++ ...354\210\230\354\241\261\352\264\2001.java" | 99 +++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 2023/07.27/Readme.md create mode 100644 "2023/07.27/\354\206\241\352\270\260\355\233\210/\353\221\220\354\210\230\354\235\230\355\225\251.java" create mode 100644 "2023/07.27/\354\206\241\352\270\260\355\233\210/\354\210\230\354\241\261\352\264\2001.java" diff --git a/2023/07.27/Readme.md b/2023/07.27/Readme.md new file mode 100644 index 0000000..fac8f25 --- /dev/null +++ b/2023/07.27/Readme.md @@ -0,0 +1,5 @@ +# 7.27(목) 스터디 + +- 백준 + - [두 수의 합](https://www.acmicpc.net/problem/9024) + - [수족관 1](https://www.acmicpc.net/problem/8982) diff --git "a/2023/07.27/\354\206\241\352\270\260\355\233\210/\353\221\220\354\210\230\354\235\230\355\225\251.java" "b/2023/07.27/\354\206\241\352\270\260\355\233\210/\353\221\220\354\210\230\354\235\230\355\225\251.java" new file mode 100644 index 0000000..4e77122 --- /dev/null +++ "b/2023/07.27/\354\206\241\352\270\260\355\233\210/\353\221\220\354\210\230\354\235\230\355\225\251.java" @@ -0,0 +1,51 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 두수의합 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + + for (int t = 0; t < T; t++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + int[] numbers = new int[N]; + for (int i = 0; i < N; i++) { + numbers[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(numbers); + + int minDiff = Integer.MAX_VALUE; + int count = 0, start = 0, end = N - 1; + + while (start < end) { + int sum = numbers[start] + numbers[end]; + + if (minDiff == Math.abs(sum - K)) { + count += 1; + } else if (minDiff > Math.abs(sum - K)) { + minDiff = Math.abs(sum - K); + count = 1; + } + + if (sum >= K) { + end -= 1; + } else { + start += 1; + } + } + System.out.println(count); + } + + } + +} \ No newline at end of file diff --git "a/2023/07.27/\354\206\241\352\270\260\355\233\210/\354\210\230\354\241\261\352\264\2001.java" "b/2023/07.27/\354\206\241\352\270\260\355\233\210/\354\210\230\354\241\261\352\264\2001.java" new file mode 100644 index 0000000..a400241 --- /dev/null +++ "b/2023/07.27/\354\206\241\352\270\260\355\233\210/\354\210\230\354\241\261\352\264\2001.java" @@ -0,0 +1,99 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 수족관1 { + + static class Point { + int x, y; + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public String toString() { + return String.format("(%d, %d)", x, y); + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public static void main(String[] args) throws IOException { + int N = Integer.parseInt(br.readLine()); + + ArrayList points = new ArrayList<>(); + int width = 0; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + points.add(new Point(x, y)); + + if (width < x) { + width = x; + } + } + + + int[] aquarium = new int[width]; + int[] water = new int[width]; + for (int i = 1; i < N - 1; i += 2) { + Point p1 = points.get(i); + Point p2 = points.get(i + 1); + for (int j = p1.x; j < p2.x; j++) { + aquarium[j] = p1.y; + } + } + + int K = Integer.parseInt(br.readLine()); + Point[] holes = new Point[K]; + for (int k = 0; k < K; k++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + + holes[k] = new Point(x1, y1); + } + + // 구멍 뚫기 + for (int k = 0; k < K; k++) { + Point p = holes[k]; + + // 왼쪽 + int index = p.x; + int depth = p.y; + + while (index >= 0) { + depth = Math.min(depth, aquarium[index]); + water[index] = Math.max(depth, water[index]); + index -= 1; + } + + // 오른쪽 + index = p.x; + depth = p.y; + + while (index < width) { + depth = Math.min(depth, aquarium[index]); + water[index] = Math.max(depth, water[index]); + index += 1; + } + + + } + + int sum = 0; + for (int i = 0; i < width; i++) { + sum += aquarium[i] - water[i]; + } + System.out.println(sum); + } +} From 442b4a51fe45e2a435ab3af40cce80ebde840f1b Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:32:26 +0900 Subject: [PATCH 665/822] =?UTF-8?q?Create=20=EB=91=90=EC=88=98=EC=9D=98?= =?UTF-8?q?=ED=95=A9.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\354\235\230\355\225\251.java" | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 "2023/07.27/\354\240\225\355\230\270\354\241\260/\353\221\220\354\210\230\354\235\230\355\225\251.java" diff --git "a/2023/07.27/\354\240\225\355\230\270\354\241\260/\353\221\220\354\210\230\354\235\230\355\225\251.java" "b/2023/07.27/\354\240\225\355\230\270\354\241\260/\353\221\220\354\210\230\354\235\230\355\225\251.java" new file mode 100644 index 0000000..4b7a8ce --- /dev/null +++ "b/2023/07.27/\354\240\225\355\230\270\354\241\260/\353\221\220\354\210\230\354\235\230\355\225\251.java" @@ -0,0 +1,96 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 두수의합_9024 { + static int N, K, ans; + static int[] num; + static Map check; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + ans = 0; + num = new int[N]; + check = new HashMap<>(); + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + num[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(num); + + int start = 0; + int end = N - 1; + int dif = Integer.MAX_VALUE; + while (start < end){ + int sum = num[start] + num[end]; + int curDif = Math.abs(K - sum); + if(dif >= curDif){ + if(dif > curDif) ans = 0; + dif = curDif; + ans++; + } + if(sum >= K){ + end--; + } else { + start++; + } + } + + System.out.println(ans); + + /**시간 초과*/ +// int dif = Integer.MAX_VALUE; +// +// for (int i = 0; i < num.length; i++) { +//// System.out.println(Arrays.toString(Arrays.stream(num).toArray())); +//// System.out.println("i : " + i); +// int idx = Arrays.binarySearch(num, K - num[i]); +// if (idx < 0) { +// idx = -idx - 1; +// } +// if (idx >= num.length) { +// idx = num.length - 1; +// } +// if (idx > 0 && Math.abs(K - (num[idx] + num[i])) > Math.abs(K - (num[idx - 1] + num[i]))) { +// idx = idx - 1; +// } +// +// if (i == idx) { +//// System.out.println("i == idx"); +// continue; +// } +// if (check.containsKey(num[idx]) && check.containsValue(num[i])) continue; +// +//// System.out.println("num[i] " + num[i] + " idx : " + idx + ", num[idx] : " + num[idx] + " , 합 : " + (num[i] + num[idx])); +// int curDif = Math.abs(K - (num[i] + num[idx])); +//// System.out.println("curDif : " + curDif); +// +// +// if (dif > curDif) { +//// System.out.println("dif 초기화, ans == 1"); +// dif = curDif; +// ans = 0; +// ans++; +// check.put(num[i], num[idx]); +// } else if (dif == curDif) { +// ans++; +//// System.out.println("ans ++ : " + ans); +// check.put(num[i], num[idx]); +// } +//// System.out.println(); +// } +// +// System.out.println(ans); + } + } +} From 7737b3f503dc9e035c0eb5b2d5c527fab0ba12d2 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:32:54 +0900 Subject: [PATCH 666/822] =?UTF-8?q?Create=20=EC=88=98=EC=A1=B1=EA=B4=80.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\354\241\261\352\264\200.java" | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 "2023/07.27/\354\240\225\355\230\270\354\241\260/\354\210\230\354\241\261\352\264\200.java" diff --git "a/2023/07.27/\354\240\225\355\230\270\354\241\260/\354\210\230\354\241\261\352\264\200.java" "b/2023/07.27/\354\240\225\355\230\270\354\241\260/\354\210\230\354\241\261\352\264\200.java" new file mode 100644 index 0000000..f885f9a --- /dev/null +++ "b/2023/07.27/\354\240\225\355\230\270\354\241\260/\354\210\230\354\241\261\352\264\200.java" @@ -0,0 +1,96 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class 수족관1_8982 { + static int N, K, ans; + static int[] box, hole, water; + static ArrayList list; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + list = new ArrayList<>(); + int len = 0; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + + int c = Integer.parseInt(st.nextToken()); + int r = Integer.parseInt(st.nextToken()); + len = Math.max(len, c); + + list.add(new Node(r, c)); + } + + box = new int[len]; + water = new int[len]; + + int cnt = 0; + + for (int i = 1; i < list.size() - 1; i += 2) { + int c1 = list.get(i).c; + int c2 = list.get(i + 1).c; + for (int j = c1; j < c2; j++) { + box[cnt] = list.get(i).r; + cnt++; + } + } + + K = Integer.parseInt(br.readLine()); + hole = new int[K]; + + for(int i=0; i=0; j--){ + if(curH < box[j]){ + water[j] = Math.max(water[j], curH); + } else { + curH = box[j]; + water[j] = Math.max(water[j], curH); + } + } + } + + for(int i=0; i Date: Mon, 31 Jul 2023 13:08:29 +0900 Subject: [PATCH 667/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20BOJ=207579=20Solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BOJ_7579_\354\225\261.java" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "2023/07.31/\354\265\234\354\260\275\354\230\201/BOJ_7579_\354\225\261.java" diff --git "a/2023/07.31/\354\265\234\354\260\275\354\230\201/BOJ_7579_\354\225\261.java" "b/2023/07.31/\354\265\234\354\260\275\354\230\201/BOJ_7579_\354\225\261.java" new file mode 100644 index 0000000..45195f2 --- /dev/null +++ "b/2023/07.31/\354\265\234\354\260\275\354\230\201/BOJ_7579_\354\225\261.java" @@ -0,0 +1,83 @@ +package BOJ_7579; + +import java.io.*; +import java.util.StringTokenizer; + +/* + + 몇 개를 비활성화 홰서 M 바이트 이상의 메모리를 추가로 확보해야 한다. + 비활성화 했을 경우의 합을 최소화하여라. + + + */ + +public class BOJ_7579_앱 { + // input + private static BufferedReader br; + private static StringBuilder sb; + + // variables + private static int N, M, ans; + private static int[] aliveApps; + private static int[] costs; + + private static Integer[][] memo = new Integer[101][10_001]; // [N+1][M+1] + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("C:\\Users\\bigyo\\Desktop\\Java Algorithm\\JavaAlgorithm\\src\\BOJ_7579\\res.txt")); + br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + sb = new StringBuilder(); + + input(); + + solve(); + + bw.write(sb.toString()); + bw.close(); + } // End of main + + private static void solve() { + DFS(0, aliveApps[0], costs[0]); + DFS(0, 0, 0); + sb.append(ans); + } // End of solve + + private static void DFS(int index, int volume, int cost) { + System.out.println("DFS(" + index + ", " + volume + ", " + cost + ")"); + + if (volume >= M) { + ans = Math.min(ans, cost); + } + + if (memo[index][cost] != null && memo[index][cost] >= volume) { + return; + } + + memo[index][cost] = volume; + + if (index + 1 < N) { + DFS(index + 1, volume + aliveApps[index + 1], cost + costs[index + 1]); + DFS(index + 1, volume, cost); + } + } // End of DFS + + private static void input() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + ans = Integer.MAX_VALUE; + + aliveApps = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + aliveApps[i] = Integer.parseInt(st.nextToken()); + } + + costs = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + costs[i] = Integer.parseInt(st.nextToken()); + } + } // End of input +} // End of Main class From 48195bc5a63bdd1556c682f896738c1f9abe797f Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 31 Jul 2023 13:36:55 +0900 Subject: [PATCH 668/822] 0731 kihun --- 2023/07.31/Readme.md | 5 + .../\354\225\261.java" | 57 +++++++++ .../\354\266\225\352\265\254.java" | 108 ++++++++++++++++++ .../\354\266\225\352\265\254_DP.java" | 73 ++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 2023/07.31/Readme.md create mode 100644 "2023/07.31/\354\206\241\352\270\260\355\233\210/\354\225\261.java" create mode 100644 "2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" create mode 100644 "2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254_DP.java" diff --git a/2023/07.31/Readme.md b/2023/07.31/Readme.md new file mode 100644 index 0000000..e87b4d1 --- /dev/null +++ b/2023/07.31/Readme.md @@ -0,0 +1,5 @@ +# 7.27(목) 스터디 + +- 백준 + - [앱](https://www.acmicpc.net/problem/7579) + - [축구](https://www.acmicpc.net/problem/1344) diff --git "a/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\225\261.java" "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\225\261.java" new file mode 100644 index 0000000..643ad62 --- /dev/null +++ "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\225\261.java" @@ -0,0 +1,57 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 앱 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M; + static int[] memories, costs; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); // 확보해야 하는 메모리 + + StringTokenizer memoryTokenizer = new StringTokenizer(br.readLine()); + StringTokenizer costTokenizer = new StringTokenizer(br.readLine()); + + int totalCost = 0; + memories = new int[N+1]; + costs = new int[N+1]; + for (int i = 1; i <= N; i++) { + int memory = Integer.parseInt(memoryTokenizer.nextToken()); + int cost = Integer.parseInt(costTokenizer.nextToken()); + + totalCost += cost; + memories[i] = memory; + costs[i] = cost; + } + + int[][] dp = new int[N + 1][totalCost + 1]; + for (int i = 1; i <= N; i++) { + int memory = memories[i]; + int cost = costs[i]; + + for (int now = 0; now <= totalCost; now++) { + if (now >= cost) { + dp[i][now] = Math.max(dp[i - 1][now], dp[i - 1][now - cost] + memory); + } else { + dp[i][now] = dp[i - 1][now]; + } + } + } + + for (int i = 0; i <= totalCost; i++) { + if (dp[N][i] >= M) { + System.out.println(i); + break; + } + } + + } + +} \ No newline at end of file diff --git "a/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" new file mode 100644 index 0000000..cd51e62 --- /dev/null +++ "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" @@ -0,0 +1,108 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class 축구 { + // 적어도 한 팀이 골을 소수로 득점할 확률을 그냥 구하자 + // 18세트 + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int A = Integer.parseInt(br.readLine()); + int B = Integer.parseInt(br.readLine()); + + int N = 18; + long[] factorials = new long[N + 1]; + for (int i = 0; i <= N; i++) { + factorials[i] = factorial(i); + } + + int[] goalList = {2, 3, 5, 7, 11, 13, 17}; + long[] combi = new long[goalList.length]; + + for (int i = 0; i < goalList.length; i++) { + int goal = goalList[i]; + combi[i] = factorials[18] / factorials[goal] / factorials[18 - goal]; + } + + double goalA = A / 100.0; + double noGoalA = 1.0 - goalA; + double goalB = B / 100.0; + double noGoalB = 1.0 - goalB; + + double pA = 0.0; + double pB = 0.0; + for (int i = 0; i < goalList.length; i++) { + // 확률 = p^goal * (1-p)^nogoal * combi + pA += Math.pow(goalA, goalList[i]) * Math.pow(noGoalA, (N - goalList[i])) * combi[i]; + pB += Math.pow(goalB, goalList[i]) * Math.pow(noGoalB, (N - goalList[i])) * combi[i]; + } + + System.out.println(pA + pB - pA * pB); + } + + static long factorial(long a) { + if (a == 0) { + return 1; + } + long result = 1; + for (long i = 1; i <= a; i++) { + result *= i; + } + return result; + } +} + +// 오차가 크다 +/* +public class 축구 { + // 적어도 한 팀이 골을 소수로 득점할 확률 = 1 - 두 팀 모두 소수로 득점 못할 확률 + // 18세트 + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int A = Integer.parseInt(br.readLine()); + int B = Integer.parseInt(br.readLine()); + + long[] factorials = new long[19]; + for (int i = 0; i < 19; i++) { + factorials[i] = factorial(i); + } + + int[] goalList = {0, 1, 6, 8, 9, 10, 12, 14, 15, 16, 18}; + long[] combi = new long[goalList.length]; + + for (int i = 0; i < goalList.length; i++) { + int goal = goalList[i]; + combi[i] = factorials[18] / factorials[goal] / factorials[18 - goal]; + } + + double goalA = (double) A / 100; + double noGoalA = 1.0 - goalA; + double goalB = (double) B / 100; + double noGoalB = 1.0 - goalB; + + double pA = 0.0; + double pB = 0.0; + for (int i = 0; i < goalList.length; i++) { + // 확률 = p^goal * (1-p)^nogoal * combi + pA += Math.pow(goalA, goalList[i]) * Math.pow(noGoalA, (18 - goalList[i])) * combi[i]; + pB += Math.pow(goalB, goalList[i]) * Math.pow(noGoalB, (18 - goalList[i])) * combi[i]; + } + + System.out.println(1 - pA * pB); + } + + static long factorial(long a) { + if (a == 0) { + return 1; + } + long result = 1; + for (long i = 1; i <= a; i++) { + result *= i; + } + return result; + } +} +*/ \ No newline at end of file diff --git "a/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254_DP.java" "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254_DP.java" new file mode 100644 index 0000000..6c477ec --- /dev/null +++ "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254_DP.java" @@ -0,0 +1,73 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 축구_DP { + // RGB거리 참고 + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int A = Integer.parseInt(br.readLine()); + int B = Integer.parseInt(br.readLine()); + int N = 19; + + double[][][] dp = new double[N][N][N]; + + double goalA = A / 100.0; + double noGoalA = 1.0 - goalA; + double goalB = B / 100.0; + double noGoalB = 1.0 - goalB; + + dp[0][0][0] = 1.0; + + for (int i = 1; i < N; i++) { + for (int a = 0; a <= i; a++) { + for (int b = 0; b <= i; b++) { + + if (a > 0) { + dp[i][a][b] += dp[i - 1][a - 1][b] * goalA * noGoalB; + } + + if (b > 0) { + dp[i][a][b] += dp[i - 1][a][b - 1] * goalB * noGoalA; + } + + if (a > 0 && b > 0) { + dp[i][a][b] += dp[i - 1][a - 1][b - 1] * goalA * goalB; + } + + dp[i][a][b] += dp[i - 1][a][b] * noGoalA * noGoalB; + + } + + } + + } + + double p = 0.0; + for (int a = 0; a < N; a++) { + for (int b = 0; b < N; b++) { + if (isPrime(a) || isPrime(b)) { + p += dp[N - 1][a][b]; + } + } + } + + System.out.println(p); + + } + + static boolean isPrime(int n) { + if (n < 2) return false; + for (int i = 2; i * i <= n; i++) { + if (n % i == 0) { + return false; + } + } + return true; + } + + +} From d5b4d31d429715839c56d3585623028405d0e5c1 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Tue, 1 Aug 2023 10:14:50 +0900 Subject: [PATCH 669/822] =?UTF-8?q?Update=20=EC=B6=95=EA=B5=AC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\266\225\352\265\254.java" | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git "a/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" index cd51e62..1d913af 100644 --- "a/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" +++ "b/2023/07.31/\354\206\241\352\270\260\355\233\210/\354\266\225\352\265\254.java" @@ -55,7 +55,6 @@ static long factorial(long a) { } } -// 오차가 크다 /* public class 축구 { // 적어도 한 팀이 골을 소수로 득점할 확률 = 1 - 두 팀 모두 소수로 득점 못할 확률 @@ -70,7 +69,7 @@ public static void main(String[] args) throws IOException { factorials[i] = factorial(i); } - int[] goalList = {0, 1, 6, 8, 9, 10, 12, 14, 15, 16, 18}; + int[] goalList = {0, 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18}; long[] combi = new long[goalList.length]; for (int i = 0; i < goalList.length; i++) { @@ -105,4 +104,4 @@ static long factorial(long a) { return result; } } -*/ \ No newline at end of file +*/ From 2d376e4a8e7a0184189cc86a4ef08810515ef26f Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 1 Aug 2023 10:58:41 +0900 Subject: [PATCH 670/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=9E=A0?= =?UTF-8?q?=EC=88=98=ED=95=A8=EC=8B=9D=EB=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...30\355\225\250\354\213\235\353\263\204.kt" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "2023/08.03/\354\241\260\354\210\230\354\227\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.kt" diff --git "a/2023/08.03/\354\241\260\354\210\230\354\227\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.kt" "b/2023/08.03/\354\241\260\354\210\230\354\227\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.kt" new file mode 100644 index 0000000..e7710ad --- /dev/null +++ "b/2023/08.03/\354\241\260\354\210\230\354\227\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.kt" @@ -0,0 +1,45 @@ +import java.io.* + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val str = readLine() + + bw.write("${check(str)}") + + bw.flush() + bw.close() +} + +fun check(str: String): String { + var i = 0 + + while (i < str.length) { + // 0으로 시작하는 패턴 다음에 무조건 1이 나온다. + if (str[i] == '0') { + if (i + 1 >= str.length) return "NOISE" + if (str[i + 1] != '1') return "NOISE" + i += 2 + } else { // 1로 시작하는 패턴 뒤에 00이 무조건 나온다. + if (i + 3 >= str.length) return "NOISE" + if (str[i + 1] != '0' || str[i + 2] != '0') return "NOISE" + i += 3 + + while (i < str.length && str[i] == '0'){ // 100~ 뒤에 0이 1개이상 나온다. + i++ + } + + // 0으로 이어지다가 뒤에 1이 안나온 경우 100~1 + if (i >= str.length) return "NOISE" + i++ + + // 1~ 이어지는 경우 i + 1과 i + 2가 00이면 100~패턴이므로 종료 아니면 계속 이동 + while (i < str.length && str[i] == '1'){ + if (i + 2 < str.length && str[i+1] == '0' && str[i+2] == '0') break + i++ + } + } + } + return "SUBMARINE" +} \ No newline at end of file From 720ebeaf86bbf043196b9c0cf246baa168637523 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 1 Aug 2023 12:52:49 +0900 Subject: [PATCH 671/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=97=AC?= =?UTF-8?q?=EC=99=95=EB=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\227\254\354\231\225\353\262\214.kt" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "2023/08.03/\354\241\260\354\210\230\354\227\260/\354\227\254\354\231\225\353\262\214.kt" diff --git "a/2023/08.03/\354\241\260\354\210\230\354\227\260/\354\227\254\354\231\225\353\262\214.kt" "b/2023/08.03/\354\241\260\354\210\230\354\227\260/\354\227\254\354\231\225\353\262\214.kt" new file mode 100644 index 0000000..5ee7f88 --- /dev/null +++ "b/2023/08.03/\354\241\260\354\210\230\354\227\260/\354\227\254\354\231\225\353\262\214.kt" @@ -0,0 +1,71 @@ +import java.io.* +import java.util.* +import kotlin.math.max + +lateinit var hive: Array + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (m, n) = readLine().trim().split(" ").map { it.toInt() } + + hive = Array(m) { IntArray(m)} + + var st: StringTokenizer + + repeat(n) { + st = StringTokenizer(readLine()) + val zero = st.nextToken().toInt() + val one = st.nextToken().toInt() + val two = st.nextToken().toInt() + + growFirst(zero, one, two, m) + } + + growSecond(m) + + val sb = StringBuilder() + + for (i in 0 until m) { + for (j in 0 until m) { + sb.append("${hive[i][j] + 1} ") + } + sb.append("\n") + } + + bw.write("$sb") + + bw.flush() + bw.close() +} + +fun growFirst(zero: Int, one: Int, two: Int, m: Int) { + var x = 0 + var y = m - 1 + + repeat(zero) { + if (y > 0) y-- + else x++ + } + + repeat(one) { + hive[y][x] += 1 + if (y > 0) y-- + else x++ + } + + repeat(two) { + hive[y][x] += 2 + if (y > 0) y-- + else x++ + } +} + +fun growSecond(m: Int) { + for (i in 1 until m) { + for (j in 1 until m) { + hive[i][j] = max(hive[i][j - 1], max(hive[i - 1][j - 1], hive[i - 1][j])) + } + } +} \ No newline at end of file From 2796d3930bd3ae976ffc62a13f38d0ebbeb1a83f Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:21:57 +0900 Subject: [PATCH 672/822] =?UTF-8?q?Create=20=EC=97=AC=EC=99=95=EB=B2=8C.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\227\254\354\231\225\353\262\214.java" | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 "2023/08.03/\354\240\225\355\230\270\354\241\260/\354\227\254\354\231\225\353\262\214.java" diff --git "a/2023/08.03/\354\240\225\355\230\270\354\241\260/\354\227\254\354\231\225\353\262\214.java" "b/2023/08.03/\354\240\225\355\230\270\354\241\260/\354\227\254\354\231\225\353\262\214.java" new file mode 100644 index 0000000..74928b4 --- /dev/null +++ "b/2023/08.03/\354\240\225\355\230\270\354\241\260/\354\227\254\354\231\225\353\262\214.java" @@ -0,0 +1,125 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** + * 처음 애벌래는 0열 아래에서 위로, 0행 왼쪽에서 오른쪽으로 성장함 + * 그 이후 (1,1) 부터 (M-1 , M-1)의 애벌래들은 자신의 좌, 좌상, 상의 애벌래 성장량만 확인 + * 0열, 0행에 주어지는 성장량은 0, 1, 2가 순차적으로 주어지므로 성장량을 배열에 담는다면 배열의 뒤로 갈 수록 값이 커짐 + * 즉 (M-1, 0)의 성장량이 (0, M-1)의 성장량 보다 큰 경우의 수는 없음(같을 수는 있음) + * 따라서 나머지 애벌래들이 체크해야하는 애벌래는 좌, 좌상, 상 중 상에 위치한 애벌래만 체크하면 됨(최초 애벌래가 성장할 때 방향이 (M-1, 0)에서 시작하여 (0, M-1)에서 끝나므로) + * 주어진 성장량을 0열과 0행에 한 번에 성장시킨 후 나머지 애벌래는 각 열의 0번째 행 값을 복사 + * */ +public class 여왕벌_10836 { + static int M, N; + static int[][] growth, larva; + static int[] curGrowth; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + growth = new int[N][3]; + larva = new int[M][M]; + curGrowth = new int[2 * M - 1]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + growth[i][j] = Integer.parseInt(st.nextToken()); + } + } + + getResult(); + + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) { + System.out.print(larva[i][j] + " "); + } + System.out.println(); + } + + } + + static void getResult() { + + //애벌래 1로 초기화 + for (int i = 0; i < M; i++) { + Arrays.fill(larva[i], 1); + } + + //0열, 0행을 모든 날짜에 대해 성장시킴 + for (int day = 0; day < N; day++) { +// makeCurGrowth(day); //현재 날짜의 성장량을 배열에 담아줌 + initGrowLarva(day); //0열, 0행을 성장시킴 + } + + growLarva(); //나머지 성장시킴 + } + + static void makeCurGrowth(int day) { + int idx = 0; + Arrays.fill(curGrowth, 0); + for (int i = 0; i < 3; i++) { + if (growth[day][i] == 0) continue; + + switch (i) { + case 0: { + curGrowth[idx] = 0; + break; + } + case 1: { + curGrowth[idx] = 1; + break; + } + case 2: { + curGrowth[idx] = 2; + break; + } + } + + growth[day][i]--; + i--; + idx++; + } + } + + static void initGrowLarva(int day) { + int r = M - 1; + int c = 0; + + while (r != 0 || c != M) { + int value = 0; + if(growth[day][0] > 0){ + growth[day][0]--; + } else if(growth[day][1] > 0) { + value = 1; + growth[day][1]--; + } else { + value = 2; + growth[day][2]--; + } + + larva[r][c] = larva[r][c] + value; + + if (r != 0) { + r--; + } else { + c++; + } + } + } + + static void growLarva() { + for (int i = 1; i < M; i++) { + int value = larva[0][i]; + for (int j = 1; j < M; j++) { + larva[j][i] = value; + } + } + } +} From 1e2a0149a68048dc907cc95e4b979db763b8d043 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:22:24 +0900 Subject: [PATCH 673/822] =?UTF-8?q?Create=20=EC=9E=A0=EC=88=98=ED=95=A8?= =?UTF-8?q?=EC=8B=9D=EB=B3=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\250\354\213\235\353\263\204.java" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "2023/08.03/\354\240\225\355\230\270\354\241\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" diff --git "a/2023/08.03/\354\240\225\355\230\270\354\241\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" "b/2023/08.03/\354\240\225\355\230\270\354\241\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" new file mode 100644 index 0000000..a2c15e0 --- /dev/null +++ "b/2023/08.03/\354\240\225\355\230\270\354\241\260/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" @@ -0,0 +1,46 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 잠수함식별_2671 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String str = br.readLine(); + String ans = "SUBMARINE"; + + int cnt = 0; + + if(str.length() == 3 || str.charAt(str.length() - 1) == '0'){ //조합해봤을 때 문자열의 길이가 3이거나 마지막 문자열이 0인 경우의 수는 없음 + ans = "NOISE"; + System.out.println(ans); + } else { + while (cnt < str.length()) { + if (str.substring(cnt, Math.min(cnt + 2, str.length())).equals("01")) { //01은 연속할 수 있는 경우가 없으므로 바로 자름 + cnt += 2; + } else if (str.substring(cnt, Math.min(cnt + 3, str.length())).equals("100")) { //100은 뒤에 0이 연속할 수도 있고 1이 연속할 수 도 있으므로 체크 + cnt +=3; + while (cnt < str.length() && str.charAt(cnt) == '0'){ + cnt++; + } + while (cnt < str.length() && str.charAt(cnt) == '1'){ + cnt++; + } + } else if(cnt > 2 && str.substring(cnt - 1, Math.min(cnt + 2, str.length())).equals("100") && str.charAt(cnt - 2) == '1'){ //100110011001 + cnt += 2; + while (cnt < str.length() && str.charAt(cnt) == '0'){ + cnt++; + } + while (cnt < str.length() && str.charAt(cnt) == '1'){ + cnt++; + } + }else { + ans = "NOISE"; + break; + } + } + + System.out.println(ans); + } + + } +} From 6c9e4dff1a2b940dbc2c61bc8ee1954b143481fd Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:23:32 +0900 Subject: [PATCH 674/822] =?UTF-8?q?Create=20=EC=95=B1.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\225\261.java" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "2023/07.31/\354\240\225\355\230\270\354\241\260/\354\225\261.java" diff --git "a/2023/07.31/\354\240\225\355\230\270\354\241\260/\354\225\261.java" "b/2023/07.31/\354\240\225\355\230\270\354\241\260/\354\225\261.java" new file mode 100644 index 0000000..5da074e --- /dev/null +++ "b/2023/07.31/\354\240\225\355\230\270\354\241\260/\354\225\261.java" @@ -0,0 +1,47 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/** + * 최소 비용으로 최대 메모리를 확보해야함 + */ +public class 앱_7579 { + static int N, M, ans; + static int[] memory, cost; + static int[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + dp = new int[N + 1][10001]; + memory = new int[N + 1]; + cost = new int[N + 1]; + ans = Integer.MAX_VALUE; + + int sum = 0; + StringTokenizer stM = new StringTokenizer(br.readLine()); + StringTokenizer stC = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + memory[i] = Integer.parseInt(stM.nextToken()); + cost[i] = Integer.parseInt(stC.nextToken()); + sum += cost[i]; + } + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= sum; j++) { //비용 + if (cost[i] > j) { + dp[i][j] = dp[i - 1][j]; + } else { + dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - cost[i]] + memory[i]); + } + + if (dp[i][j] >= M) ans = Math.min(ans, j); + } + } + System.out.println(ans); + } +} From 7f3ee6a7adb985cb7a7cc036a4ca74a4ce6b9c9f Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:24:28 +0900 Subject: [PATCH 675/822] =?UTF-8?q?Create=20=EA=BC=AC=EC=9D=B8=EC=A0=84?= =?UTF-8?q?=EA=B9=83=EC=A4=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\240\204\352\271\203\354\244\204.java" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "2023/07.24/\354\240\225\355\230\270\354\241\260/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" diff --git "a/2023/07.24/\354\240\225\355\230\270\354\241\260/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" "b/2023/07.24/\354\240\225\355\230\270\354\241\260/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" new file mode 100644 index 0000000..f9527af --- /dev/null +++ "b/2023/07.24/\354\240\225\355\230\270\354\241\260/\352\274\254\354\235\270\354\240\204\352\271\203\354\244\204.java" @@ -0,0 +1,41 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + +public class 꼬인전깃줄_1365 { + static int[] wire; + static ArrayList list; + static int N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + st = new StringTokenizer(br.readLine()); + + wire = new int[N]; + list = new ArrayList<>(); + + for (int i = 0; i < N; i++) { + wire[i] = Integer.parseInt(st.nextToken()); + } + list.add(wire[0]); + + for (int i = 1; i < N; i++) { + int next = wire[i]; + if (list.get(list.size() - 1) < next) { + list.add(next); + } else { + int temp = Collections.binarySearch(list, next); + int index = temp >= 0 ? temp : -temp - 1; + list.set(index, next); + } + } + + System.out.println(N - list.size()); + } +} From c53b793ffc61846a8024b93743dd2085e8032262 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 3 Aug 2023 10:00:24 +0900 Subject: [PATCH 676/822] 0803 kihun --- 2023/08.03/Readme.md | 5 ++ ...\354\227\254\354\231\225\353\262\214.java" | 88 +++++++++++++++++++ ...\355\225\250\354\213\235\353\263\204.java" | 24 +++++ 3 files changed, 117 insertions(+) create mode 100644 2023/08.03/Readme.md create mode 100644 "2023/08.03/\354\206\241\352\270\260\355\233\210/\354\227\254\354\231\225\353\262\214.java" create mode 100644 "2023/08.03/\354\206\241\352\270\260\355\233\210/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" diff --git a/2023/08.03/Readme.md b/2023/08.03/Readme.md new file mode 100644 index 0000000..2e45292 --- /dev/null +++ b/2023/08.03/Readme.md @@ -0,0 +1,5 @@ +# 8.3(목) 스터디 + +- 백준 + - [잠수함식별](https://www.acmicpc.net/problem/2671) + - [여왕벌](https://www.acmicpc.net/problem/10836) diff --git "a/2023/08.03/\354\206\241\352\270\260\355\233\210/\354\227\254\354\231\225\353\262\214.java" "b/2023/08.03/\354\206\241\352\270\260\355\233\210/\354\227\254\354\231\225\353\262\214.java" new file mode 100644 index 0000000..a05db24 --- /dev/null +++ "b/2023/08.03/\354\206\241\352\270\260\355\233\210/\354\227\254\354\231\225\353\262\214.java" @@ -0,0 +1,88 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 여왕벌 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int M, N; + static int[][] matrix; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + + matrix = new int[M][M]; + for (int[] m: matrix) { + Arrays.fill(m, 1); + } + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + cornerGrow(a, b, c); + } + + // 코너를 제외하고는 윗칸의 것을 따라가면 됨 + StringBuilder sb = new StringBuilder(); + for (int y = 0; y < M; y++) { + for (int x = 0; x < M; x++) { + if (y == 0) { + sb.append(matrix[y][x]).append(" "); + } else if (x == 0) { + sb.append(matrix[y][x]).append(" "); + } else { + sb.append(matrix[0][x]).append(" "); + } + } + sb.append("\n"); + } + System.out.println(sb); + + } + + static void cornerGrow(int a, int b, int c) { + int y = M - 1; + int x = 0; + // 0 성장 + while (a > 0) { + if (y != 0) { + y -= 1; + } else { + x += 1; + } + a -= 1; + } + // 1 성장 + while (b > 0) { + matrix[y][x] += 1; + + if (y != 0) { + y -= 1; + } else { + x += 1; + } + b -= 1; + } + // 2 성장 + while (c > 0) { + matrix[y][x] += 2; + + if (y != 0) { + y -= 1; + } else { + x += 1; + } + c -= 1; + } + } + +} \ No newline at end of file diff --git "a/2023/08.03/\354\206\241\352\270\260\355\233\210/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" "b/2023/08.03/\354\206\241\352\270\260\355\233\210/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" new file mode 100644 index 0000000..26c6636 --- /dev/null +++ "b/2023/08.03/\354\206\241\352\270\260\355\233\210/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" @@ -0,0 +1,24 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 잠수함식별 { + + // 우리가 식별하고자 하는 잠수함의 엔진소리의 패턴은 다음과 같다. + // (100~1~|01)~ + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String regex = "(100+1+|01)+"; + + String inputString = br.readLine(); + + if (inputString.matches(regex)) { + System.out.println("SUBMARINE"); + } else { + System.out.println("NOISE"); + } + } +} From 47da963e70beab88dcdd6f61db9f52b66bf411f9 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 3 Aug 2023 13:43:43 +0900 Subject: [PATCH 677/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=201=ED=95=99?= =?UTF-8?q?=EB=85=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1\355\225\231\353\205\204.kt" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "2023/08.07/\354\241\260\354\210\230\354\227\260/1\355\225\231\353\205\204.kt" diff --git "a/2023/08.07/\354\241\260\354\210\230\354\227\260/1\355\225\231\353\205\204.kt" "b/2023/08.07/\354\241\260\354\210\230\354\227\260/1\355\225\231\353\205\204.kt" new file mode 100644 index 0000000..303a775 --- /dev/null +++ "b/2023/08.07/\354\241\260\354\210\230\354\227\260/1\355\225\231\353\205\204.kt" @@ -0,0 +1,45 @@ +import java.io.* +import java.util.* + +lateinit var st: StringTokenizer + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + val dp = Array(n) { LongArray(21) } + val numArr = IntArray(n) + + st = StringTokenizer(readLine()) + + repeat(n) { + numArr[it] = st.nextToken().toInt() + } + + dp[0][numArr[0]] = 1 // 초깃값 + + var plus = 0 + var minus = 0 + + for (i in 1 until n - 1) { // 등호(=)를 제외하고 덧셈과 뺄셈의 횟수는 n-2번 + for (j in 0..20) { + if (dp[i - 1][j] != 0L) { // 계산하기 전의 값 + plus = j + numArr[i] + minus = j - numArr[i] + + if (plus in 0..20) { + dp[i][plus] += dp[i - 1][j] + } + + if (minus in 0..20) { + dp[i][minus] += dp[i - 1][j] + } + } + } + } + + bw.write("${dp[n - 2][numArr[n - 1]]}") + + bw.flush() + bw.close() +} \ No newline at end of file From f43670a9bb2c855a476e6d0ca25fba27daed4d1d Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 3 Aug 2023 17:15:53 +0900 Subject: [PATCH 678/822] =?UTF-8?q?Create=201=ED=95=99=EB=85=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1\355\225\231\353\205\204.java" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "2023/08.07/\354\240\225\355\230\270\354\241\260/1\355\225\231\353\205\204.java" diff --git "a/2023/08.07/\354\240\225\355\230\270\354\241\260/1\355\225\231\353\205\204.java" "b/2023/08.07/\354\240\225\355\230\270\354\241\260/1\355\225\231\353\205\204.java" new file mode 100644 index 0000000..d84d97f --- /dev/null +++ "b/2023/08.07/\354\240\225\355\230\270\354\241\260/1\355\225\231\353\205\204.java" @@ -0,0 +1,42 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 일학년_5557 { + static long[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + dp = new long[N][21]; + int[] num = new int[N]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + num[i] = Integer.parseInt(st.nextToken()); + } + + dp[0][num[0]] = 1; + + for (int i = 0; i < N - 1; i++) { + for (int j = 0; j <= 20; j++) { + if (dp[i][j] != 0) { + int dif = j - num[i + 1]; + int sum = j + num[i + 1]; + + if (0 <= dif && dif <= 20) dp[i + 1][dif] += dp[i][j]; + if (0 <= sum && sum <= 20) dp[i + 1][sum] += dp[i][j]; + } + } + } + +// for (int i = 0; i < N; i++) { +// System.out.println(Arrays.toString(Arrays.stream(dp[i]).toArray())); +// } + + System.out.println(dp[N - 2][num[N - 1]]); + } +} From 80216651a9b910b90c4fcd7d9e4eb315d1ce8d60 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 3 Aug 2023 21:08:47 +0900 Subject: [PATCH 679/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EC=BB=B5?= =?UTF-8?q?=EB=9D=BC=EB=A9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\273\265\353\235\274\353\251\264.kt" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "2023/08.07/\354\241\260\354\210\230\354\227\260/\354\273\265\353\235\274\353\251\264.kt" diff --git "a/2023/08.07/\354\241\260\354\210\230\354\227\260/\354\273\265\353\235\274\353\251\264.kt" "b/2023/08.07/\354\241\260\354\210\230\354\227\260/\354\273\265\353\235\274\353\251\264.kt" new file mode 100644 index 0000000..14fb52f --- /dev/null +++ "b/2023/08.07/\354\241\260\354\210\230\354\227\260/\354\273\265\353\235\274\353\251\264.kt" @@ -0,0 +1,37 @@ +import java.io.* +import java.util.* + +lateinit var st: StringTokenizer + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + val pq = PriorityQueue(compareBy> { it.first }.thenByDescending { it.second }) + + repeat(n) { + st = StringTokenizer(readLine()) + pq.add(Pair(st.nextToken().toInt(), st.nextToken().toInt())) + } + + val resultPq = PriorityQueue() // 라면 갯수가 적은 순으로 정렬 + for (i in 1..n) { + val problem = pq.poll() + resultPq.add(problem.second) + + if (problem.first < resultPq.size){ // 해당 데드라인에 문제가 여러개일 경우 갯수가 가장 높은 라면만 남기고 poll + resultPq.poll() + } + } + + var answer = 0 + + while (resultPq.isNotEmpty()){ + answer += resultPq.poll() + } + + bw.write("$answer") + + bw.flush() + bw.close() +} \ No newline at end of file From e0132af8fde378350a676479cfe378bc3d24ac3f Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 3 Aug 2023 22:06:13 +0900 Subject: [PATCH 680/822] =?UTF-8?q?Create=20=EC=BB=B5=EB=9D=BC=EB=A9=B4.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\273\265\353\235\274\353\251\264.java" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "2023/08.07/\354\240\225\355\230\270\354\241\260/\354\273\265\353\235\274\353\251\264.java" diff --git "a/2023/08.07/\354\240\225\355\230\270\354\241\260/\354\273\265\353\235\274\353\251\264.java" "b/2023/08.07/\354\240\225\355\230\270\354\241\260/\354\273\265\353\235\274\353\251\264.java" new file mode 100644 index 0000000..fc88345 --- /dev/null +++ "b/2023/08.07/\354\240\225\355\230\270\354\241\260/\354\273\265\353\235\274\353\251\264.java" @@ -0,0 +1,57 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class 컵라면_1781 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + PriorityQueue homework = new PriorityQueue<>((o1, o2) ->{ + if(o1.deadLine == o2.deadLine){ + return o2.ramen - o1.ramen; + } else { + return o1.deadLine - o2.deadLine; + } + }); + PriorityQueue result = new PriorityQueue<>(); + + + for(int i=0; i Date: Fri, 4 Aug 2023 11:06:48 +0900 Subject: [PATCH 681/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EA=B5=AC?= =?UTF-8?q?=EC=8A=AC=20=ED=83=88=EC=B6=9C=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\212\254_\355\203\210\354\266\234_3.kt" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "2023/08.07/\354\241\260\354\210\230\354\227\260/\352\265\254\354\212\254_\355\203\210\354\266\234_3.kt" diff --git "a/2023/08.07/\354\241\260\354\210\230\354\227\260/\352\265\254\354\212\254_\355\203\210\354\266\234_3.kt" "b/2023/08.07/\354\241\260\354\210\230\354\227\260/\352\265\254\354\212\254_\355\203\210\354\266\234_3.kt" new file mode 100644 index 0000000..91f36a2 --- /dev/null +++ "b/2023/08.07/\354\241\260\354\210\230\354\227\260/\352\265\254\354\212\254_\355\203\210\354\266\234_3.kt" @@ -0,0 +1,120 @@ +import java.awt.Point +import java.io.* +import java.util.* +import kotlin.math.abs + +lateinit var board: Array +lateinit var visited: Array>> +var sequence = "" +val dir = arrayOf(intArrayOf(-1, 0), intArrayOf(1, 0), intArrayOf(0, -1), intArrayOf(0, 1)) + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (n, m) = readLine().trim().split(" ").map { it.toInt() } + board = Array(n) { CharArray(m) } + visited = Array(n) { Array(m) { Array(n) { BooleanArray(m) } } } + val red = Point() + val blue = Point() + + repeat(n) { i -> + val info = readLine() + repeat(m) { j -> + board[i][j] = info[j] + if (board[i][j] == 'R') { + red.x = j + red.y = i + } else if (board[i][j] == 'B') { + blue.x = j + blue.y = i + } + } + } + + val cnt = bfs(red, blue) + bw.write("$cnt\n$sequence") + + bw.flush() + bw.close() +} + +fun bfs(red: Point, blue: Point): Int { + val q: Queue>> = LinkedList() + val direction = charArrayOf('U','D','L','R') + + visited[red.y][red.x][blue.y][blue.x] = true + q.add(Triple(red, blue, Pair(0, ""))) + + while (q.isNotEmpty()) { + + val info = q.poll() + val r = info.first + val b = info.second + val s = info.third + + if (s.first > 10) return -1 + + if (board[b.y][b.x] == 'O') continue // 파란 공이 구멍에 빠지면 안된다. + + if (board[r.y][r.x] == 'O' && board[b.y][b.x] != 'O') { // 빨간 공만 구멍에 빠졌을 경우 종료 + sequence = s.second + return s.first + } + + for (i in 0 until 4) { + var nrx = r.x + var nry = r.y + + while (true) { + if (nrx + dir[i][1] >= 0 && nry + dir[i][0] >= 0) { + nrx += dir[i][1] + nry += dir[i][0] + + if (board[nry][nrx] == '#' || board[nry][nrx] == 'O') break + } + } + + if (board[nry][nrx] == '#') { + nrx -= dir[i][1] + nry -= dir[i][0] + } + + var nbx = b.x + var nby = b.y + + while (true) { + if (nbx + dir[i][1] >= 0 && nby + dir[i][0] >= 0) { + nbx += dir[i][1] + nby += dir[i][0] + + if (board[nby][nbx] == '#' || board[nby][nbx] == 'O') break + } + } + + if (board[nby][nbx] == '#') { + nbx -= dir[i][1] + nby -= dir[i][0] + } + + if (nry == nby && nrx == nbx && board[nry][nrx] != 'O') { // 같은 위치인 경우 + val rDis = abs(nry - r.y) + abs(nrx - r.x) + val bDis = abs(nby - b.y) + abs(nbx - b.x) + + if (rDis > bDis) { // 파란 공은 못 움직이는 상황에서 빨간 공이랑 만난 상황 + nrx -= dir[i][1] + nry -= dir[i][0] + } else { + nbx -= dir[i][1] + nby -= dir[i][0] + } + } + + // 두 공이 이전의 위치와 같은지 체크 + if (!visited[nry][nrx][nby][nbx]) { + visited[nry][nrx][nby][nbx] = true + q.add(Triple(Point(nrx, nry), Point(nbx, nby), Pair(s.first + 1, s.second + direction[i]))) + } + } + } + return -1 +} \ No newline at end of file From 2a65cf90b6ce451f68ec24d67750ead545b86704 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Sun, 6 Aug 2023 15:55:47 +0900 Subject: [PATCH 682/822] =?UTF-8?q?=EC=BB=B5=EB=9D=BC=EB=A9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\273\265\353\235\274\353\251\264" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "2023/08.07/\352\271\200\354\247\200\355\233\210/\354\273\265\353\235\274\353\251\264" diff --git "a/2023/08.07/\352\271\200\354\247\200\355\233\210/\354\273\265\353\235\274\353\251\264" "b/2023/08.07/\352\271\200\354\247\200\355\233\210/\354\273\265\353\235\274\353\251\264" new file mode 100644 index 0000000..940ee72 --- /dev/null +++ "b/2023/08.07/\352\271\200\354\247\200\355\233\210/\354\273\265\353\235\274\353\251\264" @@ -0,0 +1,60 @@ +import java.util.*; +import java.io.*; + + +class Main { + + static class Problem implements Comparable{ + int deadline; + int ramen; + + public Problem(int deadline,int ramen){ + this.deadline = deadline; + this.ramen = ramen; + } + + @Override + public int compareTo(Problem o) { + if(this.deadline==o.deadline) return this.ramen-this.ramen; + else return this.deadline-o.deadline; + } + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + PriorityQueue pq = new PriorityQueue<>(); + PriorityQueue mins = new PriorityQueue<>(); + int N = Integer.parseInt(br.readLine()); + StringTokenizer st; + + for(int i=0;i Date: Mon, 7 Aug 2023 14:57:06 +0900 Subject: [PATCH 683/822] =?UTF-8?q?1=ED=95=99=EB=85=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1\355\225\231\353\205\204" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "2023/08.07/\352\271\200\354\247\200\355\233\210/1\355\225\231\353\205\204" diff --git "a/2023/08.07/\352\271\200\354\247\200\355\233\210/1\355\225\231\353\205\204" "b/2023/08.07/\352\271\200\354\247\200\355\233\210/1\355\225\231\353\205\204" new file mode 100644 index 0000000..613672f --- /dev/null +++ "b/2023/08.07/\352\271\200\354\247\200\355\233\210/1\355\225\231\353\205\204" @@ -0,0 +1,38 @@ +import java.util.*; +import java.io.*; + + +class Main { + + + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + + int[] nums = new int[N]; + long[][] dp = new long[N-1][21]; //0 ~ 20 + StringTokenizer st = new StringTokenizer(br.readLine()); + + for(int i=0;i0){ //이전값들 중 0~20사이 값이 있는경우 + if(j+nums[i]>=0&&j+nums[i]<=20){ //더했을떄 0~20 경우 + dp[i][j+nums[i]]+=dp[i-1][j]; + } + if(j-nums[i]>=0&&j-nums[i]<=20) { //뻇을떄 0~20 + dp[i][j-nums[i]]+=dp[i-1][j]; + } + } + } + } + System.out.println(dp[dp.length-1][nums[nums.length-1]]); + } + +} From 97f8ad46212720fe81275e4be09348c372218636 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 7 Aug 2023 23:04:06 +0900 Subject: [PATCH 684/822] 0807 kihun --- 2023/08.07/Readme.md | 6 + ...354\212\254\355\203\210\354\266\2343.java" | 171 ++++++++++++++++++ ...235\274\355\225\231\353\205\204_5557.java" | 51 ++++++ ...\354\273\265\353\235\274\353\251\264.java" | 170 +++++++++++++++++ 4 files changed, 398 insertions(+) create mode 100644 2023/08.07/Readme.md create mode 100644 "2023/08.07/\354\206\241\352\270\260\355\233\210/\352\265\254\354\212\254\355\203\210\354\266\2343.java" create mode 100644 "2023/08.07/\354\206\241\352\270\260\355\233\210/\354\235\274\355\225\231\353\205\204_5557.java" create mode 100644 "2023/08.07/\354\206\241\352\270\260\355\233\210/\354\273\265\353\235\274\353\251\264.java" diff --git a/2023/08.07/Readme.md b/2023/08.07/Readme.md new file mode 100644 index 0000000..8097b40 --- /dev/null +++ b/2023/08.07/Readme.md @@ -0,0 +1,6 @@ +# 8.7(월) 스터디 + +- 백준 + - [구슬탈출3](https://www.acmicpc.net/problem/15644) + - [컵라면](https://www.acmicpc.net/problem/1781) + - [1학년](https://www.acmicpc.net/problem/5557) diff --git "a/2023/08.07/\354\206\241\352\270\260\355\233\210/\352\265\254\354\212\254\355\203\210\354\266\2343.java" "b/2023/08.07/\354\206\241\352\270\260\355\233\210/\352\265\254\354\212\254\355\203\210\354\266\2343.java" new file mode 100644 index 0000000..83f8a4c --- /dev/null +++ "b/2023/08.07/\354\206\241\352\270\260\355\233\210/\352\265\254\354\212\254\355\203\210\354\266\2343.java" @@ -0,0 +1,171 @@ +package baekjoon.gold.one; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Objects; +import java.util.Queue; +import java.util.StringTokenizer; + +public class 구슬탈출3 { + + static class Point { + int rY, rX; + int bY, bX; + int depth; + String dir; + + public Point(int rY, int rX, int bY, int bX, int depth, String dir) { + this.rY = rY; + this.rX = rX; + this.bY = bY; + this.bX = bX; + this.depth = depth; + this.dir = dir; + } + + } + + static int N, M; + static int rY, rX; + static int bY, bX; + static int hY, hX; + static char[][] matrix; + + // 하 우 상 좌 + static int[] dY = {1, 0, -1, 0}; + static int[] dX = {0, 1, 0, -1}; + static String[] dir = {"D", "R", "U", "L"}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + matrix = new char[N][M]; + for (int i = 0; i < N; i++) { + String inputString = br.readLine(); + for (int j = 0; j < M; j++) { + char temp = inputString.charAt(j); + + if (temp == 'R') { + rY = i; + rX = j; + } else if (temp == 'B') { + bY = i; + bX = j; + } else if (temp == 'O') { + hY = i; + hX = j; + } + + matrix[i][j] = temp; + } + } + + bfs(new Point(rY, rX, bY, bX, 0, "")); + + } + + static void bfs(Point point) { + Queue queue = new LinkedList<>(); + queue.offer(point); + boolean[][][][] visited = new boolean[N][M][N][M]; + visited[point.rY][point.rX][point.bY][point.bX] = true; + + while (!queue.isEmpty()) { + Point p = queue.poll(); + + // 10 넘어가면 -1 출력 + if (p.depth > 10) { + System.out.println(-1); + return; + } + + // 파란 구슬이 빠지면 안됨 + if (matrix[p.bY][p.bX] == 'O') { + continue; + } + + // 빨간 구슬이 O, 파란 구슬이 O가 아니면 성공 + if (matrix[p.rY][p.rX] == 'O' && matrix[p.bY][p.bX] != 'O') { + System.out.println(p.depth); + System.out.println(p.dir); + return; + } + + for (int i = 0; i < 4; i++) { + int rY = p.rY; + int rX = p.rX; + + // 빨간 구슬을 한 쪽 방향으로 이동 + while (true) { + if (rY + dY[i] >= 0 && rX + dX[i] >= 0) { + rY += dY[i]; + rX += dX[i]; + + // 벽에 닿았을 경우 한 칸 빼주자 + if (matrix[rY][rX] == '#') { + rY -= dY[i]; + rX -= dX[i]; + break; + } + + // O에 도착 + if (matrix[rY][rX] == 'O') { + break; + } + } + } + + int bY = p.bY; + int bX = p.bX; + + // 파란 구슬을 한 쪽 방향으로 이동 + while (true) { + if (bY + dY[i] >= 0 && bX + dX[i] >= 0) { + bY += dY[i]; + bX += dX[i]; + + // 벽에 닿았을 경우 한 칸 빼주자 + if (matrix[bY][bX] == '#') { + bY -= dY[i]; + bX -= dX[i]; + break; + } + + // O에 도착 + if (matrix[bY][bX] == 'O') { + break; + } + } + } + + // 빨간 구슬, 파란 구슬이 같은 곳이면? + // #...RB# --L--> #RB...# + if (rY == bY && rX == bX && matrix[rY][rX] != 'O') { + int rDiff = Math.abs(rY - p.rY) + Math.abs(rX - p.rX); + int bDiff = Math.abs(bY - p.bY) + Math.abs(bX - p.bX); + + // 벽으로부터 더 먼 것을 한 칸 빼준다 + if (rDiff > bDiff) { + rY -= dY[i]; + rX -= dX[i]; + } else { + bY -= dY[i]; + bX -= dX[i]; + } + } + + if (!visited[rY][rX][bY][bX]) { + visited[rY][rX][bY][bX] = true; + queue.offer(new Point(rY, rX, bY, bX, p.depth + 1, p.dir + dir[i])); + } + } + } + System.out.println(-1); + } + +} diff --git "a/2023/08.07/\354\206\241\352\270\260\355\233\210/\354\235\274\355\225\231\353\205\204_5557.java" "b/2023/08.07/\354\206\241\352\270\260\355\233\210/\354\235\274\355\225\231\353\205\204_5557.java" new file mode 100644 index 0000000..bb5df7c --- /dev/null +++ "b/2023/08.07/\354\206\241\352\270\260\355\233\210/\354\235\274\355\225\231\353\205\204_5557.java" @@ -0,0 +1,51 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 일학년_5557 { + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + StringTokenizer st = new StringTokenizer(br.readLine()); + + int[] numbers = new int[N + 1]; + for (int i = 1; i <= N; i++) { + int temp = Integer.parseInt(st.nextToken()); + numbers[i] = temp; + } + + // 상근이는 0 이상 20 이하의 수만 안다 + // long으로 해야 안 터짐 + // y단계 연산 시 x값의 수 + long[][] dp = new long[N][21]; + + dp[1][numbers[1]] = 1; + + for (int y = 2; y < N; y++) { + for (int x = 0; x <= 20; x++) { + // 이전 단계에 경우의 수가 있다면? + if (dp[y - 1][x] != 0) { + int plus = x + numbers[y]; + int minus = x - numbers[y]; + + if (plus >= 0 && plus <= 20) { + dp[y][plus] += dp[y - 1][x]; + } + + if (minus >= 0 && minus <= 20) { + dp[y][minus] += dp[y - 1][x]; + } + } + } + } + + System.out.println(dp[N-1][numbers[N]]); + + } +} diff --git "a/2023/08.07/\354\206\241\352\270\260\355\233\210/\354\273\265\353\235\274\353\251\264.java" "b/2023/08.07/\354\206\241\352\270\260\355\233\210/\354\273\265\353\235\274\353\251\264.java" new file mode 100644 index 0000000..23d1595 --- /dev/null +++ "b/2023/08.07/\354\206\241\352\270\260\355\233\210/\354\273\265\353\235\274\353\251\264.java" @@ -0,0 +1,170 @@ +package baekjoon.gold.two; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 컵라면 { + + static class Homework implements Comparable { + int deadline; + int cupRamen; + + public Homework(int deadline, int cupRamen) { + this.deadline = deadline; + this.cupRamen = cupRamen; + } + + @Override + public int compareTo(Object o) { + Homework h = (Homework) o; + if (this.deadline == h.deadline) { + return h.cupRamen - this.cupRamen; + } + + return this.deadline - h.deadline; + } + + @Override + public String toString() { + return String.format("(%d,%d)", this.deadline, this.cupRamen); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + List homeworkList = new ArrayList<>(); + + StringTokenizer st; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int deadline = Integer.parseInt(st.nextToken()); + int cupRamen = Integer.parseInt(st.nextToken()); + homeworkList.add(new Homework(deadline, cupRamen)); + } + + homeworkList.sort(Homework::compareTo); + + for (Homework h : homeworkList) { + System.out.println(h); + } + + Queue pq = new PriorityQueue<>(); + for (int i = 0; i < N; i++) { + Homework hw = homeworkList.get(i); + pq.add(hw.cupRamen); + + if (hw.deadline < pq.size()) { + pq.poll(); + } + // ex) hw.deadline이 2인데 pq.size가 5다? + // hw.deadline을 오름차순 정렬했으므로 현재는 2초라고 생각해야 됨 + // 따라서 최대 2문제까지만 소화 가능하므로 poll해서 맞춰줘야 함 + } + System.out.println(pq); + + int sum = 0; + while (!pq.isEmpty()) { + int cupRamen = pq.poll(); + sum += cupRamen; + } + System.out.println(sum); + } + +} + +//public class 컵라면 { +// +// static class Homework implements Comparable{ +// int deadline; +// int cupRamen; +// +// public Homework(int deadline, int cupRamen) { +// this.deadline = deadline; +// this.cupRamen = cupRamen; +// } +// +// @Override +// public int compareTo(Homework o) { +// if (this.cupRamen == o.cupRamen) { +// return this.deadline - o.deadline; +// } +// +// return o.cupRamen - this.cupRamen; +// } +// +// @Override +// public String toString() { +// return String.format("(%d,%d)", this.deadline, this.cupRamen); +// } +// } +// +// public static void main(String[] args) throws IOException { +// // maxDeadline의 수만큼 고를 수 있음 +// // Deadline이 5인 원소는 5개 고를 수 있고 2인 원소는 2개 고를 수 있음 +// +// BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); +// +// int N = Integer.parseInt(br.readLine()); +// +// List homeworkList = new ArrayList<>(); +// +// StringTokenizer st; +// +// int maxDeadline = -1; +// TreeMap countMap = new TreeMap<>(); +// +// for (int i = 0; i < N; i++) { +// st = new StringTokenizer(br.readLine()); +// int deadline = Integer.parseInt(st.nextToken()); +// int cupRamen = Integer.parseInt(st.nextToken()); +// homeworkList.add(new Homework(deadline, cupRamen)); +// maxDeadline = Math.max(maxDeadline, deadline); +// if (!countMap.containsKey(deadline)) { +// countMap.put(deadline, 0); +// } +// } +// +// // 단, maxDeadline은 주어진 deadline N보다 작거나 같아야 함 +// maxDeadline = Math.min(maxDeadline, N); +// +// homeworkList.sort(Homework::compareTo); +// +// int count = 0; +// int sum = 0; +// for (Homework h : homeworkList) { +// // 이미 maxDeadline만큼 골랐으면 끝 +// if (count == maxDeadline) { +// break; +// } +// +// // maxDeadline보다 크거나 count 보다 작아도 안 됨 +// // count초만큼 흘렀으니까 이미 deadline이 지난 문제 +// if (h.deadline > maxDeadline) { +// continue; +// } +// +// // 해당 deadline을 이미 deadline 수만큼 골랐으면 패스 +// if (countMap.get(h.deadline) == h.deadline) { +// continue; +// } +// +// count += 1; +// sum += h.cupRamen; +// countMap.put(h.deadline, countMap.get(h.deadline) + 1); +// +// System.out.println(countMap); +// System.out.println(count); +// System.out.println(h); +// } +// +// System.out.println(sum); +// +// } +// +//} \ No newline at end of file From 959f25cd16c7d01183509c6c7e155a5a38d3160e Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 8 Aug 2023 12:16:07 +0900 Subject: [PATCH 685/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=ED=9A=8C?= =?UTF-8?q?=EC=9E=A5=EB=BD=91=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14\354\236\245\353\275\221\352\270\260.kt" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "2023/08.10/\354\241\260\354\210\230\354\227\260/\355\232\214\354\236\245\353\275\221\352\270\260.kt" diff --git "a/2023/08.10/\354\241\260\354\210\230\354\227\260/\355\232\214\354\236\245\353\275\221\352\270\260.kt" "b/2023/08.10/\354\241\260\354\210\230\354\227\260/\355\232\214\354\236\245\353\275\221\352\270\260.kt" new file mode 100644 index 0000000..dff5433 --- /dev/null +++ "b/2023/08.10/\354\241\260\354\210\230\354\227\260/\355\232\214\354\236\245\353\275\221\352\270\260.kt" @@ -0,0 +1,58 @@ +import java.io.* +import java.util.* +import kotlin.math.max +import kotlin.math.min + +lateinit var st: StringTokenizer + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + val relation = Array(n + 1) { IntArray(n + 1) { 50 } } + val scorePq = Array(50){ PriorityQueue() } + + repeat(n){ relation[it+1][it+1] = 0 } + + while (true) { + st = StringTokenizer(readLine()) + val s = st.nextToken().toInt() + val e = st.nextToken().toInt() + + if (s == -1 && e == -1) break + + relation[s][e] = 1 + relation[e][s] = 1 + } + + // 플로이드-워셜 + for (k in 1..n) { + for (i in 1..n) { + for (j in 1..n) { + if (relation[i][k] + relation[k][j] < relation[i][j]) { + relation[i][j] = relation[i][k] + relation[k][j] + } + } + } + } + + var minScore = 50 + + for (i in 1..n){ + var maxScore = 0 + for (j in 1..n){ + maxScore = max(maxScore, relation[i][j]) + } + scorePq[maxScore].add(i) + minScore = min(minScore,maxScore) + } + + bw.write("$minScore ${scorePq[minScore].size}\n") + + while (scorePq[minScore].isNotEmpty()){ + bw.write("${scorePq[minScore].poll()} ") + } + + bw.flush() + bw.close() +} \ No newline at end of file From b38dd74bc774353308bca354eb8e3dcf52888cb3 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 8 Aug 2023 14:00:02 +0900 Subject: [PATCH 686/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EC=B0=BD?= =?UTF-8?q?=EC=98=81=EC=9D=B4=EC=99=80=20=ED=87=B4=EA=B7=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\231\200_\355\207\264\352\267\274.kt" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "2023/08.10/\354\241\260\354\210\230\354\227\260/\354\260\275\354\230\201\354\235\264\354\231\200_\355\207\264\352\267\274.kt" diff --git "a/2023/08.10/\354\241\260\354\210\230\354\227\260/\354\260\275\354\230\201\354\235\264\354\231\200_\355\207\264\352\267\274.kt" "b/2023/08.10/\354\241\260\354\210\230\354\227\260/\354\260\275\354\230\201\354\235\264\354\231\200_\355\207\264\352\267\274.kt" new file mode 100644 index 0000000..8d3b76f --- /dev/null +++ "b/2023/08.10/\354\241\260\354\210\230\354\227\260/\354\260\275\354\230\201\354\235\264\354\231\200_\355\207\264\352\267\274.kt" @@ -0,0 +1,74 @@ +import java.awt.Point +import java.io.* +import java.util.* +import kotlin.math.* + +lateinit var st: StringTokenizer +lateinit var road: Array +val dir = arrayOf(intArrayOf(-1, 0), intArrayOf(1, 0), intArrayOf(0, -1), intArrayOf(0, 1)) + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + + if (n == 1) bw.write("0") + else { + road = Array(n) { IntArray(n) } + + var maxH = 0 + var minH = Integer.MAX_VALUE + + repeat(n) { i -> + st = StringTokenizer(readLine()) + repeat(n) { j -> + road[i][j] = st.nextToken().toInt() + maxH = max(maxH, road[i][j]) + minH = min(minH, road[i][j]) + } + } + + // 이분 탐색 (조건을 만족하면서 가장 높은 경사로 구하기) + var minGrad = 0 + var maxGrad = maxH - minH + + while (minGrad <= maxGrad) { + val midGrad = (minGrad + maxGrad) / 2 + + if (dijkstra(n, midGrad)) maxGrad = midGrad - 1 + else minGrad = midGrad + 1 + } + + bw.write("$minGrad") + } + + bw.flush() + bw.close() +} + +fun dijkstra(n: Int, baseGrad: Int): Boolean { + val q: Queue = LinkedList() + val visited = Array(n) { BooleanArray(n) } + + q.add(Point(0, 0)) + visited[0][0] = true + + while (q.isNotEmpty()) { + val cur = q.poll() + + if (cur.x == n - 1 && cur.y == n - 1) return true + + for (i in 0 until 4) { + val nx = cur.x + dir[i][1] + val ny = cur.y + dir[i][0] + + if (nx in 0 until n && ny in 0 until n && !visited[ny][nx]) { + if (abs(road[ny][nx] - road[cur.y][cur.x]) <= baseGrad) { + visited[ny][nx] = true + q.add(Point(nx, ny)) + } + } + } + } + return false +} \ No newline at end of file From 104cd2f677f39740ab890df9539e4d09bac1522c Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:03:48 +0900 Subject: [PATCH 687/822] =?UTF-8?q?=ED=9A=8C=EC=9E=A5=EB=BD=91=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\214\354\236\245\353\275\221\352\270\260" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "2023/08.10/\352\271\200\354\247\200\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260" diff --git "a/2023/08.10/\352\271\200\354\247\200\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260" "b/2023/08.10/\352\271\200\354\247\200\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260" new file mode 100644 index 0000000..fce61cd --- /dev/null +++ "b/2023/08.10/\352\271\200\354\247\200\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260" @@ -0,0 +1,83 @@ +import java.io.*; +import java.util.*; + + +class Main{ + static class Node{ + int v; + int cost; + + public Node(int v, int cost) { + this.v = v; + this.cost = cost; + } + } + static int N; + static ArrayList[] graph; + static boolean[] visited; + static int[] dist; + static int[] scores; + static ArrayList candidates; + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + N = Integer.parseInt(br.readLine()); + + graph = new ArrayList[N+1]; + + scores = new int[N]; + candidates = new ArrayList<>(); + for(int i=0;i(); + } + + while(true){ + st = new StringTokenizer(br.readLine()); + int n1 = Integer.parseInt(st.nextToken()); + int n2 = Integer.parseInt(st.nextToken()); + if(n1==-1&&n2==-1) break; + graph[n1].add(new Node(n2,0)); + graph[n2].add(new Node(n1,0)); + } + + for(int i=1;i<=N;i++){ + visited = new boolean[N+1]; + dist = new int[N+1]; + Arrays.fill(dist,Integer.MAX_VALUE); + scores[i-1]= dijkstra(i); + } + int min = Integer.MAX_VALUE; + for(int i=0;i pq = new PriorityQueue<>(((o1, o2) -> o1.cost-o2.cost)); + pq.offer(new Node(start,0)); + dist[start] = 0; + while(!pq.isEmpty()){ + Node now = pq.poll(); + + if(!visited[now.v]) visited[now.v] = true; + + for(Node next : graph[now.v]){ + if(!visited[next.v]&&dist[next.v]>dist[now.v]+next.cost){ + dist[next.v] = now.cost+1; + pq.offer(new Node(next.v,dist[next.v])); + } + } + + } + int max = Integer.MIN_VALUE; + for(int i=1;i<=N;i++) { + if(dist[i]!=Integer.MAX_VALUE) + max = Math.max(max,dist[i]); + } + return max; + } +} From 221860a1979c845e62cca84bbe8560ff34b2083a Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Tue, 8 Aug 2023 23:35:46 +0900 Subject: [PATCH 688/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=EC=9D=B4=EC=99=80=20?= =?UTF-8?q?=EB=9D=BC=EB=A9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\264\354\231\200 \353\235\274\353\251\264" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "2023/08.10/\352\271\200\354\247\200\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200 \353\235\274\353\251\264" diff --git "a/2023/08.10/\352\271\200\354\247\200\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200 \353\235\274\353\251\264" "b/2023/08.10/\352\271\200\354\247\200\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200 \353\235\274\353\251\264" new file mode 100644 index 0000000..c961fb3 --- /dev/null +++ "b/2023/08.10/\352\271\200\354\247\200\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200 \353\235\274\353\251\264" @@ -0,0 +1,73 @@ +import java.io.*; +import java.util.*; + + +class Main{ + + static class Node{ + int x; + int y; + int cost; + + public Node(int x,int y,int cost){ + this.x = x; + this.y = y; + this.cost = cost; + } + + + } + static int[][] map; + static boolean[][] visited; + static int[][] dist; + static int N; + static int[] dx={-1,0,1,0}; + static int[] dy={0,1,0,-1}; + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + N = Integer.parseInt(br.readLine()); + + map = new int[N][N]; + visited = new boolean[N][N]; + dist = new int[N][N]; + for(int i=0;i q = new PriorityQueue<>(((o1, o2) -> o1.cost-o2.cost)); + q.offer(new Node(0,0,0)); + dist[0][0] = 0; + while(!q.isEmpty()){ + Node now = q.poll(); + + visited[now.x][now.y] = true; + for(int i=0;i<4;i++){ + int nx = now.x+dx[i]; + int ny = now.y+dy[i]; + if(isRange(nx,ny)){ + int calc = Math.max(now.cost,Math.abs(map[nx][ny]-map[now.x][now.y])); + if(!visited[nx][ny]&&dist[nx][ny]>calc){ + dist[nx][ny] =calc ; + q.offer(new Node(nx,ny,calc)); + } + } + } + + } + } + static boolean isRange(int x,int y){ + if(x>=0&&y>=0&&x Date: Wed, 9 Aug 2023 14:27:52 +0900 Subject: [PATCH 689/822] =?UTF-8?q?Create=20=EC=B0=BD=EC=98=81=EC=9D=B4?= =?UTF-8?q?=EC=99=80=EC=B6=9C=EA=B7=BC.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\231\200\354\266\234\352\267\274.java" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "2023/08.10/\354\240\225\355\230\270\354\241\260/\354\260\275\354\230\201\354\235\264\354\231\200\354\266\234\352\267\274.java" diff --git "a/2023/08.10/\354\240\225\355\230\270\354\241\260/\354\260\275\354\230\201\354\235\264\354\231\200\354\266\234\352\267\274.java" "b/2023/08.10/\354\240\225\355\230\270\354\241\260/\354\260\275\354\230\201\354\235\264\354\231\200\354\266\234\352\267\274.java" new file mode 100644 index 0000000..c7550db --- /dev/null +++ "b/2023/08.10/\354\240\225\355\230\270\354\241\260/\354\260\275\354\230\201\354\235\264\354\231\200\354\266\234\352\267\274.java" @@ -0,0 +1,91 @@ +import jdk.internal.util.xml.impl.Input; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +/** + * 최대 경사의 최솟값 -> 이분탐색 문제 + * 입력 시 경사의 최댓값과 최솟값을 저장한 후 이분탐색 시작 + * 탐색 시 mid값만큼의 차이를 허용하는지 안하는지 확인 + * 탐색 완료 후 최솟값(left) 출력 + * */ +public class 창영이와퇴근_22116 { + static int[] dr = {-1, 0, 1, 0}; + static int[] dc = {0, 1, 0, -1}; + static int N; + static int[][] map; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + map = new int[N][N]; + + int min = Integer.MAX_VALUE; + int max = 0; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + + min = Math.min(min, map[i][j]); + max = Math.max(max, map[i][j]); + } + } + + int left = 0; + int right = max - min; + + while (left <= right) { + int mid = (left + right) / 2; + + if (checkCase(mid)) { + right = mid - 1; + } else { + left = mid + 1; + } + } + + System.out.println(left); + } + + static boolean checkCase(int value) { + Queue queue = new LinkedList<>(); + boolean[][] vis = new boolean[N][N]; + boolean check = false; + queue.add(new Point(0, 0)); + vis[0][0] = true; + + while (!queue.isEmpty()) { + Point cur = queue.poll(); + if (cur.r == N - 1 && cur.c == N - 1) { + check = true; + break; + } + + for (int i = 0; i < 4; i++) { + int rr = cur.r + dr[i]; + int cc = cur.c + dc[i]; + + if (rr < 0 || rr >= N || cc < 0 || cc >= N || vis[rr][cc] || Math.abs(map[cur.r][cur.c] - map[rr][cc]) > value) continue; + + vis[rr][cc] = true; + queue.add(new Point(rr, cc)); + } + } + + return check; + } + + static class Point { + int r, c; + + public Point(int r, int c) { + this.r = r; + this.c = c; + } + } +} From 5992b13e1a9315f16c1e24e36da325d8837a5bd6 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:00:02 +0900 Subject: [PATCH 690/822] =?UTF-8?q?Create=20=ED=9A=8C=EC=9E=A5=EB=BD=91?= =?UTF-8?q?=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\236\245\353\275\221\352\270\260.java" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "2023/08.10/\354\240\225\355\230\270\354\241\260/\355\232\214\354\236\245\353\275\221\352\270\260.java" diff --git "a/2023/08.10/\354\240\225\355\230\270\354\241\260/\355\232\214\354\236\245\353\275\221\352\270\260.java" "b/2023/08.10/\354\240\225\355\230\270\354\241\260/\355\232\214\354\236\245\353\275\221\352\270\260.java" new file mode 100644 index 0000000..b9d03e8 --- /dev/null +++ "b/2023/08.10/\354\240\225\355\230\270\354\241\260/\355\232\214\354\236\245\353\275\221\352\270\260.java" @@ -0,0 +1,71 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +/** + * 플로이드와샬 문제 + * floyd 배열에 관계를 입력하고, 경유지에 따른 최소 거리를 갱신 + * 각 행의 최댓값이 해당 사람의 점수이고, 최저 점수를 보유한 사람들이 회장이 될 수 있음 + */ +public class 회장뽑기_2660 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int MAX = 1_000_000; + int N = Integer.parseInt(br.readLine()); + int[][] floyd = new int[N][N]; + for (int i = 0; i < N; i++) { + Arrays.fill(floyd[i], MAX); + } + + while (true) { + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()) - 1; + int b = Integer.parseInt(st.nextToken()) - 1; + + if (a == -2 && b == -2) break; + + floyd[a][b] = 1; + floyd[b][a] = 1; + } + + for (int k = 0; k < N; k++) { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (i != j && floyd[i][j] > floyd[i][k] + floyd[k][j]) { + floyd[i][j] = floyd[i][k] + floyd[k][j]; + } + } + } + } + + int[] score = new int[N]; //각 행의 최댓값(해당 사람의 점수)을 저장할 배열 + int min = Integer.MAX_VALUE; //회장 자격이 되는 사람의 점수 + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (floyd[i][j] != MAX) { + score[i] = Math.max(score[i], floyd[i][j]); + } + } + min = Math.min(score[i], min); + } + + ArrayList captain = new ArrayList<>(); + for (int i = 0; i < N; i++) { + if (score[i] == min) { + captain.add(i + 1); + } + } + + Collections.sort(captain); + + System.out.println(min + " " + captain.size()); + for(int i : captain){ + System.out.print(i + " "); + } + } +} From d88aae8036e77c1f8f5f2286982cc4d3c24006a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=89=E1=85=AE=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Thu, 10 Aug 2023 00:01:14 +0900 Subject: [PATCH 691/822] =?UTF-8?q?0727=20=EC=88=98=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\354\235\230\355\225\251.java" | 55 +++++++++++++ ...354\210\230\354\241\261\352\264\2001.java" | 78 +++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 "2023/07.27/\354\235\264\354\210\230\354\232\251/\353\221\220\354\210\230\354\235\230\355\225\251.java" create mode 100644 "2023/07.27/\354\235\264\354\210\230\354\232\251/\354\210\230\354\241\261\352\264\2001.java" diff --git "a/2023/07.27/\354\235\264\354\210\230\354\232\251/\353\221\220\354\210\230\354\235\230\355\225\251.java" "b/2023/07.27/\354\235\264\354\210\230\354\232\251/\353\221\220\354\210\230\354\235\230\355\225\251.java" new file mode 100644 index 0000000..f1e9c7a --- /dev/null +++ "b/2023/07.27/\354\235\264\354\210\230\354\232\251/\353\221\220\354\210\230\354\235\230\355\225\251.java" @@ -0,0 +1,55 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/9024 + +public class 두수의합 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + for (int test = 0; test < t; test++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + int[] arr = new int[n]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(arr); + int left = 0; + int right = arr.length - 1; + int minValue = Integer.MAX_VALUE; + int count = 1; + + while (true) { + int sum = arr[left] + arr[right]; + if (Math.abs(sum - k) == minValue) { + count++; + } else if (Math.abs(sum - k) < minValue) { + count = 1; + minValue = Math.abs(sum - k); + } + + if (sum == k) { + left++; + right--; + } else if (sum < k) { + left++; + } else { + right--; + } + + if (left >= right) { + break; + } + } + System.out.println(count); + } + } +} diff --git "a/2023/07.27/\354\235\264\354\210\230\354\232\251/\354\210\230\354\241\261\352\264\2001.java" "b/2023/07.27/\354\235\264\354\210\230\354\232\251/\354\210\230\354\241\261\352\264\2001.java" new file mode 100644 index 0000000..afee936 --- /dev/null +++ "b/2023/07.27/\354\235\264\354\210\230\354\232\251/\354\210\230\354\241\261\352\264\2001.java" @@ -0,0 +1,78 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/8982 + +public class 수족관1 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + int[] depth = new int[40001]; + int[] surface = new int[40001]; + int lastIndex = 0; + br.readLine(); + for (int i = 0; i < n / 2 - 1; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for (int j = x1; j < x2; j++) { + depth[j] = y1; + } + lastIndex = x2 - 1; + } + br.readLine(); + + int k = Integer.parseInt(br.readLine()); + Vertex[] hole = new Vertex[k]; + + for (int i = 0; i < k; ++i) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + hole[i] = new Vertex(x, y); + } + for (Vertex currentVertex : hole) { + int currentDepth = currentVertex.y; + int currentCol = currentVertex.x; + + for (int i = currentCol; i >= 0; --i) { + currentDepth = currentDepth > depth[i] ? depth[i] : currentDepth; + surface[i] = currentDepth > surface[i] ? currentDepth : surface[i]; + } + + currentDepth = currentVertex.y; + currentCol = currentVertex.x; + + for (int i = currentCol; i <= lastIndex; ++i) { + currentDepth = currentDepth > depth[i] ? depth[i] : currentDepth; + surface[i] = currentDepth > surface[i] ? currentDepth : surface[i]; + } + } + int ans = 0; + for (int i = 0; i <= lastIndex; ++i) { + ans += depth[i] - surface[i]; + } + System.out.println(ans); + } + + static class Vertex { + int x, y; + + Vertex(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public String toString() { + return x + ":" + y; + } + } +} From 3cbb77a648e882a1fc617024436fc7a30c916510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=89=E1=85=AE=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Thu, 10 Aug 2023 00:01:35 +0900 Subject: [PATCH 692/822] =?UTF-8?q?0731=20=EC=88=98=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\225\261.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "2023/07.31/\354\235\264\354\210\230\354\232\251/\354\225\261.java" diff --git "a/2023/07.31/\354\235\264\354\210\230\354\232\251/\354\225\261.java" "b/2023/07.31/\354\235\264\354\210\230\354\232\251/\354\225\261.java" new file mode 100644 index 0000000..545a801 --- /dev/null +++ "b/2023/07.31/\354\235\264\354\210\230\354\232\251/\354\225\261.java" @@ -0,0 +1,49 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/7579 + +public class 앱 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + int[] memory = new int[N]; + int[] cost = new int[N]; + StringTokenizer stMemory = new StringTokenizer(br.readLine()); + StringTokenizer stCost = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + memory[i] = Integer.parseInt(stMemory.nextToken()); + cost[i] = Integer.parseInt(stCost.nextToken()); + } + + // N(최대 100) * cost(최대 100) + int[][] dp = new int[N][10001]; + int ans = 10001; + for (int i = 0; i < N; i++) { + int currentMemory = memory[i]; + int currentCost = cost[i]; + for (int j = 0; j < 10001; j++) { + if (i == 0) { + if (j >= currentCost) { + dp[i][j] = currentMemory; + } + } else { + if (j >= currentCost) dp[i][j] = Math.max(dp[i - 1][j - currentCost] + currentMemory, dp[i - 1][j]); + else dp[i][j] = dp[i - 1][j]; + } + + if (dp[i][j] >= M) { + ans = Math.min(ans, j); + // 최소비용으로 M이상의 메모리만 확보하면 됨. 따라서 break + break; + } + + } + } + System.out.println(ans); + } +} \ No newline at end of file From 6800600d46184d09aa5c2812fa89e296eaae31a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=89=E1=85=AE=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Thu, 10 Aug 2023 00:01:48 +0900 Subject: [PATCH 693/822] =?UTF-8?q?0803=20=EC=88=98=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\227\254\354\231\225\353\262\214.java" | 66 +++++++++++++++++++ ...\355\225\250\354\213\235\353\263\204.java" | 17 +++++ 2 files changed, 83 insertions(+) create mode 100644 "2023/08.03/\354\235\264\354\210\230\354\232\251/\354\227\254\354\231\225\353\262\214.java" create mode 100644 "2023/08.03/\354\235\264\354\210\230\354\232\251/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" diff --git "a/2023/08.03/\354\235\264\354\210\230\354\232\251/\354\227\254\354\231\225\353\262\214.java" "b/2023/08.03/\354\235\264\354\210\230\354\232\251/\354\227\254\354\231\225\353\262\214.java" new file mode 100644 index 0000000..aea58cd --- /dev/null +++ "b/2023/08.03/\354\235\264\354\210\230\354\232\251/\354\227\254\354\231\225\353\262\214.java" @@ -0,0 +1,66 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/10836 + +public class 여왕벌 { + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int M = Integer.parseInt(st.nextToken()); + int N = Integer.parseInt(st.nextToken()); + + int[][] honeycomb = new int[M][M]; + for (int i = 0; i < M; i++) { + Arrays.fill(honeycomb[i], 1); + } + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int zeroCount = Integer.parseInt(st.nextToken()); + int oneCount = Integer.parseInt(st.nextToken()); + int twoCount = Integer.parseInt(st.nextToken()); + + for (int j = M - 1; j > 0; j--) { + if (zeroCount > 0) { + zeroCount--; + } else if (oneCount > 0) { + oneCount--; + honeycomb[j][0] += 1; + } else if (twoCount > 0) { + twoCount--; + honeycomb[j][0] += 2; + } + } + + for (int j = 0; j < M; j++) { + if (zeroCount > 0) { + zeroCount--; + } else if (oneCount > 0) { + oneCount--; + honeycomb[0][j] += 1; + } else if (twoCount > 0) { + twoCount--; + honeycomb[0][j] += 2; + } + } + } + + for (int i = 1; i < M; i++) { + System.arraycopy(honeycomb[i - 1], 1, honeycomb[i], 1, M - 1); + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) + sb.append(honeycomb[i][j] + " "); + sb.append("\n"); + } + + System.out.println(sb); + } +} diff --git "a/2023/08.03/\354\235\264\354\210\230\354\232\251/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" "b/2023/08.03/\354\235\264\354\210\230\354\232\251/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" new file mode 100644 index 0000000..ef02cd3 --- /dev/null +++ "b/2023/08.03/\354\235\264\354\210\230\354\232\251/\354\236\240\354\210\230\355\225\250\354\213\235\353\263\204.java" @@ -0,0 +1,17 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.regex.Pattern; + +// https://www.acmicpc.net/problem/2671 + +public class 잠수함식별 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String sound = br.readLine(); + String ans = "NOISE"; + if (Pattern.matches("(100+1+|01)+", sound)) + ans = "SUBMARINE"; + System.out.println(ans); + } +} \ No newline at end of file From 090a7bb541581015613c57c8d30223723d9fd00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=89=E1=85=AE=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Thu, 10 Aug 2023 00:02:02 +0900 Subject: [PATCH 694/822] =?UTF-8?q?0807=20=EC=88=98=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\235\274\355\225\231\353\205\204.java" | 33 ++++++++++ ...\354\273\265\353\235\274\353\251\264.java" | 66 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 "2023/08.07/\354\235\264\354\210\230\354\232\251/\354\235\274\355\225\231\353\205\204.java" create mode 100644 "2023/08.07/\354\235\264\354\210\230\354\232\251/\354\273\265\353\235\274\353\251\264.java" diff --git "a/2023/08.07/\354\235\264\354\210\230\354\232\251/\354\235\274\355\225\231\353\205\204.java" "b/2023/08.07/\354\235\264\354\210\230\354\232\251/\354\235\274\355\225\231\353\205\204.java" new file mode 100644 index 0000000..7164f7a --- /dev/null +++ "b/2023/08.07/\354\235\264\354\210\230\354\232\251/\354\235\274\355\225\231\353\205\204.java" @@ -0,0 +1,33 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +// https://www.acmicpc.net/problem/5557 + +public class 일학년 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + StringTokenizer st = new StringTokenizer(br.readLine()); + int[] numbers = new int[N]; + long[][] dp = new long[N - 1][21]; + for(int i = 0; i < N; i++){ + numbers[i] = Integer.parseInt(st.nextToken()); + } + dp[0][numbers[0]] = 1; + for(int i = 1; i < N - 1; i++){ + for(int j = 0; j < 21; j++){ + if(dp[i-1][j] > 0){ + int plus = j + numbers[i]; + int minus = j - numbers[i]; + if(0 <= plus && plus <= 20) + dp[i][j + numbers[i]] += dp[i - 1][j]; + if(0 <= minus && minus <= 20) + dp[i][j - numbers[i]] += dp[i - 1][j]; + } + } + } + System.out.println(dp[N - 2][numbers[N - 1]]); + } +} diff --git "a/2023/08.07/\354\235\264\354\210\230\354\232\251/\354\273\265\353\235\274\353\251\264.java" "b/2023/08.07/\354\235\264\354\210\230\354\232\251/\354\273\265\353\235\274\353\251\264.java" new file mode 100644 index 0000000..1b98738 --- /dev/null +++ "b/2023/08.07/\354\235\264\354\210\230\354\232\251/\354\273\265\353\235\274\353\251\264.java" @@ -0,0 +1,66 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +// https://www.acmicpc.net/problem/1781 + +public class 컵라면 { + public static void main(String[] args) throws IOException { + PriorityQueue pq = new PriorityQueue<>(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + Question[] questionList = new Question[N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int deadLine = Integer.parseInt(st.nextToken()); + int cupNoodle = Integer.parseInt(st.nextToken()); + questionList[i] = new Question(deadLine, cupNoodle); + } + Arrays.parallelSort(questionList); + for(Question q : questionList){ + int queueSize = pq.size(); + if(queueSize < q.deadLine){ + pq.add(q.cupNoodle); + }else if(queueSize == q.deadLine){ + if(q.cupNoodle > pq.peek()){ + pq.poll(); + pq.add(q.cupNoodle); + } + } + } + int ans = 0; + while(!pq.isEmpty()){ + ans += pq.poll(); + } + System.out.println(ans); + } +} + +class Question implements Comparable { + Question(int deadLine, int cupNoodle) { + this.deadLine = deadLine; + this.cupNoodle = cupNoodle; + } + + int deadLine; + int cupNoodle; + + @Override + public int compareTo(Question o) { + if (this.deadLine < o.deadLine) { + return -1; + } else if (this.deadLine == o.deadLine) { + if (this.cupNoodle > o.cupNoodle) { + return -1; + } else if (this.cupNoodle == o.cupNoodle) { + return 0; + } else { + return 1; + } + } else { + return 1; + } + } +} From e707b41f3914249695c04e2634daafa1269958c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=89=E1=85=AE=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Thu, 10 Aug 2023 00:02:10 +0900 Subject: [PATCH 695/822] =?UTF-8?q?0810=20=EC=88=98=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\230\225\355\207\264\352\267\274.java" | 68 +++++++++++++++++++ ...\354\236\245\353\275\221\352\270\260.java" | 64 +++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 "2023/08.10/\354\235\264\354\210\230\354\232\251/\354\260\275\354\230\201\354\235\264\355\230\225\355\207\264\352\267\274.java" create mode 100644 "2023/08.10/\354\235\264\354\210\230\354\232\251/\355\232\214\354\236\245\353\275\221\352\270\260.java" diff --git "a/2023/08.10/\354\235\264\354\210\230\354\232\251/\354\260\275\354\230\201\354\235\264\355\230\225\355\207\264\352\267\274.java" "b/2023/08.10/\354\235\264\354\210\230\354\232\251/\354\260\275\354\230\201\354\235\264\355\230\225\355\207\264\352\267\274.java" new file mode 100644 index 0000000..517bc75 --- /dev/null +++ "b/2023/08.10/\354\235\264\354\210\230\354\232\251/\354\260\275\354\230\201\354\235\264\355\230\225\355\207\264\352\267\274.java" @@ -0,0 +1,68 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/22116 + +public class 창영이형퇴근 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + int[] dx = {-1, 1, 0, 0}; + int[] dy = {0, 0, -1, 1}; + int[][] grid = new int[N][N]; + int[][] visited = new int[N][N]; + PriorityQueue pq = new PriorityQueue(); + for (int i = 0; i < N; i++) { + Arrays.fill(visited[i], Integer.MAX_VALUE); + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + grid[i][j] = Integer.parseInt(st.nextToken()); + } + } + visited[0][0] = 0; + // slope, row, col + pq.add(new Info(0, 0, 0)); + while (!pq.isEmpty()) { + Info info = pq.poll(); + int slope = info.slope; + int row = info.row; + int col = info.col; + if (visited[row][col] < slope) continue; + for (int i = 0; i < 4; i++) { + int nRow = row + dx[i]; + int nCol = col + dy[i]; + if ((0 <= nRow && nRow < N) && (0 <= nCol && nCol < N)) { + int nSlope = Math.max(Math.abs(grid[row][col] - grid[nRow][nCol]), slope); + if (visited[nRow][nCol] > nSlope) { + visited[nRow][nCol] = nSlope; + pq.add(new Info(nSlope, nRow, nCol)); + } + } + } + } + System.out.println(visited[N - 1][N - 1]); + } +} + +class Info implements Comparable { + int slope; + int row; + int col; + + public Info(int slope, int row, int col) { + this.slope = slope; + this.row = row; + this.col = col; + } + + @Override + public int compareTo(Info o) { + if (this.slope < o.slope) return -1; + else if (this.slope == o.slope) return 0; + else return 1; + } +} \ No newline at end of file diff --git "a/2023/08.10/\354\235\264\354\210\230\354\232\251/\355\232\214\354\236\245\353\275\221\352\270\260.java" "b/2023/08.10/\354\235\264\354\210\230\354\232\251/\355\232\214\354\236\245\353\275\221\352\270\260.java" new file mode 100644 index 0000000..30a54f0 --- /dev/null +++ "b/2023/08.10/\354\235\264\354\210\230\354\232\251/\355\232\214\354\236\245\353\275\221\352\270\260.java" @@ -0,0 +1,64 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/2660 + +class 회장뽑기 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + int dist[][] = new int[N][N]; + // 자기 자신으로 가는 거리 = 0, 최대 50명 이므로 회장 최대 점수는 49점 + for(int i = 0; i < N; i++){ + for(int j = 0; j < N; j++){ + if(i == j){ + dist[i][j] = 0; + }else{ + dist[i][j] = 50; + } + } + } + // 모든 사람과의 거리는 1 + while(true){ + StringTokenizer st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + if(from == -1 && to == -1) break; + dist[from - 1][to - 1] = 1; + dist[to - 1][from - 1] = 1; + } + for(int i = 0; i < N; i++){ + for(int j = 0; j < N; j++){ + for(int k = 0; k < N; k++){ + //j -> k 까지 가는 거리 vs j -> i -> k 거리 + dist[j][k] = Math.min(dist[j][i] + dist[i][k], dist[j][k]); + } + } + } + + int[] scoreList = new int[N]; + int minScore = 50; + for(int i = 0; i < N; i++){ + // 각 회장 후보마다 점수를 구해서 최소 점수인 사람을 선출 + int score = Arrays.stream(dist[i]).max().getAsInt(); + scoreList[i] = score; + if(minScore > score) minScore = score; + } + StringBuilder sb1 = new StringBuilder(); + sb1.append(minScore + " "); + StringBuilder sb2 = new StringBuilder(); + int ansCount = 0; + for(int i = 0; i < N; i++){ + if(scoreList[i] == minScore){ + ansCount += 1; + sb2.append(i + 1 + " "); + } + } + sb1.append(ansCount); + System.out.println(sb1); + System.out.println(sb2); + } +} \ No newline at end of file From c80b16d9f8cec234743658d15b7eb6679f1d94e8 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 10 Aug 2023 14:12:42 +0900 Subject: [PATCH 696/822] 0810 kihun --- 2023/08.10/Readme.md | 5 + ...\354\231\200\355\207\264\352\267\274.java" | 96 +++++++++++++++++++ ...\354\236\245\353\275\221\352\270\260.java" | 91 ++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 2023/08.10/Readme.md create mode 100644 "2023/08.10/\354\206\241\352\270\260\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200\355\207\264\352\267\274.java" create mode 100644 "2023/08.10/\354\206\241\352\270\260\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260.java" diff --git a/2023/08.10/Readme.md b/2023/08.10/Readme.md new file mode 100644 index 0000000..7b4af87 --- /dev/null +++ b/2023/08.10/Readme.md @@ -0,0 +1,5 @@ +# 8.7(월) 스터디 + +- 백준 + - [창영이와 퇴근](https://www.acmicpc.net/problem/22116) + - [회장뽑기](https://www.acmicpc.net/problem/2660) diff --git "a/2023/08.10/\354\206\241\352\270\260\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200\355\207\264\352\267\274.java" "b/2023/08.10/\354\206\241\352\270\260\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200\355\207\264\352\267\274.java" new file mode 100644 index 0000000..e23fb39 --- /dev/null +++ "b/2023/08.10/\354\206\241\352\270\260\355\233\210/\354\260\275\354\230\201\354\235\264\354\231\200\355\207\264\352\267\274.java" @@ -0,0 +1,96 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class 창영이와퇴근 { + + static class Node implements Comparable { + int y, x; + long height; + + public Node(int y, int x, long height) { + this.y = y; + this.x = x; + this.height = height; + } + + @Override + public int compareTo(Node node) { + return Long.compare(this.height, node.height); + } + } + + static int N; + static long maxHeight; + static long[][] matrix; + static long[][] heights; + + static int[] dY = {1, 0, -1, 0}; + static int[] dX = {0, 1, 0, -1}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + matrix = new long[N][N]; + heights = new long[N][N]; + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + matrix[i][j] = Long.parseLong(st.nextToken()); + } + } + + // 모든 heights를 MAX_VALUE로 + for (long[] h : heights) { + Arrays.fill(h, Long.MAX_VALUE); + } + + maxHeight = 0; + bfs(); + System.out.println(maxHeight); + } + + static void bfs() { + // 1 x 1이면 갈 곳이 없으므로 끝 + if (N == 1) { + return; + } + + PriorityQueue queue = new PriorityQueue<>(); + queue.offer(new Node(0, 1, Math.abs(matrix[0][0] - matrix[0][1]))); + queue.offer(new Node(1, 0, Math.abs(matrix[0][0] - matrix[1][0]))); + maxHeight = 0; + heights[0][0] = 0; + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + // 이미 간 곳이라 패스 + if (heights[now.y][now.x] != Long.MAX_VALUE) continue; + + heights[now.y][now.x] = now.height; + maxHeight = Math.max(maxHeight, now.height); + + // 도착 + if (now.y == N - 1 && now.x == N - 1) break; + + for (int i = 0; i < 4; i++) { + int nY = now.y + dY[i]; + int nX = now.x + dX[i]; + + if (nY < 0 || nX < 0 || nY >= N || nX >= N) continue; + if (heights[nY][nX] != Long.MAX_VALUE) continue; + + queue.offer(new Node(nY, nX, Math.abs(matrix[now.y][now.x] - matrix[nY][nX]))); + } + } + + } +} diff --git "a/2023/08.10/\354\206\241\352\270\260\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260.java" "b/2023/08.10/\354\206\241\352\270\260\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260.java" new file mode 100644 index 0000000..e8a8a14 --- /dev/null +++ "b/2023/08.10/\354\206\241\352\270\260\355\233\210/\355\232\214\354\236\245\353\275\221\352\270\260.java" @@ -0,0 +1,91 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.StringTokenizer; + +public class 회장뽑기 { + + static int N; + static int[][] matrix; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + matrix = new int[N+1][N+1]; + + // (i, i)를 제외하고 모두 큰 값으로 초기화 + for (int[] m : matrix) { + Arrays.fill(m, 5000); + } + for (int i = 1; i <= N; i++) { + matrix[i][i] = 0; + } + + while (true) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int y = Integer.parseInt(st.nextToken()); + int x = Integer.parseInt(st.nextToken()); + + if (y == -1 && x == -1) { + break; + } + + matrix[y][x] = 1; + matrix[x][y] = 1; + } + + // 플로이드 워셜 + for (int mid = 1; mid <= N; mid++) { + for (int start = 1; start <= N; start++) { + for (int end = 1; end <= N; end++) { + + if (matrix[start][end] > matrix[start][mid] + matrix[mid][end]) { + matrix[start][end] = matrix[start][mid] + matrix[mid][end]; + } + + } + } + } + + int minScore = Integer.MAX_VALUE; + ArrayList candidates = new ArrayList<>(); + for (int i = 1; i <= N; i++) { + int temp = 0; + for (int j = 1; j <= N; j++) { + if (matrix[i][j] != 5000) { + temp = Math.max(matrix[i][j], temp); + } + } + + if (minScore == temp) { + candidates.add(i); + } + else if (minScore > temp) { + minScore = Math.min(temp, minScore); + candidates = new ArrayList<>(); + candidates.add(i); + } + + } + + Collections.sort(candidates); + + StringBuilder sb = new StringBuilder(); + sb.append(minScore).append(" ").append(candidates.size()).append("\n"); + for (int i = 0; i < candidates.size(); i++) { + sb.append(candidates.get(i)); + if (i != candidates.size() - 1) { + sb.append(" "); + } + } + + System.out.println(sb); + + } +} From 81c1fd6a10260d11a2f646dbc7d702451a56fb30 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 10 Aug 2023 16:45:48 +0900 Subject: [PATCH 697/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20RGB=EA=B1=B0?= =?UTF-8?q?=EB=A6=AC=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RGB\352\261\260\353\246\254_2.kt" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "2023/08.17/\354\241\260\354\210\230\354\227\260/RGB\352\261\260\353\246\254_2.kt" diff --git "a/2023/08.17/\354\241\260\354\210\230\354\227\260/RGB\352\261\260\353\246\254_2.kt" "b/2023/08.17/\354\241\260\354\210\230\354\227\260/RGB\352\261\260\353\246\254_2.kt" new file mode 100644 index 0000000..4814829 --- /dev/null +++ "b/2023/08.17/\354\241\260\354\210\230\354\227\260/RGB\352\261\260\353\246\254_2.kt" @@ -0,0 +1,45 @@ +import java.io.* +import java.util.* +import kotlin.math.min + +lateinit var st: StringTokenizer +const val MAX_VALUE = 1000000 + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val n = readLine().toInt() + val house = Array(n + 1) { IntArray(n + 1) } + val dp = Array(n + 1) { IntArray(n + 1) } + + repeat(n) { + st = StringTokenizer(readLine()) + house[it + 1][0] = st.nextToken().toInt() + house[it + 1][1] = st.nextToken().toInt() + house[it + 1][2] = st.nextToken().toInt() + } + + var answer = MAX_VALUE + + for (i in 0 until 3) { // R -> G -> B순으로 선택 + for (j in 0 until 3) { // 선택한 색깔 집을 제외하고는 최댓값으로 갱신 + if (i == j) dp[1][j] = house[1][j] + else dp[1][j] = MAX_VALUE + } + + for (j in 2..n){ + dp[j][0] = house[j][0] + min(dp[j-1][1], dp[j-1][2]) + dp[j][1] = house[j][1] + min(dp[j-1][0], dp[j-1][2]) + dp[j][2] = house[j][2] + min(dp[j-1][0], dp[j-1][1]) + } + + for (j in 0 until 3){ + if (i != j) answer = min(answer, dp[n][j]) // n번이 1번에서 선택한 집이 아닐 때 최솟값 갱신 + } + } + + bw.write("$answer") + + bw.flush() + bw.close() +} \ No newline at end of file From 6458769a4bc0a41074e7d35cd745716aa1300828 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 10 Aug 2023 20:49:51 +0900 Subject: [PATCH 698/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EC=A0=84?= =?UTF-8?q?=ED=99=94=EB=B2=88=ED=98=B8=20=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\230\270_\353\252\251\353\241\235.kt" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "2023/08.17/\354\241\260\354\210\230\354\227\260/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.kt" diff --git "a/2023/08.17/\354\241\260\354\210\230\354\227\260/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.kt" "b/2023/08.17/\354\241\260\354\210\230\354\227\260/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.kt" new file mode 100644 index 0000000..c93c0e9 --- /dev/null +++ "b/2023/08.17/\354\241\260\354\210\230\354\227\260/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235.kt" @@ -0,0 +1,31 @@ +import java.io.* + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val t = readLine().toInt() + var contactArr: Array + + repeat(t) { + val n = readLine().toInt() + var isFind = false + contactArr = Array(n) { "" } + + repeat(n) { contactArr[it] = readLine() } + + contactArr.sort() + + for (i in 0 until n-1){ + if (contactArr[i + 1].startsWith(contactArr[i])) { + isFind = true + break + } + } + + if (isFind) bw.write("NO\n") + else bw.write("YES\n") + } + + bw.flush() + bw.close() +} \ No newline at end of file From 3b901725e0a9499a5bfac3e06d61f293ced8054c Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 10 Aug 2023 22:12:16 +0900 Subject: [PATCH 699/822] [SOLVE] @josooyeon11: Cubeditor --- .../Cubeditor .kt" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "2023/08.17/\354\241\260\354\210\230\354\227\260/Cubeditor .kt" diff --git "a/2023/08.17/\354\241\260\354\210\230\354\227\260/Cubeditor .kt" "b/2023/08.17/\354\241\260\354\210\230\354\227\260/Cubeditor .kt" new file mode 100644 index 0000000..a6144a0 --- /dev/null +++ "b/2023/08.17/\354\241\260\354\210\230\354\227\260/Cubeditor .kt" @@ -0,0 +1,41 @@ +import java.io.* +import kotlin.math.max + +lateinit var table: IntArray + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val str = readLine() + val n = str.length + var answer = 0 + + for (i in 0 until n) { + val pattern = str.substring(i, n) + answer = max(answer, makeTable(pattern)) + } + + bw.write("$answer") + + bw.flush() + bw.close() +} + +fun makeTable(pattern: String): Int { + var idx = 0 + var answer = 0 + val len = pattern.length + table = IntArray(len) + + for (i in 1 until len) { + while (idx > 0 && pattern[i] != pattern[idx]) { + idx = table[idx - 1] + } + + if (pattern[i] == pattern[idx]) { + table[i] = ++idx + answer = max(answer, table[i]) + } + } + return answer +} \ No newline at end of file From f9d965fc26f4c72d4f3a00d0cd55de1e61239619 Mon Sep 17 00:00:00 2001 From: "suyong5713@gmail.com" Date: Fri, 11 Aug 2023 21:18:49 +0900 Subject: [PATCH 700/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20RGB?= =?UTF-8?q?=EA=B1=B0=EB=A6=AC2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RGB\352\261\260\353\246\2542.java" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "2023/08.17/\354\235\264\354\210\230\354\232\251/RGB\352\261\260\353\246\2542.java" diff --git "a/2023/08.17/\354\235\264\354\210\230\354\232\251/RGB\352\261\260\353\246\2542.java" "b/2023/08.17/\354\235\264\354\210\230\354\232\251/RGB\352\261\260\353\246\2542.java" new file mode 100644 index 0000000..ccac5cc --- /dev/null +++ "b/2023/08.17/\354\235\264\354\210\230\354\232\251/RGB\352\261\260\353\246\2542.java" @@ -0,0 +1,55 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/17404 + +public class RGB거리2 { + public static void main(String[] args) throws IOException { + final int INF = 1_000_000; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + int[][] arr = new int[N][3]; + int[][] dp = new int[N][3]; + for(int i = 0; i < N; i++){ + StringTokenizer st = new StringTokenizer(br.readLine()); + for(int j = 0; j < 3; j++){ + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + // 첫번째 집을 빨간색 + dp[0][0] = arr[0][0]; + dp[0][1] = INF; + dp[0][2] = INF; + for(int i = 1; i < N; i++){ + dp[i][0] = Math.min(dp[i-1][1], dp[i-1][2]) + arr[i][0]; + dp[i][1] = Math.min(dp[i-1][0], dp[i-1][2]) + arr[i][1]; + dp[i][2] = Math.min(dp[i-1][0], dp[i-1][1]) + arr[i][2]; + } + int ans = Math.min(dp[N-1][1], dp[N-1][2]); + + // 첫번째 집을 초록색 + dp[0][1] = arr[0][1]; + dp[0][0] = INF; + dp[0][2] = INF; + for(int i = 1; i < N; i++){ + dp[i][0] = Math.min(dp[i-1][1], dp[i-1][2]) + arr[i][0]; + dp[i][1] = Math.min(dp[i-1][0], dp[i-1][2]) + arr[i][1]; + dp[i][2] = Math.min(dp[i-1][0], dp[i-1][1]) + arr[i][2]; + } + ans = Math.min(ans, Math.min(dp[N-1][0], dp[N-1][2])); + + // 첫번째 집을 파란색 + dp[0][2] = arr[0][2]; + dp[0][0] = INF; + dp[0][1] = INF; + for(int i = 1; i < N; i++){ + dp[i][0] = Math.min(dp[i-1][1], dp[i-1][2]) + arr[i][0]; + dp[i][1] = Math.min(dp[i-1][0], dp[i-1][2]) + arr[i][1]; + dp[i][2] = Math.min(dp[i-1][0], dp[i-1][1]) + arr[i][2]; + } + ans = Math.min(ans, Math.min(dp[N-1][1], dp[N-1][0])); + System.out.println(ans); + } +} From e63dd815944cecf5115af6ec4a3982260a74e350 Mon Sep 17 00:00:00 2001 From: "suyong5713@gmail.com" Date: Fri, 11 Aug 2023 22:18:05 +0900 Subject: [PATCH 701/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EC=A0=84?= =?UTF-8?q?=ED=99=94=EB=B2=88=ED=98=B8=20=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\230\270\353\252\251\353\241\235.java" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "2023/08.17/\354\235\264\354\210\230\354\232\251/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" diff --git "a/2023/08.17/\354\235\264\354\210\230\354\232\251/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" "b/2023/08.17/\354\235\264\354\210\230\354\232\251/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" new file mode 100644 index 0000000..d5c5e59 --- /dev/null +++ "b/2023/08.17/\354\235\264\354\210\230\354\232\251/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" @@ -0,0 +1,31 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +// https://www.acmicpc.net/problem/5052 + +public class 전화번호목록 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int tc = Integer.parseInt(br.readLine()); + while (tc > 0) { + int N = Integer.parseInt(br.readLine()); + String[] contactList = new String[N]; + for (int i = 0; i < N; i++) { + contactList[i] = br.readLine(); + } + Arrays.sort(contactList); + boolean flag = true; + for(int i = 0; i < contactList.length - 1; i++){ + if(contactList[i + 1].startsWith(contactList[i])) { + System.out.println("NO"); + flag = false; + break; + } + } + if(flag) System.out.println("YES"); + tc--; + } + } +} From e67ac92dd30793e90e3c66161073c03c2dd1ec97 Mon Sep 17 00:00:00 2001 From: "suyong5713@gmail.com" Date: Sat, 12 Aug 2023 00:30:01 +0900 Subject: [PATCH 702/822] [SOLVE] @suyong5713 - Cubeditor --- .../Cubeditor.java" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "2023/08.17/\354\235\264\354\210\230\354\232\251/Cubeditor.java" diff --git "a/2023/08.17/\354\235\264\354\210\230\354\232\251/Cubeditor.java" "b/2023/08.17/\354\235\264\354\210\230\354\232\251/Cubeditor.java" new file mode 100644 index 0000000..f20b255 --- /dev/null +++ "b/2023/08.17/\354\235\264\354\210\230\354\232\251/Cubeditor.java" @@ -0,0 +1,35 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Cubeditor { + static int max =0; + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println(makeTable(br.readLine())); + } + + static int makeTable(String parent) { + int parentLength = parent.length(); + for(int pos=0; pos < parentLength; pos++) { + String pattern = parent.substring(pos); + int patternLength = pattern.length(); + // table[idx] : 패턴의 idx번째 문자까지 중복출현하는 최장 문자열 길이 + int[] table = new int[patternLength]; + // 접두사 길이 + int idx = 0; + for(int i=1; i < patternLength; i++) { + while(idx>0 && pattern.charAt(i) != pattern.charAt(idx)) { + // 여기가 이해 안됨 + idx = table[idx-1]; + } + // 일치하면 접두사 인덱스 한칸 이동. 접두사의 길이 최댓값 비교 후 갱신 + if(pattern.charAt(i) == pattern.charAt(idx)) { + table[i] = ++idx; + max = Math.max(max, idx); + } + } + } + return max; + } +} From be521c88871c82e14b43616b538e6f103fe03e35 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 14 Aug 2023 18:46:11 +0900 Subject: [PATCH 703/822] 0817 kihun --- .../Cubeditor.java" | 50 +++++++++++++ .../RGB\352\261\260\353\246\2542.java" | 75 +++++++++++++++++++ ...\355\230\270\353\252\251\353\241\235.java" | 41 ++++++++++ 3 files changed, 166 insertions(+) create mode 100644 "2023/08.17/\354\206\241\352\270\260\355\233\210/Cubeditor.java" create mode 100644 "2023/08.17/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\2542.java" create mode 100644 "2023/08.17/\354\206\241\352\270\260\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" diff --git "a/2023/08.17/\354\206\241\352\270\260\355\233\210/Cubeditor.java" "b/2023/08.17/\354\206\241\352\270\260\355\233\210/Cubeditor.java" new file mode 100644 index 0000000..e7d7b15 --- /dev/null +++ "b/2023/08.17/\354\206\241\352\270\260\355\233\210/Cubeditor.java" @@ -0,0 +1,50 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Cubeditor { + + // 접두사와 접미사가 같은 문자열의 최대 길이 + // https://loosie.tistory.com/192 + // https://youtu.be/UcjK_k5PLHI + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String inputString = br.readLine(); + int length = inputString.length(); + int answer = 0; + + for (int i = 0; i < length; i++) { + String subString = inputString.substring(i, length); + answer = Math.max(answer, kmp(subString)); + } + + System.out.println(answer); + } + + static int kmp(String str) { + int left = 0; + int length = str.length(); + int maxValue = 0; + int[] table = new int[length]; + + for (int right = 1; right < length; right++) { + + while (left > 0 && str.charAt(right) != str.charAt(left)) { + left = table[left - 1]; + } + + if (str.charAt(left) == str.charAt(right)) { + left += 1; + table[right] = left; + maxValue = Math.max(maxValue, left); + } + + } + + return maxValue; + } + +} diff --git "a/2023/08.17/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\2542.java" "b/2023/08.17/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\2542.java" new file mode 100644 index 0000000..4791aa7 --- /dev/null +++ "b/2023/08.17/\354\206\241\352\270\260\355\233\210/RGB\352\261\260\353\246\2542.java" @@ -0,0 +1,75 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class RGB거리2 { + + static int N, result; + static int[][] dp, costs; + + static final int RED = 0; + static final int GREEN = 1; + static final int BLUE = 2; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + dp = new int[N + 1][3]; + costs = new int[N][3]; + + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int red = Integer.parseInt(st.nextToken()); + int green = Integer.parseInt(st.nextToken()); + int blue = Integer.parseInt(st.nextToken()); + + costs[i][RED] = red; + costs[i][GREEN] = green; + costs[i][BLUE] = blue; + } + + result = Integer.MAX_VALUE; + reset(); + for (int i = 0; i < 3; i++) { + paint(i); + reset(); + } + System.out.println(result); + } + + static void reset() { + for (int d[] : dp) { + Arrays.fill(d, 10000000); + } + } + + static void paint(int index) { + + // 첫번째 색을 고정 + dp[0][index] = costs[0][index]; + for (int i = 0; i < 3; i++) { + if (i == index) continue; + dp[1][i] = dp[0][index] + costs[1][i]; + } + + // RGB 거리 참고 + for (int i = 2; i < N; i++) { + dp[i][RED] = Math.min(dp[i - 1][GREEN], dp[i - 1][BLUE]) + costs[i][RED]; + dp[i][GREEN] = Math.min(dp[i - 1][RED], dp[i - 1][BLUE]) + costs[i][GREEN]; + dp[i][BLUE] = Math.min(dp[i - 1][RED], dp[i - 1][GREEN]) + costs[i][BLUE]; + } + + // 첫번째 색 제외하고 결정 + for (int i = 0; i < 3; i++) { + if (i == index) continue; + result = Math.min(result, dp[N - 1][i]); + } + + } + +} diff --git "a/2023/08.17/\354\206\241\352\270\260\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" "b/2023/08.17/\354\206\241\352\270\260\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" new file mode 100644 index 0000000..021022c --- /dev/null +++ "b/2023/08.17/\354\206\241\352\270\260\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" @@ -0,0 +1,41 @@ +package baekjoon.gold.four; + +import java.io.*; +import java.util.*; + +public class 전화번호목록 { + // 포함 관계인가? + // 포함 관계이면 NO + + static int T, N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + T = Integer.parseInt(br.readLine()); + + for (int t = 0; t < T; t++) { + N = Integer.parseInt(br.readLine()); + String[] numbers = new String[N]; + for (int i = 0; i < N; i++) { + numbers[i] = br.readLine(); + } + Arrays.sort(numbers); + + boolean flag = true; + for (int i = 0; i < N - 1; i++) { + if (numbers[i + 1].startsWith(numbers[i])) { + flag = false; + break; + } + } + + if (flag) { + System.out.println("YES"); + } else { + System.out.println("NO"); + } + } + + } + +} From 80486cf9ea20b8560a217b8808a85b48bbaeaeea Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 14 Aug 2023 18:46:35 +0900 Subject: [PATCH 704/822] 0817 Readme.md --- 2023/08.10/Readme.md | 2 +- 2023/08.17/Readme.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 2023/08.17/Readme.md diff --git a/2023/08.10/Readme.md b/2023/08.10/Readme.md index 7b4af87..11c06fd 100644 --- a/2023/08.10/Readme.md +++ b/2023/08.10/Readme.md @@ -1,4 +1,4 @@ -# 8.7(월) 스터디 +# 8.10(목) 스터디 - 백준 - [창영이와 퇴근](https://www.acmicpc.net/problem/22116) diff --git a/2023/08.17/Readme.md b/2023/08.17/Readme.md new file mode 100644 index 0000000..3cde021 --- /dev/null +++ b/2023/08.17/Readme.md @@ -0,0 +1,6 @@ +# 8.17(목) 스터디 + +- 백준 + - [Cubeditor](https://www.acmicpc.net/problem/1701) + - [전화번호 목록](https://www.acmicpc.net/problem/5052) + - [RGB거리 2](https://www.acmicpc.net/problem/17404) From e64ed406aa45985a62f571ff162feaafb30e96b7 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 14 Aug 2023 20:53:00 +0900 Subject: [PATCH 705/822] =?UTF-8?q?Create=20RGB=EA=B1=B0=EB=A6=AC2.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RGB\352\261\260\353\246\2542.java" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "2023/08.17/\354\240\225\355\230\270\354\241\260/RGB\352\261\260\353\246\2542.java" diff --git "a/2023/08.17/\354\240\225\355\230\270\354\241\260/RGB\352\261\260\353\246\2542.java" "b/2023/08.17/\354\240\225\355\230\270\354\241\260/RGB\352\261\260\353\246\2542.java" new file mode 100644 index 0000000..b9f2ec1 --- /dev/null +++ "b/2023/08.17/\354\240\225\355\230\270\354\241\260/RGB\352\261\260\353\246\2542.java" @@ -0,0 +1,62 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/** + * 조건 1) 인접한 집은 색이 달라야함, 조건 2) 1번과 N번 집은 색이 달라야함 + * 1번집이 빨, 초, 파를 골랐을 경우를 나누면서 시작 + * 1번이 빨간색을 골랐다면 N번은 빨간색을 제외한 초, 파 중 골라야함. 즉 dp[N][color]의 값이 조건 2까지 부합하는 경우의 최소 비용 + * 크기가 3인 cases[] 배열에 1번 집이 각 색깔을 골랐을 때의 최소비용 저장 후 cases[] 배열의 최솟값을 구하면 정답 + * */ +public class RGB거리2_17404 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + + int[][] home = new int[N + 1][3]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + home[i][j] = Integer.parseInt(st.nextToken()); + } + } + + int[] cases = new int[3]; + for (int color = 0; color < 3; color++) { + int[][] dp = new int[N+1][3]; + + for(int i=0; i Date: Mon, 14 Aug 2023 21:07:04 +0900 Subject: [PATCH 706/822] Cubeditor --- .../Cubeditor" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "2023/08.17/\352\271\200\354\247\200\355\233\210/Cubeditor" diff --git "a/2023/08.17/\352\271\200\354\247\200\355\233\210/Cubeditor" "b/2023/08.17/\352\271\200\354\247\200\355\233\210/Cubeditor" new file mode 100644 index 0000000..7108a53 --- /dev/null +++ "b/2023/08.17/\352\271\200\354\247\200\355\233\210/Cubeditor" @@ -0,0 +1,40 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + static int[] table; + static int max = 0; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + //StringTokenizer st = new StringTokenizer(br.readLine()); + + String str = br.readLine(); + + + for(int i=0;i0&&str.charAt(i)!=str.charAt(index)){ + index = table[index-1]; + } + if(str.charAt(i)==str.charAt(index)){ + table[i] = ++index; + m = Math.max(m,index); + } + } + return m; + } + +} From 57ebe06ae25eb91f624be9ab4edc811a156e7750 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Tue, 15 Aug 2023 17:52:55 +0900 Subject: [PATCH 707/822] =?UTF-8?q?=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\210\355\230\270 \353\252\251\353\241\235" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "2023/08.17/\352\271\200\354\247\200\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235" diff --git "a/2023/08.17/\352\271\200\354\247\200\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235" "b/2023/08.17/\352\271\200\354\247\200\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235" new file mode 100644 index 0000000..2ace0a5 --- /dev/null +++ "b/2023/08.17/\352\271\200\354\247\200\355\233\210/\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235" @@ -0,0 +1,36 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + + static String[] str; + static int n; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + //StringTokenizer st = new StringTokenizer(br.readLine()); + int TC = Integer.parseInt(br.readLine()); + + while (TC-- > 0) { + boolean flag = true; + n = Integer.parseInt(br.readLine()); + str = new String[n]; + for (int i = 0; i < n; i++) { + str[i] = br.readLine().trim(); + } + Arrays.sort(str); + for (int i = 0; i < n - 1; i++) { + if (str[i + 1].startsWith(str[i])) { + flag = !flag; + break; + } + } + System.out.println(flag ? "YES" : "NO"); + + } + } + +} From 838536ee67db20cbd752f3b7d61ab52ffc5ae043 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:26:47 +0900 Subject: [PATCH 708/822] =?UTF-8?q?RGB=20=EA=B1=B0=EB=A6=AC2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RGB \352\261\260\353\246\2542" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "2023/08.17/\352\271\200\354\247\200\355\233\210/RGB \352\261\260\353\246\2542" diff --git "a/2023/08.17/\352\271\200\354\247\200\355\233\210/RGB \352\261\260\353\246\2542" "b/2023/08.17/\352\271\200\354\247\200\355\233\210/RGB \352\261\260\353\246\2542" new file mode 100644 index 0000000..d6dfc5d --- /dev/null +++ "b/2023/08.17/\352\271\200\354\247\200\355\233\210/RGB \352\261\260\353\246\2542" @@ -0,0 +1,52 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + static final int INF = 1001; + static int[][] dp; + static int[][] RGB; + static int[] start; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int N = Integer.parseInt(br.readLine()); + dp = new int[N+1][3]; + RGB = new int[N+1][N]; + start = new int[N]; + for(int i=1;i<=N;i++){ + st = new StringTokenizer(br.readLine()); + for(int j=0;j<3;j++) + RGB[i][j] = Integer.parseInt(st.nextToken()); + } + //첫집 고정 + for(int i=0;i<3;i++){ + for(int j=0;j<3;j++){ + if(i==j) + dp[1][j] = RGB[1][j]; + else + dp[1][j] = INF; + } + for(int j=2;j<=N;j++){ + dp[j][0] = Math.min(dp[j-1][1],dp[j-1][2]) + RGB[j][0]; + dp[j][1] = Math.min(dp[j-1][0],dp[j-1][2]) + RGB[j][1]; + dp[j][2] = Math.min(dp[j-1][0],dp[j-1][1]) + RGB[j][2]; + + if(j==N){ + if(i==0) + start[i] = Math.min(dp[N][1],dp[N][2]); + else if(i==1) + start[i] = Math.min(dp[N][0],dp[N][2]); + else + start[i] = Math.min(dp[N][0],dp[N][1]); + } + } + } + System.out.println(Math.min(start[0],Math.min(start[1],start[2]))); + + } + +} From d08bf23ec7cb6759b9b291e1600747395dde10ab Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 16 Aug 2023 20:57:28 +0900 Subject: [PATCH 709/822] Create cubeditor.java --- .../cubeditor.java" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "2023/08.17/\354\240\225\355\230\270\354\241\260/cubeditor.java" diff --git "a/2023/08.17/\354\240\225\355\230\270\354\241\260/cubeditor.java" "b/2023/08.17/\354\240\225\355\230\270\354\241\260/cubeditor.java" new file mode 100644 index 0000000..3a5ab82 --- /dev/null +++ "b/2023/08.17/\354\240\225\355\230\270\354\241\260/cubeditor.java" @@ -0,0 +1,35 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Cubeditor_1701 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String str = br.readLine(); + int ans = 0; + for(int i=0; i 0 && pattern.charAt(i) != pattern.charAt(idx)){ + idx = table[idx - 1]; + } + if(pattern.charAt(i) == pattern.charAt(idx)){ + idx++; + table[i] = idx; + max = Math.max(max, table[i]); + } + } + + return max; + } +} From 91f833a62485ac6d0f23e94fbaf86a4f2c5d3086 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Thu, 17 Aug 2023 16:55:11 +0900 Subject: [PATCH 710/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20Solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...OJ 17404 RGB\352\261\260\353\246\254 2.kt" | 97 +++++++++++++++++++ ...\355\230\270\353\252\251\353\241\235.java" | 50 ++++++++++ 2 files changed, 147 insertions(+) create mode 100644 "2023/08.17/\354\265\234\354\260\275\354\230\201/BOJ 17404 RGB\352\261\260\353\246\254 2.kt" create mode 100644 "2023/08.17/\354\265\234\354\260\275\354\230\201/Main_5052_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" diff --git "a/2023/08.17/\354\265\234\354\260\275\354\230\201/BOJ 17404 RGB\352\261\260\353\246\254 2.kt" "b/2023/08.17/\354\265\234\354\260\275\354\230\201/BOJ 17404 RGB\352\261\260\353\246\254 2.kt" new file mode 100644 index 0000000..4150232 --- /dev/null +++ "b/2023/08.17/\354\265\234\354\260\275\354\230\201/BOJ 17404 RGB\352\261\260\353\246\254 2.kt" @@ -0,0 +1,97 @@ +package BOJ_17404 + +import java.io.BufferedReader +import java.io.BufferedWriter +import java.io.File +import java.io.OutputStreamWriter +import java.util.* +import kotlin.math.min + + +// https://www.acmicpc.net/problem/17404 +// input +private lateinit var br: BufferedReader + +// variables +private const val INF = Int.MAX_VALUE / 4 +private var N = 0 +private lateinit var memo: Array // N번째의 색상별 최소비용 +private lateinit var colors: Array + +private data class Color(var red: Int = 0, var green: Int = 0, var blue: Int = 0) + +fun main() { + val path = "C:\\Users\\bigyo\\Desktop\\알고리즘\\KotlinAlgo\\src\\main\\kotlin\\BOJ_17404\\res.txt" + br = BufferedReader(File(path).bufferedReader()) + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + input() + + bw.write(solve()) + bw.close() +} // End of main() + +private fun solve(): String { + val sb = StringBuilder() + + sb.append(DP()) + return sb.toString() +} // End of solve() + +private fun DP(): Int { + var ans = INF + + repeat(3) { i -> + when (i) { + 0 -> { + memo[0][0] = colors[0].red + memo[0][1] = INF + memo[0][2] = INF + } + + 1 -> { + memo[0][0] = INF + memo[0][1] = colors[0].green + memo[0][2] = INF + } + + 2 -> { + memo[0][0] = INF + memo[0][1] = INF + memo[0][2] = colors[0].blue + } + } + + + for (j in 1 until N) { + memo[j][0] = min(memo[j - 1][1], memo[j - 1][2]) + colors[j].red + memo[j][1] = min(memo[j - 1][0], memo[j - 1][2]) + colors[j].green + memo[j][2] = min(memo[j - 1][0], memo[j - 1][1]) + colors[j].blue + } + + for (j in 0 until 3) { + if (i == j) continue + ans = min(ans, memo[N - 1][j]) + } + } + + return ans +} // End of DP() + +private fun input() { + N = br.readLine().toInt() + + memo = Array(N + 1) { IntArray(3) } + colors = Array(N + 1) { Color(0, 0, 0) } + + colors = Array(N + 1) { Color() } + for (i in 0 until N) { + StringTokenizer(br.readLine()).run { + colors[i] = Color( + nextToken().toInt(), + nextToken().toInt(), + nextToken().toInt(), + ) + } + } +} // End of input() diff --git "a/2023/08.17/\354\265\234\354\260\275\354\230\201/Main_5052_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" "b/2023/08.17/\354\265\234\354\260\275\354\230\201/Main_5052_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" new file mode 100644 index 0000000..11d489b --- /dev/null +++ "b/2023/08.17/\354\265\234\354\260\275\354\230\201/Main_5052_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.java" @@ -0,0 +1,50 @@ +import java.util.*; +import java.io.*; + +public class Main_5052_전화번호목록 { + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream("res/input_bj_5052.txt")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + int T = Integer.parseInt(br.readLine()); + while(T --> 0) { + int N = Integer.parseInt(br.readLine()); + HashMap map = new HashMap<>(); + String number_list[] = new String[N]; + + for(int i=0; i map) { + + for(int i=0; i Date: Fri, 18 Aug 2023 11:32:21 +0900 Subject: [PATCH 711/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EB=B2=BC?= =?UTF-8?q?=EB=9D=BD=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.kt" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\274\353\235\275\354\271\230\352\270\260.kt" diff --git "a/2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\274\353\235\275\354\271\230\352\270\260.kt" "b/2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\274\353\235\275\354\271\230\352\270\260.kt" new file mode 100644 index 0000000..5d0f9da --- /dev/null +++ "b/2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\274\353\235\275\354\271\230\352\270\260.kt" @@ -0,0 +1,36 @@ +import java.io.* +import java.util.* +import kotlin.math.max + +lateinit var st: StringTokenizer + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (n, t) = readLine().split(" ").map { it.toInt() } + val scores = Array(n + 1) { IntArray(2) } + + repeat(n) { + st = StringTokenizer(readLine()) + scores[it + 1][0] = st.nextToken().toInt() + scores[it + 1][1] = st.nextToken().toInt() + } + + val dp = Array(n + 1) { IntArray(t + 1) } + + // knapsack + for (i in 1..n) { + for (j in 1..t) { + if (scores[i][0] > j) { + dp[i][j] = dp[i - 1][j] + } else { + dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - scores[i][0]] + scores[i][1]) + } + } + } + + bw.write("${dp[n][t]}") + + bw.flush() + bw.close() +} \ No newline at end of file From dcb96399062824ded615d61f57ab69d96580d864 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 18 Aug 2023 14:23:31 +0900 Subject: [PATCH 712/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EB=B2=BD=20?= =?UTF-8?q?=EB=B6=80=EC=88=98=EA=B3=A0=20=EC=9D=B4=EB=8F=99=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\217\231\355\225\230\352\270\260.kt" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260.kt" diff --git "a/2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260.kt" "b/2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260.kt" new file mode 100644 index 0000000..060aac5 --- /dev/null +++ "b/2023/08.24/\354\241\260\354\210\230\354\227\260/\353\262\275_\353\266\200\354\210\230\352\263\240_\354\235\264\353\217\231\355\225\230\352\270\260.kt" @@ -0,0 +1,64 @@ +import java.awt.Point +import java.io.* +import java.util.* + +lateinit var map: Array +lateinit var visited: Array> +val dir = arrayOf(intArrayOf(-1, 0), intArrayOf(1, 0), intArrayOf(0, -1), intArrayOf(0, 1)) + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val (n, m) = readLine().split(" ").map { it.toInt() } + map = Array(n) { IntArray(m) } + visited = Array(n) { Array(m) { BooleanArray(2) } } + + repeat(n) { i -> + val info = readLine() + repeat(m) { j -> + map[i][j] = info[j].digitToInt() + } + } + + bw.write("${bfs(n, m)}") + + bw.flush() + bw.close() +} + +fun bfs(n: Int, m: Int): Int { + val q: Queue> = LinkedList() + + q.add(Triple(Point(0, 0), false, 1)) + + if (n == 1 && m == 1) return 1 + + while (q.isNotEmpty()) { + val cur = q.poll() + + if (cur.first.x == m - 1 && cur.first.y == n - 1) return cur.third + + for (i in 0 until 4) { + val nx = cur.first.x + dir[i][1] + val ny = cur.first.y + dir[i][0] + + if (nx in 0 until m && ny in 0 until n) { + if (map[ny][nx] == 0) { + if (!cur.second && !visited[ny][nx][0]) { // 벽을 부순 적이 없는 경우 + q.add(Triple(Point(nx, ny), false, cur.third + 1)) + visited[ny][nx][0] = true + } else if (cur.second && !visited[ny][nx][1]) { // 벽을 한 번 부순 경우 + q.add(Triple(Point(nx, ny), true, cur.third + 1)) + visited[ny][nx][1] = true + } + } else { + if (!cur.second){ // 벽을 만났는데 부순 적이 없는 경우 + q.add(Triple(Point(nx,ny),true,cur.third + 1)) + visited[ny][nx][1] = true + } + } + } + } + } + return -1 +} \ No newline at end of file From 660501c9f131c4e863b15fa92e58afd5c74f3166 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:01:36 +0900 Subject: [PATCH 713/822] =?UTF-8?q?=EB=B2=BD=20=EB=B6=80=EC=88=98=EA=B3=A0?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\264\353\217\231\355\225\230\352\270\260" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" diff --git "a/2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" "b/2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" new file mode 100644 index 0000000..15b7d7b --- /dev/null +++ "b/2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" @@ -0,0 +1,86 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + static class Node{ + int x; + int y; + int cnt; + + //0: 안부심 , 1: 부심 + int isCrashing; + + public Node(int x, int y, int cnt, int isCrashing) { + this.x = x; + this.y = y; + this.cnt = cnt; + this.isCrashing = isCrashing; + } + } + static int min; + + static int N,M; + static int[] dx = {-1,0,1,0}; + static int[] dy = {0,1,0,-1}; + static int[][] map; + static boolean[][][] visited; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + min = Integer.MAX_VALUE; + map = new int[N][M]; + visited = new boolean[2][N][M]; + + for(int i=0;i q = new ArrayDeque<>(); + q.offer(new Node(0,0,1,0)); + + while(!q.isEmpty()){ + + Node now = q.poll(); + if(now.x==N-1&&now.y==M-1){ + min = now.cnt; + break; + } + for(int i=0;i<4;i++){ + int nx = now.x+dx[i]; + int ny = now.y+dy[i]; + if(isRange(nx,ny)){ + //벽이 아닐떄 방문한 적이 없다면 + if(map[nx][ny]==0){ + if(!visited[now.isCrashing][nx][ny]){ + q.offer(new Node(nx,ny, now.cnt+1,now.isCrashing)); + visited[now.isCrashing][nx][ny] = true; + } + }else{ + //벽일때는 벽을 한번도 안부순 경우만 + if(!visited[now.isCrashing][nx][ny]&&now.isCrashing==0){ + q.offer(new Node(nx,ny,now.cnt+1,1)); + visited[now.isCrashing][nx][ny] = true; + } + } + } + } + } + + } + static boolean isRange(int x,int y){ + return x>=0&&y>=0&&x Date: Fri, 18 Aug 2023 15:03:24 +0900 Subject: [PATCH 714/822] =?UTF-8?q?=EB=B2=BD=20=EB=B6=80=EC=88=98=EA=B3=A0?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" => "2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" (100%) diff --git "a/2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" "b/2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" similarity index 100% rename from "2023/08.25/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" rename to "2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260" From 2144e7ed53dade35cd6d4e3c16a8f1575e6d8df4 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:05:10 +0900 Subject: [PATCH 715/822] Create README.MD --- 2023/08.24/README.MD | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 2023/08.24/README.MD diff --git a/2023/08.24/README.MD b/2023/08.24/README.MD new file mode 100644 index 0000000..13cc333 --- /dev/null +++ b/2023/08.24/README.MD @@ -0,0 +1,8 @@ +# 8.14(목) 스터디 + +- 백준 + - [벽 부수고 이동하기](https://www.acmicpc.net/problem/2206) + - [벼락치기](https://www.acmicpc.net/problem/14728) + - [0 만들기](https://www.acmicpc.net/problem/7490) + - [친구 네트워크](https://www.acmicpc.net/problem/4195) + From 3381090e5e34e8830929afdac1dbf4d8e1f9041f Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:03:24 +0900 Subject: [PATCH 716/822] =?UTF-8?q?=EB=B2=BC=EB=9D=BD=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\274\353\235\275\354\271\230\352\270\260" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260" diff --git "a/2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260" "b/2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260" new file mode 100644 index 0000000..ef20797 --- /dev/null +++ "b/2023/08.24/\352\271\200\354\247\200\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260" @@ -0,0 +1,50 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + static int[][] dp; + static int N,T; + static int[][] units; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + T = Integer.parseInt(st.nextToken()); + units = new int[N+1][2]; + dp = new int[N+1][T+1]; + + for(int i=1;i<=N;i++){ + st = new StringTokenizer(br.readLine()); + units[i][0] = Integer.parseInt(st.nextToken()); + units[i][1] = Integer.parseInt(st.nextToken()); + } + + + + for(int i=1;i<=N;i++){ + for(int j=1;j<=T;j++){ + if(units[i][0]<=j){ + //이전 가치보다 큰 경우 + if(dp[i-1][j-units[i][0]] + units[i][1]>dp[i-1][j]){ + dp[i][j] = dp[i-1][j-units[i][0]] + units[i][1]; + }else{ + dp[i][j] = dp[i-1][j]; + } + }else{ + //준비할수 있는 시간이 더 작은 경우에는 이전값 그대로 + dp[i][j] = dp[i-1][j]; + } + + } + } + System.out.println(dp[N][T]); + + } + + + +} From 097b3f01e4e3206850c4254b33cf39a378907e0d Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 18 Aug 2023 17:50:18 +0900 Subject: [PATCH 717/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EC=B9=9C?= =?UTF-8?q?=EA=B5=AC=20=EB=84=A4=ED=8A=B8=EC=9B=8C=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44\355\212\270\354\233\214\355\201\254.kt" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "2023/08.24/\354\241\260\354\210\230\354\227\260/\354\271\234\352\265\254_\353\204\244\355\212\270\354\233\214\355\201\254.kt" diff --git "a/2023/08.24/\354\241\260\354\210\230\354\227\260/\354\271\234\352\265\254_\353\204\244\355\212\270\354\233\214\355\201\254.kt" "b/2023/08.24/\354\241\260\354\210\230\354\227\260/\354\271\234\352\265\254_\353\204\244\355\212\270\354\233\214\355\201\254.kt" new file mode 100644 index 0000000..1550579 --- /dev/null +++ "b/2023/08.24/\354\241\260\354\210\230\354\227\260/\354\271\234\352\265\254_\353\204\244\355\212\270\354\233\214\355\201\254.kt" @@ -0,0 +1,58 @@ +import java.io.* +import java.util.* +import kotlin.collections.HashMap + +lateinit var st: StringTokenizer +lateinit var relation: HashMap +lateinit var count: HashMap + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + val bw = BufferedWriter(OutputStreamWriter(System.out)) + + val t = readLine().toInt() + + repeat(t) { + val f = readLine().toInt() + relation = HashMap() + count = HashMap() + + repeat(f) { + st = StringTokenizer(readLine()) + + val p1 = st.nextToken() + val p2 = st.nextToken() + + relation.putIfAbsent(p1,p1) + count.putIfAbsent(p1,1) + + relation.putIfAbsent(p2,p2) + count.putIfAbsent(p2,1) + + union(p1,p2) + + bw.write("${count[find(p1)]!!}\n") + } + } + + bw.flush() + bw.close() +} + +/* 분리집합 */ +fun union(x: String, y: String) { + val nx = find(x) + val ny = find(y) + + if (nx != ny) { + relation[ny] = nx + count.replace(nx,count[ny]!! + count[nx]!!) + } +} + +fun find(x: String): String { + return if (relation[x] == x) x + else { + relation[x] = find(relation[x]!!) + relation[x]!! + } +} \ No newline at end of file From b82c648bdf9ece0c3f6908b70cf13ee5f0fb60f0 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 18 Aug 2023 19:27:11 +0900 Subject: [PATCH 718/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=200=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0_\353\247\214\353\223\244\352\270\260.kt" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "2023/08.24/\354\241\260\354\210\230\354\227\260/0_\353\247\214\353\223\244\352\270\260.kt" diff --git "a/2023/08.24/\354\241\260\354\210\230\354\227\260/0_\353\247\214\353\223\244\352\270\260.kt" "b/2023/08.24/\354\241\260\354\210\230\354\227\260/0_\353\247\214\353\223\244\352\270\260.kt" new file mode 100644 index 0000000..68ebba9 --- /dev/null +++ "b/2023/08.24/\354\241\260\354\210\230\354\227\260/0_\353\247\214\353\223\244\352\270\260.kt" @@ -0,0 +1,57 @@ +import java.io.* +import java.util.* +import kotlin.collections.ArrayList + +lateinit var bw: BufferedWriter +lateinit var expressList: ArrayList +val op = arrayOf("+", "-", " ") + +fun main() = with(BufferedReader(InputStreamReader(System.`in`))) { + bw = BufferedWriter(OutputStreamWriter(System.out)) + + val t = readLine().toInt() + + repeat(t) { + val n = readLine().toInt() + expressList = ArrayList() + + comb(n, 1, "1") + expressList.sort() + + for (express in expressList){ + bw.write("$express\n") + } + + bw.write("\n") + } + + bw.flush() + bw.close() +} + +fun comb(n: Int, size: Int, expression: String) { + if (size == n) { + val ex = expression.replace(" ", "") + if (calc(ex)) expressList.add(expression) + return + } + + for (i in 0 until 3) { + comb(n, size + 1, expression + op[i] + (size + 1)) + } +} + +fun calc(expression: String): Boolean { + val st = StringTokenizer(expression, "-|+", true) + var sum = st.nextToken().toInt() + + while (st.hasMoreTokens()) { + val s = st.nextToken() + + when (s) { + "+" -> sum += st.nextToken().toInt() + "-" -> sum -= st.nextToken().toInt() + } + } + return sum == 0 +} \ No newline at end of file From 621990279dba3dca709cfb68222f48e5e9f446a3 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:26:58 +0900 Subject: [PATCH 719/822] =?UTF-8?q?0=20=EB=A7=8C=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0 \353\247\214\353\223\244\352\270\260" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "2023/08.24/\352\271\200\354\247\200\355\233\210/0 \353\247\214\353\223\244\352\270\260" diff --git "a/2023/08.24/\352\271\200\354\247\200\355\233\210/0 \353\247\214\353\223\244\352\270\260" "b/2023/08.24/\352\271\200\354\247\200\355\233\210/0 \353\247\214\353\223\244\352\270\260" new file mode 100644 index 0000000..8ddb529 --- /dev/null +++ "b/2023/08.24/\352\271\200\354\247\200\355\233\210/0 \353\247\214\353\223\244\352\270\260" @@ -0,0 +1,58 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + static int N; + static String[] op = {"+","-"," "}; + static int[] nums; + static ArrayList res; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int TC = Integer.parseInt(br.readLine()); + + while(TC-->0){ + N = Integer.parseInt(br.readLine()); + nums = new int[N]; + for(int i=0;i(); + solve(1,String.valueOf(nums[0])); + Collections.sort(res); + for(String s : res) + System.out.println(s); + System.out.println(); + res.clear(); + } + } + static void solve(int depth,String expression){ + if(depth==N){ + String str = expression.replaceAll(" ",""); + if(isZero(str)){ + res.add(expression); + } + return ; + } + for(int i=0;i<3;i++) + solve(depth+1,expression+op[i]+nums[depth]); + + } + static boolean isZero(String str){ + String[] list = str.split("\\+|-"); + int opIndex = 1; + int sum = Integer.parseInt(list[0]); + for(int i=0;i Date: Tue, 22 Aug 2023 17:01:39 +0900 Subject: [PATCH 720/822] =?UTF-8?q?=EC=B9=9C=EA=B5=AC=20=EB=84=A4=ED=8A=B8?= =?UTF-8?q?=EC=9B=8C=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\244\355\212\270\354\233\214\355\201\254" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "2023/08.24/\352\271\200\354\247\200\355\233\210/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254" diff --git "a/2023/08.24/\352\271\200\354\247\200\355\233\210/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254" "b/2023/08.24/\352\271\200\354\247\200\355\233\210/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254" new file mode 100644 index 0000000..6a2fb66 --- /dev/null +++ "b/2023/08.24/\352\271\200\354\247\200\355\233\210/\354\271\234\352\265\254 \353\204\244\355\212\270\354\233\214\355\201\254" @@ -0,0 +1,60 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + static HashMap relations; + static int F; + static int[] counts; + static int[] parents; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int TC = Integer.parseInt(br.readLine()); + + while(TC-->0){ + F = Integer.parseInt(br.readLine()); + counts = new int[F*2+1]; + parents = new int[F*2+1]; + relations = new HashMap<>(F*2+1); + + for(int i=0;i Date: Wed, 23 Aug 2023 19:54:36 +0900 Subject: [PATCH 721/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EB=B2=BD?= =?UTF-8?q?=20=EB=B6=80=EC=88=98=EA=B3=A0=20=EC=9D=B4=EB=8F=99=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\217\231\355\225\230\352\270\260.java" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" diff --git "a/2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" new file mode 100644 index 0000000..a3c150b --- /dev/null +++ "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" @@ -0,0 +1,80 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/2206 +// BFS 탐색시 벽을 부쉈던 이력이 있는지 저장 +// visited를 3차원으로 정의하여 벽을 부순상태에서의 이동경로와 벽을 부수지 않은상태에서 이동경로를 구분. + +public class 벽부수고이동하기 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + LinkedList ll = new LinkedList(); + int[] dRow = {-1, 1, 0, 0}; + int[] dCol = {0, 0, -1, 1}; + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + char[][] map = new char[N][M]; + boolean[][][] visited = new boolean[N][M][2]; + int minValue = 1_000_000; + for (int i = 0; i < N; i++) { + String row = br.readLine(); + for (int j = 0; j < M; j++) { + map[i][j] = row.charAt(j); + } + } + ll.add(new Position(0, 0, 1, false)); + visited[0][0][0] = true; + while (!ll.isEmpty()) { + Position currentPosition = ll.pollFirst(); + // 출구 위치면 최소 거리 갱신 + if (currentPosition.row == N - 1 && currentPosition.col == M - 1) { + System.out.println(currentPosition.dist); + return; + } + for (int i = 0; i < 4; i++) { + int nRow = dRow[i] + currentPosition.row; + int nCol = dCol[i] + currentPosition.col; + if (!(0 <= nRow && nRow < N) || !(0 <= nCol && nCol < M)) { + continue; + } + if (map[nRow][nCol] == '0') { + // 벽부순적 없고 다음 공간이 방문한 적 없는 곳일때 + if (!currentPosition.isBroken && !visited[nRow][nCol][0]) { + visited[nRow][nCol][0] = true; + ll.add(new Position(nRow, nCol, currentPosition.dist + 1, false)); + } + // 이미 벽을 부순적이 있고 다음 공간이 방문한 적 없을 때 + else if (currentPosition.isBroken && !visited[nRow][nCol][1]) { + visited[nRow][nCol][1] = true; + ll.add(new Position(nRow, nCol, currentPosition.dist + 1, true)); + } + } else { + // 다음 위치가 벽이라면 부순적 없을때만 이동 가능 + if (!currentPosition.isBroken) { + visited[nRow][nCol][1] = true; + ll.add(new Position(nRow, nCol, currentPosition.dist + 1, true)); + } + } + } + } + System.out.println(-1); + } +} + +class Position { + int row; + int col; + int dist; + boolean isBroken; + + public Position(int row, int col, int dist, boolean isBroken) { + this.row = row; + this.col = col; + this.dist = dist; + this.isBroken = isBroken; + } +} From 6c6220abd6b6ad27c249863aab4e19d00d033dd8 Mon Sep 17 00:00:00 2001 From: "suyong5713@gmail.com" Date: Wed, 23 Aug 2023 19:54:57 +0900 Subject: [PATCH 722/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EB=B2=BC?= =?UTF-8?q?=EB=9D=BD=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\235\275\354\271\230\352\270\260.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\274\353\235\275\354\271\230\352\270\260.java" diff --git "a/2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\274\353\235\275\354\271\230\352\270\260.java" "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\274\353\235\275\354\271\230\352\270\260.java" new file mode 100644 index 0000000..23c55b1 --- /dev/null +++ "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\353\262\274\353\235\275\354\271\230\352\270\260.java" @@ -0,0 +1,49 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +// https://www.acmicpc.net/problem/14728 +// 단원을 공부하는데에 필요한 시간을 인덱스로 두고 해결 + +public class 벼락치기 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int T = Integer.parseInt(st.nextToken()); + Problem[] problems = new Problem[N]; + int[][] dp = new int[N][T + 1]; + for(int i = 0; i < N; i++){ + st = new StringTokenizer(br.readLine()); + int time = Integer.parseInt(st.nextToken()); + int score = Integer.parseInt(st.nextToken()); + problems[i] = new Problem(score, time); + } + for(int i = 0; i < N; i++){ + for(int j = 1; j <= T; j++){ + if(i == 0){ + if(j >= problems[i].time){ + dp[i][j] = problems[i].score; + } + continue; + } + if(j - problems[i].time >= 0){ + dp[i][j] = Math.max(dp[i-1][j],Math.max(dp[i-1][j - problems[i].time] + problems[i].score, dp[i][j - 1])); + }else{ + dp[i][j] = dp[i - 1][j]; + } + } + } + System.out.println(dp[N-1][T]); + } +} +class Problem{ + int score; + int time; + + public Problem(int score, int time) { + this.score = score; + this.time = time; + } +} From f775c6501d9b8f08ea91c1eb75e942f4ad269826 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 23 Aug 2023 21:56:26 +0900 Subject: [PATCH 723/822] 0824 kihun --- 2023/08.24/README.MD | 3 +- ...\353\235\275\354\271\230\352\270\260.java" | 52 ++++++++++ ...\353\217\231\355\225\230\352\270\260.java" | 97 +++++++++++++++++++ ...247\214\353\223\244\352\270\260_7490.java" | 38 ++++++++ ...\355\212\270\354\233\214\355\201\254.java" | 69 +++++++++++++ 5 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 "2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260.java" create mode 100644 "2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" create mode 100644 "2023/08.24/\354\206\241\352\270\260\355\233\210/\354\230\201\353\247\214\353\223\244\352\270\260_7490.java" create mode 100644 "2023/08.24/\354\206\241\352\270\260\355\233\210/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" diff --git a/2023/08.24/README.MD b/2023/08.24/README.MD index 13cc333..eb8f350 100644 --- a/2023/08.24/README.MD +++ b/2023/08.24/README.MD @@ -1,8 +1,7 @@ -# 8.14(목) 스터디 +# 8.24(목) 스터디 - 백준 - [벽 부수고 이동하기](https://www.acmicpc.net/problem/2206) - [벼락치기](https://www.acmicpc.net/problem/14728) - [0 만들기](https://www.acmicpc.net/problem/7490) - [친구 네트워크](https://www.acmicpc.net/problem/4195) - diff --git "a/2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260.java" "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260.java" new file mode 100644 index 0000000..7d827a2 --- /dev/null +++ "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\274\353\235\275\354\271\230\352\270\260.java" @@ -0,0 +1,52 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 벼락치기 { + + static int N, T; + static int[] kList, sList; + static int[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + T = Integer.parseInt(st.nextToken()); + + kList = new int[N + 1]; + sList = new int[N + 1]; + + int totalCost = 0; + + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + kList[i] = Integer.parseInt(st.nextToken()); + sList[i] = Integer.parseInt(st.nextToken()); + totalCost += kList[i]; + } + + int timeLimit = Math.min(T, totalCost); + + dp = new int[N + 1][timeLimit + 1]; + for (int i = 1; i <= N; i++) { + int k = kList[i]; + int s = sList[i]; + + for (int cost = 0; cost <= timeLimit; cost++) { + if (cost >= k) { + dp[i][cost] = Math.max(dp[i - 1][cost], dp[i - 1][cost - k] + s); + } else { + dp[i][cost] = dp[i - 1][cost]; + } + } + } + + System.out.println(dp[N][timeLimit]); + + } +} \ No newline at end of file diff --git "a/2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" new file mode 100644 index 0000000..b6bff95 --- /dev/null +++ "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" @@ -0,0 +1,97 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class 벽부수고이동하기 { + + static int N, M; + static int[][] matrix; + static boolean[][][] visited; + + static int[] dY = {1, 0, -1, 0}; + static int[] dX = {0, 1, 0, -1}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + matrix = new int[N][M]; + visited = new boolean[2][N][M]; + + for (int i = 0; i < N; i++) { + char[] c = br.readLine().toCharArray(); + for (int j = 0; j < M; j++) { + matrix[i][j] = Integer.parseInt(String.valueOf(c[j])); + } + } + + bfs(); + + } + + static void bfs() { + Queue queue = new LinkedList<>(); + queue.offer(new Point(0, 0, 1, false)); + + while (!queue.isEmpty()) { + Point p = queue.poll(); + + if (p.y == N-1 && p.x == M-1) { + System.out.println(p.dist); + return; + } + + for (int i = 0; i < 4; i++) { + int nY = p.y + dY[i]; + int nX = p.x + dX[i]; + + if (nY < 0 || nX < 0 || nY >= N || nX >= M) continue; + + // 벽 + if (matrix[nY][nX] == 1) { + if (!p.crash) { + queue.add(new Point(nY, nX, p.dist+1, true)); + visited[1][nY][nX] = true; + } + } + // 길 + else { + // 아직 안 부숨 + if (!p.crash && !visited[0][nY][nX]) { + queue.add(new Point(nY, nX, p.dist+1, false)); + visited[0][nY][nX] = true; + } + // 이미 벽을 부숨 + else if (p.crash && !visited[1][nY][nX]) { + queue.add(new Point(nY, nX, p.dist+1, true)); + visited[1][nY][nX] = true; + } + } + } + } + + System.out.println(-1); + } + + static class Point { + int y; + int x; + int dist; + boolean crash; + + public Point(int y, int x, int dist, boolean crash) { + this.y = y; + this.x = x; + this.dist = dist; + this.crash = crash; + } + } + +} \ No newline at end of file diff --git "a/2023/08.24/\354\206\241\352\270\260\355\233\210/\354\230\201\353\247\214\353\223\244\352\270\260_7490.java" "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\354\230\201\353\247\214\353\223\244\352\270\260_7490.java" new file mode 100644 index 0000000..eff2a3f --- /dev/null +++ "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\354\230\201\353\247\214\353\223\244\352\270\260_7490.java" @@ -0,0 +1,38 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 영만들기_7490 { + + static int N, T; + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + T = Integer.parseInt(br.readLine()); + for (int t = 0; t < T; t++) { + N = Integer.parseInt(br.readLine()); + dfs(1, 1, 0, 1, "1"); + sb.append("\n"); + } + System.out.println(sb); + } + + static void dfs(int depth, int now, int sum, int op, String eq) { + if (depth == N) { + sum += (now * op); + if (sum == 0) { + sb.append(eq + "\n"); + } + return; + } + + dfs(depth + 1, now * 10 + (depth + 1), sum, op, eq+" "+ (depth + 1)); + dfs(depth + 1, depth + 1, sum + (now*op), 1, eq+"+"+ (depth + 1)); + dfs(depth + 1, depth + 1, sum + (now*op), -1, eq+"-"+ (depth + 1)); + } + +} \ No newline at end of file diff --git "a/2023/08.24/\354\206\241\352\270\260\355\233\210/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" new file mode 100644 index 0000000..fc416af --- /dev/null +++ "b/2023/08.24/\354\206\241\352\270\260\355\233\210/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" @@ -0,0 +1,69 @@ +package baekjoon.gold.two; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.StringTokenizer; + +public class 친구네트워크 { + // 유니온 파인드 + // https://ssungkang.tistory.com/entry/Algorithm-%EC%9C%A0%EB%8B%88%EC%98%A8-%ED%8C%8C%EC%9D%B8%EB%93%9CUnion-Find + + static int T, F; + static int[] parent, count; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + T = Integer.parseInt(br.readLine()); + for (int t = 0; t < T; t++) { + F = Integer.parseInt(br.readLine()); + HashMap names = new HashMap<>(); + parent = new int[F * 2]; + count = new int[F * 2]; + Arrays.setAll(parent, i -> i); + Arrays.fill(count, 1); + int index = 0; + + for (int f = 0; f < F; f++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + String a = st.nextToken(); + String b = st.nextToken(); + if (!names.containsKey(a)) { + names.put(a, index); + index += 1; + } + if (!names.containsKey(b)) { + names.put(b, index); + index += 1; + } + union(names.get(a), names.get(b)); + System.out.println(count[find(names.get(b))]); + } + } + } + + static int find(int index) { + // 타고 타고 올라가서 부모 노드를 찾는다 + if (parent[index] == index) { + return index; + } else { + return parent[index] = find(parent[index]); + } + } + + static void union(int idxA, int idxB) { + int parentA = find(idxA); + int parentB = find(idxB); + + // 부모가 같으므로 이미 연결됨 + if (parentA == parentB) { + return; + } + + parent[Math.max(parentA, parentB)] = Math.min(parentA, parentB); + count[Math.min(parentA, parentB)] += count[Math.max(parentA, parentB)]; + } + +} \ No newline at end of file From fa650980657fbf04bef0258fcf9ec91d4067f655 Mon Sep 17 00:00:00 2001 From: Bucket <77010707+suyong5713@users.noreply.github.com> Date: Wed, 23 Aug 2023 22:11:29 +0900 Subject: [PATCH 724/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=200=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\341\206\257\341\204\200\341\205\265.java" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\213\341\205\247\341\206\274\341\204\206\341\205\241\341\206\253\341\204\203\341\205\263\341\206\257\341\204\200\341\205\265.java" diff --git "a/2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\213\341\205\247\341\206\274\341\204\206\341\205\241\341\206\253\341\204\203\341\205\263\341\206\257\341\204\200\341\205\265.java" "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\213\341\205\247\341\206\274\341\204\206\341\205\241\341\206\253\341\204\203\341\205\263\341\206\257\341\204\200\341\205\265.java" new file mode 100644 index 0000000..8bf1b85 --- /dev/null +++ "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\213\341\205\247\341\206\274\341\204\206\341\205\241\341\206\253\341\204\203\341\205\263\341\206\257\341\204\200\341\205\265.java" @@ -0,0 +1,33 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +// https://www.acmicpc.net/problem/7490 +public class 영만들기 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + int[] numList = new int[T]; + for(int t = 0; t < T; t++){ + numList[t] = Integer.parseInt(br.readLine()); + } + for(int n : numList){ + backTracking(1, 0, 1, n, 1, "1"); + System.out.println(); + } + + } + static void backTracking(int idx, int currentValue, int currentNum, int limit, int operator, String history){ + if(idx == limit){ + currentValue += (currentNum * operator); + if(currentValue == 0){ + System.out.println(history); + } + }else { + // 숫자를 이어붙이는 경우 지금 당장 계산하지 않고 숫자를 이어붙인 다음, 직전 연산이 +였는지 -였는지 다음 backTracking 에 넘겨줌 + backTracking(idx + 1, currentValue, (currentNum * 10) + (idx + 1), limit, operator, history + " " + (idx + 1)); + backTracking(idx + 1, currentValue + (currentNum * operator), idx + 1, limit, 1, history + "+" + (idx + 1)); + backTracking(idx + 1, currentValue + (currentNum * operator), idx + 1, limit, -1, history + "-" + (idx + 1)); + } + } +} From 64dcb97ad050e58459bba9ce333c26e169521d18 Mon Sep 17 00:00:00 2001 From: Bucket <77010707+suyong5713@users.noreply.github.com> Date: Wed, 23 Aug 2023 22:57:29 +0900 Subject: [PATCH 725/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EC=B9=9C?= =?UTF-8?q?=EA=B5=AC=20=EB=84=A4=ED=8A=B8=EC=9B=8C=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\341\205\257\341\204\217\341\205\263.java" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\216\341\205\265\341\206\253\341\204\200\341\205\256\341\204\202\341\205\246\341\204\220\341\205\263\341\204\213\341\205\257\341\204\217\341\205\263.java" diff --git "a/2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\216\341\205\265\341\206\253\341\204\200\341\205\256\341\204\202\341\205\246\341\204\220\341\205\263\341\204\213\341\205\257\341\204\217\341\205\263.java" "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\216\341\205\265\341\206\253\341\204\200\341\205\256\341\204\202\341\205\246\341\204\220\341\205\263\341\204\213\341\205\257\341\204\217\341\205\263.java" new file mode 100644 index 0000000..fb1db30 --- /dev/null +++ "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\341\204\216\341\205\265\341\206\253\341\204\200\341\205\256\341\204\202\341\205\246\341\204\220\341\205\263\341\204\213\341\205\257\341\204\217\341\205\263.java" @@ -0,0 +1,72 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.StringTokenizer; + +// 유니온 파인드 알고리즘 +// https://velog.io/@suk13574/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98Java-%EC%9C%A0%EB%8B%88%EC%98%A8-%ED%8C%8C%EC%9D%B8%EB%93%9CUnion-Find-%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 + +//https://www.acmicpc.net/problem/4195 + +class 친구네트워크 { + private static int T; + private static int F; + private static int[] parent; + private static int[] count; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + T = Integer.parseInt(br.readLine()); + StringBuilder sb = new StringBuilder(); + for(int t = 0; t < T; t++){ + F = Integer.parseInt(br.readLine()); + // 3개의 친구관계에서 모두다른 이름이 나오면 6명 + parent = new int[F * 2]; + count = new int[F * 2]; + for(int i = 0; i < F * 2; i++){ + parent[i] = i; + } + Arrays.fill(count, 1); + int index = 0; + HashMap map = new HashMap<>(); + for(int f = 0; f < F; f++){ + StringTokenizer st = new StringTokenizer(br.readLine()); + String friend1 = st.nextToken(); + String friend2 = st.nextToken(); + if(!map.containsKey(friend1)){ + map.put(friend1, index++); + } + if(!map.containsKey(friend2)){ + map.put(friend2, index++); + } + sb.append(union(map.get(friend1), map.get(friend2)) + "\n"); + } + } + System.out.println(sb); + + } + static int find(int x){ + if(parent[x] == x) return x; + else{ + return find(parent[x]); + } + } + + static int union(int a, int b){ + a = find(a); + b = find(b); + if(a == b){ + return count[a]; + } else if (a < b) { + // a가 b의 루트 노드가 됨 + parent[b] = a; + count[a] += count[b]; + return count[a]; + }else { + parent[a] = b; + count[b] += count[a]; + return count[b]; + } + } +} \ No newline at end of file From 84a1f194b0d0a33fee86c80ab5128d729974aef8 Mon Sep 17 00:00:00 2001 From: kosdjs Date: Thu, 24 Aug 2023 04:49:39 +0900 Subject: [PATCH 726/822] =?UTF-8?q?=EB=B2=BD=20=EB=B6=80=EC=88=98=EA=B3=A0?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99=ED=95=98=EA=B8=B0,=20=EB=B2=BC=EB=9D=BD?= =?UTF-8?q?=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\235\275\354\271\230\352\270\260.java" | 33 ++++++++ ...\353\217\231\355\225\230\352\270\260.java" | 75 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 "2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\274\353\235\275\354\271\230\352\270\260.java" create mode 100644 "2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" diff --git "a/2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\274\353\235\275\354\271\230\352\270\260.java" "b/2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\274\353\235\275\354\271\230\352\270\260.java" new file mode 100644 index 0000000..2e811ee --- /dev/null +++ "b/2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\274\353\235\275\354\271\230\352\270\260.java" @@ -0,0 +1,33 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int t = Integer.parseInt(st.nextToken()); + int chap[][] = new int[n+1][2];//0 time, 1 score + for(int i=1; i<=n; i++) { + st = new StringTokenizer(br.readLine()); + for(int j=0; j<2; j++) { + chap[i][j] = Integer.parseInt(st.nextToken()); + } + } + int dp[][] = new int[n+1][t+1]; + for(int i=1; i<=n; i++) { + for(int j=0; j<=t; j++) { + if(chap[i][0] <= j) { + dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - chap[i][0]] + chap[i][1]); + } else { + dp[i][j] = dp[i-1][j]; + } + } + } + System.out.println(dp[n][t]); + } + +} diff --git "a/2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" "b/2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" new file mode 100644 index 0000000..6fbaeb5 --- /dev/null +++ "b/2023/08.24/\354\206\241\352\264\200\354\236\254/\353\262\275\353\266\200\354\210\230\352\263\240\354\235\264\353\217\231\355\225\230\352\270\260.java" @@ -0,0 +1,75 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + int[] dx = {1, 0, -1, 0}; + int[] dy = {0, 1, 0, -1}; + + int[][] map = new int[n][m]; + for(int i=0; i q = new ArrayDeque(); + q.offer(new int[] {0, 0, 0});//x, y, wall + while(!q.isEmpty()) { + int[] now = q.poll(); + int x = now[0]; + int y = now[1]; + int wall = now[2]; + boolean condition = false; + for(int k=0; k<4; k++) { + int nx = now[0] + dx[k]; + int ny = now[1] + dy[k]; + if(nx < 0 || nx >= n || ny < 0 || ny >= m) { + continue; + } + + if(map[nx][ny] == 1) { + if(now[2] == 0 && !visit[nx][ny][1]) { + visit[nx][ny][1] = true; + dist[nx][ny] = dist[x][y] + 1; + q.offer(new int[] {nx, ny, 1}); + } + } + else { + if(!visit[nx][ny][wall]) { + visit[nx][ny][wall] = true; + dist[nx][ny] = dist[x][y] + 1; + q.offer(new int[] {nx, ny, wall}); + } + } + if(nx == n-1 && ny == m-1) { + System.out.println(dist[nx][ny]); + condition = true; + break; + } + } + if(condition) { + break; + } + } + if(n == 1 && m == 1) { + System.out.println(1); + } else if(q.isEmpty()) { + System.out.println(-1); + } + } +} From c781e62851d39bf63382f266eeca97a70fd1f56a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 24 Aug 2023 22:45:08 +0900 Subject: [PATCH 727/822] 0828 Readme.md --- 2023/08.28/Readme.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 2023/08.28/Readme.md diff --git a/2023/08.28/Readme.md b/2023/08.28/Readme.md new file mode 100644 index 0000000..e7cec02 --- /dev/null +++ b/2023/08.28/Readme.md @@ -0,0 +1,6 @@ +# 8.28(월) 스터디 + +- 백준 + - [내리막 길](https://www.acmicpc.net/problem/1520) + - [문자열 폭발](https://www.acmicpc.net/problem/9935) + - [타임머신](https://www.acmicpc.net/problem/11657) From e61fc7653c9881b26118451566bd68666b98ca73 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 25 Aug 2023 21:32:29 +0900 Subject: [PATCH 728/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=ED=83=80?= =?UTF-8?q?=EC=9E=84=EB=A8=B8=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\236\204\353\250\270\354\213\240.java" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "2023/08.28/\354\241\260\354\210\230\354\227\260/\355\203\200\354\236\204\353\250\270\354\213\240.java" diff --git "a/2023/08.28/\354\241\260\354\210\230\354\227\260/\355\203\200\354\236\204\353\250\270\354\213\240.java" "b/2023/08.28/\354\241\260\354\210\230\354\227\260/\355\203\200\354\236\204\353\250\270\354\213\240.java" new file mode 100644 index 0000000..bac3d50 --- /dev/null +++ "b/2023/08.28/\354\241\260\354\210\230\354\227\260/\355\203\200\354\236\204\353\250\270\354\213\240.java" @@ -0,0 +1,80 @@ +import java.io.*; +import java.util.*; + +class Edge { + int a; + int b; + int c; + + public Edge(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + } +} + +public class Main { + static ArrayList graph; + static final int INF = 1000000000; + static long[] dist; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + graph = new ArrayList<>(); + + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + graph.add(new Edge(a, b, c)); + } + + if (bellmanFord(n, m)) { + for (int i = 2; i <= n; i++) { + if (dist[i] == INF) bw.write("-1\n"); + else bw.write(dist[i] + "\n"); + } + } else bw.write("-1"); + + bw.flush(); + bw.close(); + } + + public static boolean bellmanFord(int n, int m) { + dist = new long[n + 1]; + + Arrays.fill(dist, INF); + dist[1] = 0; + + // 정점의 개수만큼 반복 + for (int i = 0; i < n; i++) { + // 간선의 개수만큼 반복 + for (int j = 0; j < m; j++) { + Edge e = graph.get(j); + // 최단거리 갱신 + if (dist[e.a] != INF && dist[e.b] > dist[e.a] + e.c) { + dist[e.b] = dist[e.a] + e.c; + } + } + } + + // 마지막으로 m개의 간선을 돌 때 변화가 있는지 확인 + for (int i = 0; i < m; i++) { + Edge e = graph.get(i); + + // 현재 최단거리에서 더 작은 값이 발생하면 음수 사이클 + if (dist[e.a] != INF && dist[e.b] > dist[e.a] + e.c) { + return false; + } + } + return true; + } +} \ No newline at end of file From c2793f87ee12a7018e9671ee3a2e03f88df8b926 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Sat, 26 Aug 2023 01:35:24 +0900 Subject: [PATCH 729/822] =?UTF-8?q?=EB=AC=B8=EC=9E=90=EC=97=B4=20=ED=8F=AD?= =?UTF-8?q?=EB=B0=9C=20solve(x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\220\354\227\264 \355\217\255\353\260\234" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "2023/08.28/\352\271\200\354\247\200\355\233\210/\353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234" diff --git "a/2023/08.28/\352\271\200\354\247\200\355\233\210/\353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234" "b/2023/08.28/\352\271\200\354\247\200\355\233\210/\353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234" new file mode 100644 index 0000000..2ece708 --- /dev/null +++ "b/2023/08.28/\352\271\200\354\247\200\355\233\210/\353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234" @@ -0,0 +1,43 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + + public static void main(String[] args) throws Exception { + BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); + String str = br.readLine(); + String pattern = br.readLine(); + int patternSize = pattern.length(); + + Stack stack = new Stack<>(); + + for(int i=0;i=patternSize){ + boolean flag = true; + + for(int j=0;j Date: Sat, 26 Aug 2023 11:49:21 +0900 Subject: [PATCH 730/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EB=82=B4?= =?UTF-8?q?=EB=A6=AC=EB=A7=89=20=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\246\254\353\247\211_\352\270\270.java" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "2023/08.28/\354\241\260\354\210\230\354\227\260/\353\202\264\353\246\254\353\247\211_\352\270\270.java" diff --git "a/2023/08.28/\354\241\260\354\210\230\354\227\260/\353\202\264\353\246\254\353\247\211_\352\270\270.java" "b/2023/08.28/\354\241\260\354\210\230\354\227\260/\353\202\264\353\246\254\353\247\211_\352\270\270.java" new file mode 100644 index 0000000..4f0c5f6 --- /dev/null +++ "b/2023/08.28/\354\241\260\354\210\230\354\227\260/\353\202\264\353\246\254\353\247\211_\352\270\270.java" @@ -0,0 +1,62 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int[][] dp; + static int[][] map; + static int n; + static int m; + static int[][] dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + + dp = new int[n + 1][m + 1]; + map = new int[n + 1][m + 1]; + + for (int i = 1; i <= n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 1; j <= m; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int i = 1; i <= n; i++) { + Arrays.fill(dp[i], 1, m+1, -1); + } + + bw.write(String.valueOf(dfs(1, 1))); + + bw.flush(); + bw.close(); + } + + public static int dfs(int x, int y) { + + // 경로를 찾은 경우 + if (x == m && y == n) return 1; + + // 해당 좌표에 경로가 있다면 경로의 갯수를 반환 + if (dp[y][x] != -1) return dp[y][x]; + + dp[y][x] = 0; // 탐색 시작 지점 초기화 + + for (int i = 0; i < 4; i++) { + int nx = dir[i][1] + x; + int ny = dir[i][0] + y; + + if (nx < 1 || nx > m || ny < 1 || ny > n) continue; + + if (map[y][x] > map[ny][nx]) { // 현재 좌표 경로의 갯수 += 다음 좌표에 경로의 갯수 + dp[y][x] += dfs(nx, ny); + } + } + return dp[y][x]; + } +} \ No newline at end of file From ecb4fc735dbdaf21c07daad362fee13307e34783 Mon Sep 17 00:00:00 2001 From: su6378 Date: Sat, 26 Aug 2023 14:48:29 +0900 Subject: [PATCH 731/822] =?UTF-8?q?[SOLVE]=20@josooyeon11:=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=ED=8F=AD=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\227\264_\355\217\255\353\260\234.java" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "2023/08.28/\354\241\260\354\210\230\354\227\260/\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.java" diff --git "a/2023/08.28/\354\241\260\354\210\230\354\227\260/\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.java" "b/2023/08.28/\354\241\260\354\210\230\354\227\260/\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.java" new file mode 100644 index 0000000..c2db9c6 --- /dev/null +++ "b/2023/08.28/\354\241\260\354\210\230\354\227\260/\353\254\270\354\236\220\354\227\264_\355\217\255\353\260\234.java" @@ -0,0 +1,48 @@ +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + String str = br.readLine(); + String pattern = br.readLine(); + Stack stack = new Stack<>(); + int len = pattern.length(); + + for (int i = 0; i < str.length(); i++) { + stack.add(str.charAt(i)); + + if (stack.size() >= len){ + boolean isFind = true; + + for (int j = 0; j < len; j++) { + if (stack.get(stack.size() - len + j) != pattern.charAt(j)){ // 패턴이 일치하지 않는 경우 + isFind = false; + break; + } + } + + if (isFind){ + for (int j = 0; j < len; j++) { + stack.pop(); + } + } + } + } + + StringBuilder sb = new StringBuilder(); + + for (Character c : stack){ + sb.append(c); + } + + if (stack.isEmpty()) bw.write("FRULA"); + else bw.write(sb.toString()); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From 83953c295945940e4ab4f4355b660c7c084ce8ca Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Sat, 26 Aug 2023 17:32:21 +0900 Subject: [PATCH 732/822] =?UTF-8?q?=EB=82=B4=EB=A6=AC=EB=A7=89=20=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\264\353\246\254\353\247\211 \352\270\270" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "2023/08.28/\352\271\200\354\247\200\355\233\210/\353\202\264\353\246\254\353\247\211 \352\270\270" diff --git "a/2023/08.28/\352\271\200\354\247\200\355\233\210/\353\202\264\353\246\254\353\247\211 \352\270\270" "b/2023/08.28/\352\271\200\354\247\200\355\233\210/\353\202\264\353\246\254\353\247\211 \352\270\270" new file mode 100644 index 0000000..6bf6725 --- /dev/null +++ "b/2023/08.28/\352\271\200\354\247\200\355\233\210/\353\202\264\353\246\254\353\247\211 \352\270\270" @@ -0,0 +1,58 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + + static int[][] map; + static int[][] dp; + static int[] dx={-1,0,1,0}; + static int[] dy={0,1,0,-1}; + static int M,N; + static int result; + + public static void main(String[] args) throws Exception { + BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st= new StringTokenizer(br.readLine()); + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + + map = new int[M][N]; + dp = new int[M][N]; + result = 0; + for(int i=0;imap[nx][ny]){ + dp[x][y]+=dfs(nx,ny); + } + } + } + return dp[x][y]; + } + + static boolean isRange(int x,int y){ + return x>=0&&y>=0&&x Date: Sat, 26 Aug 2023 17:32:48 +0900 Subject: [PATCH 733/822] =?UTF-8?q?=EB=AC=B8=EC=9E=90=EC=97=B4=20=ED=8F=AD?= =?UTF-8?q?=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 84c702c66ecdb0d70050f47bf72c0a2be691c390 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Sat, 26 Aug 2023 19:24:34 +0900 Subject: [PATCH 734/822] =?UTF-8?q?=ED=83=80=EC=9E=84=EB=A8=B8=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3\200\354\236\204\353\250\270\354\213\240" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "2023/08.28/\352\271\200\354\247\200\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240" diff --git "a/2023/08.28/\352\271\200\354\247\200\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240" "b/2023/08.28/\352\271\200\354\247\200\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240" new file mode 100644 index 0000000..6af10ee --- /dev/null +++ "b/2023/08.28/\352\271\200\354\247\200\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240" @@ -0,0 +1,72 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + static class Node{ + int v; + int w; + int cost; + + public Node(int v, int w, int cost) { + this.v = v; + this.w = w; + this.cost = cost; + } + } + static ArrayList graph; + static int N,M; + static final int INF = 500 * 10000; + static long[] dist; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + dist = new long[N+1]; + Arrays.fill(dist,INF); + graph = new ArrayList<>(); + + for(int i=0;idist[now.v]+now.cost){ + dist[now.w] = dist[now.v]+now.cost; + } + + } + } + for(int i=0;idist[now.v]+now.cost){ + return false; + } + } + return true; + } +} From 9c0aef3aff6376efd29879c429f8425f1afbea49 Mon Sep 17 00:00:00 2001 From: "suyong5713@gmail.com" Date: Sun, 27 Aug 2023 16:49:53 +0900 Subject: [PATCH 735/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EB=82=B4?= =?UTF-8?q?=EB=A6=AC=EB=A7=89=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\247\214\353\223\244\352\270\260.java" | 33 +++++++++ ...\355\212\270\354\233\214\355\201\254.java" | 72 +++++++++++++++++++ ...\353\246\254\353\247\211\352\270\270.java" | 53 ++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 "2023/08.24/\354\235\264\354\210\230\354\232\251/\354\230\201\353\247\214\353\223\244\352\270\260.java" create mode 100644 "2023/08.24/\354\235\264\354\210\230\354\232\251/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" create mode 100644 "2023/08.28/\354\235\264\354\210\230\354\232\251/\353\202\264\353\246\254\353\247\211\352\270\270.java" diff --git "a/2023/08.24/\354\235\264\354\210\230\354\232\251/\354\230\201\353\247\214\353\223\244\352\270\260.java" "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\354\230\201\353\247\214\353\223\244\352\270\260.java" new file mode 100644 index 0000000..8bf1b85 --- /dev/null +++ "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\354\230\201\353\247\214\353\223\244\352\270\260.java" @@ -0,0 +1,33 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +// https://www.acmicpc.net/problem/7490 +public class 영만들기 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + int[] numList = new int[T]; + for(int t = 0; t < T; t++){ + numList[t] = Integer.parseInt(br.readLine()); + } + for(int n : numList){ + backTracking(1, 0, 1, n, 1, "1"); + System.out.println(); + } + + } + static void backTracking(int idx, int currentValue, int currentNum, int limit, int operator, String history){ + if(idx == limit){ + currentValue += (currentNum * operator); + if(currentValue == 0){ + System.out.println(history); + } + }else { + // 숫자를 이어붙이는 경우 지금 당장 계산하지 않고 숫자를 이어붙인 다음, 직전 연산이 +였는지 -였는지 다음 backTracking 에 넘겨줌 + backTracking(idx + 1, currentValue, (currentNum * 10) + (idx + 1), limit, operator, history + " " + (idx + 1)); + backTracking(idx + 1, currentValue + (currentNum * operator), idx + 1, limit, 1, history + "+" + (idx + 1)); + backTracking(idx + 1, currentValue + (currentNum * operator), idx + 1, limit, -1, history + "-" + (idx + 1)); + } + } +} diff --git "a/2023/08.24/\354\235\264\354\210\230\354\232\251/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" new file mode 100644 index 0000000..fb1db30 --- /dev/null +++ "b/2023/08.24/\354\235\264\354\210\230\354\232\251/\354\271\234\352\265\254\353\204\244\355\212\270\354\233\214\355\201\254.java" @@ -0,0 +1,72 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.StringTokenizer; + +// 유니온 파인드 알고리즘 +// https://velog.io/@suk13574/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98Java-%EC%9C%A0%EB%8B%88%EC%98%A8-%ED%8C%8C%EC%9D%B8%EB%93%9CUnion-Find-%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 + +//https://www.acmicpc.net/problem/4195 + +class 친구네트워크 { + private static int T; + private static int F; + private static int[] parent; + private static int[] count; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + T = Integer.parseInt(br.readLine()); + StringBuilder sb = new StringBuilder(); + for(int t = 0; t < T; t++){ + F = Integer.parseInt(br.readLine()); + // 3개의 친구관계에서 모두다른 이름이 나오면 6명 + parent = new int[F * 2]; + count = new int[F * 2]; + for(int i = 0; i < F * 2; i++){ + parent[i] = i; + } + Arrays.fill(count, 1); + int index = 0; + HashMap map = new HashMap<>(); + for(int f = 0; f < F; f++){ + StringTokenizer st = new StringTokenizer(br.readLine()); + String friend1 = st.nextToken(); + String friend2 = st.nextToken(); + if(!map.containsKey(friend1)){ + map.put(friend1, index++); + } + if(!map.containsKey(friend2)){ + map.put(friend2, index++); + } + sb.append(union(map.get(friend1), map.get(friend2)) + "\n"); + } + } + System.out.println(sb); + + } + static int find(int x){ + if(parent[x] == x) return x; + else{ + return find(parent[x]); + } + } + + static int union(int a, int b){ + a = find(a); + b = find(b); + if(a == b){ + return count[a]; + } else if (a < b) { + // a가 b의 루트 노드가 됨 + parent[b] = a; + count[a] += count[b]; + return count[a]; + }else { + parent[a] = b; + count[b] += count[a]; + return count[b]; + } + } +} \ No newline at end of file diff --git "a/2023/08.28/\354\235\264\354\210\230\354\232\251/\353\202\264\353\246\254\353\247\211\352\270\270.java" "b/2023/08.28/\354\235\264\354\210\230\354\232\251/\353\202\264\353\246\254\353\247\211\352\270\270.java" new file mode 100644 index 0000000..c9ba042 --- /dev/null +++ "b/2023/08.28/\354\235\264\354\210\230\354\232\251/\353\202\264\353\246\254\353\247\211\352\270\270.java" @@ -0,0 +1,53 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 내리막길 { + static int[][] dp; + static int[][] map; + static int N; + static int M; + static int[] dRow = {1, -1, 0, 0}; + static int[] dCol = {0, 0, 1, -1}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + map = new int[M][N]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + dp = new int[M][N]; + for(int i = 0; i < M; i++){ + Arrays.fill(dp[i], -1); + } + + System.out.println(DFS(0,0)); + + } + static int DFS(int row, int col){ + if(row == M - 1 && col == N - 1) return 1; + if(dp[row][col] != -1){ + return dp[row][col]; + } + // 한번도 방문한적 없는 위치라면 0으로 초기화 후 계산 + dp[row][col] = 0; + for(int i = 0; i < 4; i++){ + int nRow = row + dRow[i]; + int nCol = col + dCol[i]; + if(nRow < 0 || nRow >= M || nCol < 0 || nCol >= N) continue; + if(map[nRow][nCol] < map[row][col]){ + dp[row][col] += DFS(nRow,nCol); + } + } + return dp[row][col]; + } +} \ No newline at end of file From c81fac601adcd7ff70347f41dbf3d751d602c535 Mon Sep 17 00:00:00 2001 From: suyong5713 Date: Sun, 27 Aug 2023 18:00:08 +0900 Subject: [PATCH 736/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=ED=8F=AD=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\227\264\355\217\255\353\260\234.java" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "2023/08.28/\354\235\264\354\210\230\354\232\251/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" diff --git "a/2023/08.28/\354\235\264\354\210\230\354\232\251/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" "b/2023/08.28/\354\235\264\354\210\230\354\232\251/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" new file mode 100644 index 0000000..0ab00a1 --- /dev/null +++ "b/2023/08.28/\354\235\264\354\210\230\354\232\251/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" @@ -0,0 +1,37 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +public class 문자열폭발 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String string = br.readLine(); + String bomb = br.readLine(); + Stack stack = new Stack(); + for(int i = 0; i < string.length(); i++){ + stack.push(string.charAt(i)); + boolean flag = true; + if(stack.size() >= bomb.length()){ + int startIndex = stack.size() - bomb.length(); + for(int j = 0; j < bomb.length(); j++){ + if(stack.get(startIndex + j) != bomb.charAt(j)){ + flag = false; + break; + } + } + if(flag) { + for (int j = 0; j < bomb.length(); j++) { + stack.pop(); + } + } + } + } + StringBuilder sb = new StringBuilder(); + for(char chr: stack){ + sb.append(chr); + } + if(sb.length() > 0) System.out.println(sb); + else System.out.println("FRULA"); + } +} From 7fc27910400a752dfd5067a5176c1ee85fda0d5f Mon Sep 17 00:00:00 2001 From: suyong5713 Date: Sun, 27 Aug 2023 19:08:17 +0900 Subject: [PATCH 737/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=ED=83=80?= =?UTF-8?q?=EC=9E=84=EB=A8=B8=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\236\204\353\250\270\354\213\240.java" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "2023/08.28/\354\235\264\354\210\230\354\232\251/\355\203\200\354\236\204\353\250\270\354\213\240.java" diff --git "a/2023/08.28/\354\235\264\354\210\230\354\232\251/\355\203\200\354\236\204\353\250\270\354\213\240.java" "b/2023/08.28/\354\235\264\354\210\230\354\232\251/\355\203\200\354\236\204\353\250\270\354\213\240.java" new file mode 100644 index 0000000..37a60bb --- /dev/null +++ "b/2023/08.28/\354\235\264\354\210\230\354\232\251/\355\203\200\354\236\204\353\250\270\354\213\240.java" @@ -0,0 +1,53 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 타임머신 { + static int N; + static int M; + static long[] distList; + static int[] startList; + static int[] endList; + static int[] timeList; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + startList = new int[M]; + endList = new int[M]; + timeList = new int[M]; + distList = new long[N + 1]; + // 도시 500개에 대하여 노선 6천개, 최대시간 10000이므로 모든 버스노선 소요시간이 10000일때 30_000_000_000 이므로 최대값을 long타입 지정 + Arrays.fill(distList, Long.MAX_VALUE); + for(int i = 0; i < M; i++){ + st = new StringTokenizer(br.readLine()); + startList[i] = Integer.parseInt(st.nextToken()); + endList[i] = Integer.parseInt(st.nextToken()); + timeList[i] = Integer.parseInt(st.nextToken()); + } + distList[1] = 0; + boolean negativeCycle = false; + for(int i = 0; i < N; i++){ + for(int j = 0; j < M; j++){ + if(distList[startList[j]] != Integer.MAX_VALUE && distList[endList[j]] > distList[startList[j]] + timeList[j]){ + distList[endList[j]] = distList[startList[j]] + timeList[j]; + if(i == N - 1){ + negativeCycle = true; + } + } + } + } + if(negativeCycle){ + System.out.println(-1); + }else{ + for(int i = 2; i <= N; i++){ + if(distList[i] == Long.MAX_VALUE) + System.out.println(-1); + else System.out.println(distList[i]); + } + } + } +} From 2f2f9280d2f54f951e745d82ef46d17b566bac74 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 27 Aug 2023 21:50:47 +0900 Subject: [PATCH 738/822] 0828 kihun --- ...\353\246\254\353\247\211\352\270\270.java" | 65 ++++++++++++++ ...\354\227\264\355\217\255\353\260\234.java" | 31 +++++++ ...\354\236\204\353\250\270\354\213\240.java" | 87 +++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 "2023/08.28/\354\206\241\352\270\260\355\233\210/\353\202\264\353\246\254\353\247\211\352\270\270.java" create mode 100644 "2023/08.28/\354\206\241\352\270\260\355\233\210/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" create mode 100644 "2023/08.28/\354\206\241\352\270\260\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240.java" diff --git "a/2023/08.28/\354\206\241\352\270\260\355\233\210/\353\202\264\353\246\254\353\247\211\352\270\270.java" "b/2023/08.28/\354\206\241\352\270\260\355\233\210/\353\202\264\353\246\254\353\247\211\352\270\270.java" new file mode 100644 index 0000000..7e5b21d --- /dev/null +++ "b/2023/08.28/\354\206\241\352\270\260\355\233\210/\353\202\264\353\246\254\353\247\211\352\270\270.java" @@ -0,0 +1,65 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 내리막길 { + + static int[] dY = {1, 0, -1, 0}; + static int[] dX = {0, 1, 0, -1}; + static int M, N; + static int[][] matrix; + static int[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + matrix = new int[M][N]; + dp = new int[M][N]; + for (int i = 0; i < M; i++) { + Arrays.fill(dp[i], -1); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + matrix[i][j] = Integer.parseInt(st.nextToken()); + } + } + + dfs(0, 0); + + System.out.println(dp[0][0]); + + } + + static int dfs(int y, int x) { + + if (y == M-1 && x == N-1) return 1; + + dp[y][x] = 0; + for (int i = 0; i < 4; i++) { + int nY = y + dY[i]; + int nX = x + dX[i]; + + if (nY < 0 || nX < 0 || nY >= M || nX >= N) continue; + + if (matrix[nY][nX] < matrix[y][x]) { + // 이미 방문 했으면 더해주기 + if (dp[nY][nX] != -1) { + dp[y][x] += dp[nY][nX]; + } else { + dp[y][x] += dfs(nY, nX); + } + } + } + + return dp[y][x]; + } +} \ No newline at end of file diff --git "a/2023/08.28/\354\206\241\352\270\260\355\233\210/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" "b/2023/08.28/\354\206\241\352\270\260\355\233\210/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" new file mode 100644 index 0000000..e9866e3 --- /dev/null +++ "b/2023/08.28/\354\206\241\352\270\260\355\233\210/\353\254\270\354\236\220\354\227\264\355\217\255\353\260\234.java" @@ -0,0 +1,31 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 문자열폭발 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String inputString = br.readLine(); + String bomb = br.readLine(); + int bombLength = bomb.length(); + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < inputString.length(); i++) { + sb.append(inputString.charAt(i)); + if (sb.length() >= bombLength && + sb.substring(sb.length() - bombLength).equals(bomb) + ) { + sb.setLength(sb.length() - bombLength); + } + } + + if (sb.length() == 0) { + System.out.println("FRULA"); + } else { + System.out.println(sb); + } + } +} \ No newline at end of file diff --git "a/2023/08.28/\354\206\241\352\270\260\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240.java" "b/2023/08.28/\354\206\241\352\270\260\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240.java" new file mode 100644 index 0000000..19f2694 --- /dev/null +++ "b/2023/08.28/\354\206\241\352\270\260\355\233\210/\355\203\200\354\236\204\353\250\270\354\213\240.java" @@ -0,0 +1,87 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 타임머신 { + + static class Node { + int start; + int end; + int weight; + + public Node(int start, int end, int weight) { + this.start = start; + this.end = end; + this.weight = weight; + } + } + + static int N, M; + static Node[] nodes; + static long[] distances; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + nodes = new Node[M]; + distances = new long[N + 1]; + Arrays.fill(distances, Integer.MAX_VALUE); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + nodes[i] = new Node(a, b, c); + } + + if (bellmanFord()) { + System.out.println(-1); + } else { + for (int i = 2; i <= N; i++) { + if (distances[i] == Integer.MAX_VALUE) { + System.out.println(-1); + } else { + System.out.println(distances[i]); + } + } + } + } + + static boolean bellmanFord() { + distances[1] = 0; // 시작점은 0 + + for (int i = 1; i <= N; i++) { + + for (int j = 0; j < M; j++) { + int start = nodes[j].start; + int end = nodes[j].end; + int weight = nodes[j].weight; + + if (distances[start] == Integer.MAX_VALUE) continue; + + if (distances[end] > (distances[start] + weight)) { + distances[end] = distances[start] + weight; + + // N번째에서 값이 갱신된다면 음수 순환 존재 + if (i == N) { + return true; + } + } + + } + } + + return false; + } + +} From 304ef8a9360175852bf1f8d1bc9af8a1c21ab6e6 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:18:04 +0900 Subject: [PATCH 739/822] =?UTF-8?q?=EB=82=B4=EB=A0=A4=EA=B0=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\264\353\240\244\352\260\200\352\270\260" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" diff --git "a/2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" "b/2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" new file mode 100644 index 0000000..be3ca6d --- /dev/null +++ "b/2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" @@ -0,0 +1,53 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + + static int N; + static int[][] nums; + static int[][][] dp; + static int max,min; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st; + N = Integer.parseInt(br.readLine()); + nums = new int[N][3]; + dp = new int[N][3][2]; + for(int i=0;i Date: Mon, 28 Aug 2023 21:19:20 +0900 Subject: [PATCH 740/822] Create README.md --- "2023/0831/\352\271\200\354\247\200\355\233\210/README.md" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "2023/0831/\352\271\200\354\247\200\355\233\210/README.md" diff --git "a/2023/0831/\352\271\200\354\247\200\355\233\210/README.md" "b/2023/0831/\352\271\200\354\247\200\355\233\210/README.md" new file mode 100644 index 0000000..3a5b357 --- /dev/null +++ "b/2023/0831/\352\271\200\354\247\200\355\233\210/README.md" @@ -0,0 +1,5 @@ +# 8.31(목) 스터디 + +- 백준 + - [내려가기](https://www.acmicpc.net/problem/2096) + - [스티커 붙이기](https://www.acmicpc.net/problem/18808) From a43a3e10ea783095d1eff6b44e8c4e2834cc6912 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:19:56 +0900 Subject: [PATCH 741/822] Create README.md --- .../README.md" => 2023/0831/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "2023/0831/\352\271\200\354\247\200\355\233\210/README.md" => 2023/0831/README.md (100%) diff --git "a/2023/0831/\352\271\200\354\247\200\355\233\210/README.md" b/2023/0831/README.md similarity index 100% rename from "2023/0831/\352\271\200\354\247\200\355\233\210/README.md" rename to 2023/0831/README.md From c1dc1484a2b2fa521d6316220f95df51c533f25c Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Tue, 29 Aug 2023 15:00:58 +0900 Subject: [PATCH 742/822] dir name change --- 2023/{0831 => 08.31}/README.md | 0 .../\353\202\264\353\240\244\352\260\200\352\270\260" | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename 2023/{0831 => 08.31}/README.md (100%) rename "2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" => "2023/08.31/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" (100%) diff --git a/2023/0831/README.md b/2023/08.31/README.md similarity index 100% rename from 2023/0831/README.md rename to 2023/08.31/README.md diff --git "a/2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" "b/2023/08.31/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" similarity index 100% rename from "2023/0831/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" rename to "2023/08.31/\352\271\200\354\247\200\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260" From 3a61adf95ffc19f41c804949e35183b79ccbb902 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:11:35 +0900 Subject: [PATCH 743/822] =?UTF-8?q?Create=20=EB=82=B4=EB=A0=A4=EA=B0=80?= =?UTF-8?q?=EA=B8=B0.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\240\244\352\260\200\352\270\260.java" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "2023/08.31/\354\240\225\355\230\270\354\241\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" diff --git "a/2023/08.31/\354\240\225\355\230\270\354\241\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" "b/2023/08.31/\354\240\225\355\230\270\354\241\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" new file mode 100644 index 0000000..d49ad70 --- /dev/null +++ "b/2023/08.31/\354\240\225\355\230\270\354\241\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" @@ -0,0 +1,64 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/** + * 'RGB거리(1149번)과 비슷한 유형의 문제 + * 최댓값과 최솟값을 저장할 배열을 만들고, i행 값에 i-1행의 값을 조건에 따라 누적 + * */ + +public class 내려가기_2096 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + + int[][] max = new int[N][3]; + int[][] min = new int[N][3]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + int value = Integer.parseInt(st.nextToken()); + max[i][j] = value; + min[i][j] = value; + } + } + + for (int i = 1; i < N; i++) { + for (int j = 0; j < 3; j++) { + if (j == 0 || j == 2) { + int maxA = max[i][j] + max[i - 1][j]; + int maxB = max[i][j] + max[i - 1][1]; + + int minA = min[i][j] + min[i - 1][j]; + int minB = min[i][j] + min[i - 1][1]; + + max[i][j] = Math.max(maxA, maxB); + min[i][j] = Math.min(minA, minB); + } else { + int maxTemp = max[i][j]; //아래 for문 돌 때 max와 min 값이 변하므로 임시 저장해둠 + int minTemp = min[i][j]; + min[i][1] += min[i - 1][0]; //최초 한 번 더해줘야 최솟값 비교 가능 + + for (int k = 0; k < 3; k++) { + max[i][j] = Math.max(max[i][j], maxTemp + max[i - 1][k]); + min[i][j] = Math.min(min[i][j], minTemp + min[i - 1][k]); + } + } + } + } + + int maxResult = 0; + int minResult = Integer.MAX_VALUE; + + for (int i = 0; i < 3; i++) { + maxResult = Math.max(maxResult, max[N - 1][i]); + minResult = Math.min(minResult, min[N - 1][i]); + } + + System.out.println(maxResult + " " + minResult); + } +} From 98c74ade56aa329a0d695d4d2cdb03f9e64f1506 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:38:13 +0900 Subject: [PATCH 744/822] =?UTF-8?q?=EC=8A=A4=ED=8B=B0=EC=BB=A4=20=EB=B6=99?= =?UTF-8?q?=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\244 \353\266\231\354\235\264\352\270\260" | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 "2023/08.31/\352\271\200\354\247\200\355\233\210/\354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260" diff --git "a/2023/08.31/\352\271\200\354\247\200\355\233\210/\354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260" "b/2023/08.31/\352\271\200\354\247\200\355\233\210/\354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260" new file mode 100644 index 0000000..fca1f11 --- /dev/null +++ "b/2023/08.31/\352\271\200\354\247\200\355\233\210/\354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260" @@ -0,0 +1,161 @@ + + +import java.io.*; +import java.util.*; + + +class Main{ + + + static int N,M,K,R,C; + static int[][] notebook; + static int[][] stickers; + static int count; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + notebook = new int[N][M]; + count =0; + while(K-->0){ + st = new StringTokenizer(br.readLine()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + stickers = new int[R][C]; + for(int i=0;i=N||c+j>=M) { + flag = false; + break; + } + if(arr[i][j]==1&¬ebook[i+r][j+c]==1){ + flag = false; + break; + } + } + } + //붙는 경우 + if(flag) break; + //안붙는 경우 + else{ + //한칸식 다밀어봐도 안되는경우 + if(r>=N) return false; + else{ + if(c>=M){ + r++; + c=0; + }else{ + c++; + } + } + } + } + + + //노트북에 스티커 붙이기 + for(int i=0;i Date: Wed, 30 Aug 2023 21:08:42 +0900 Subject: [PATCH 745/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EB=82=B4?= =?UTF-8?q?=EB=A0=A4=EA=B0=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\240\244\352\260\200\352\270\260.java" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "2023/08.31/\354\235\264\354\210\230\354\232\251/\353\202\264\353\240\244\352\260\200\352\270\260.java" diff --git "a/2023/08.31/\354\235\264\354\210\230\354\232\251/\353\202\264\353\240\244\352\260\200\352\270\260.java" "b/2023/08.31/\354\235\264\354\210\230\354\232\251/\353\202\264\353\240\244\352\260\200\352\270\260.java" new file mode 100644 index 0000000..83cd5ed --- /dev/null +++ "b/2023/08.31/\354\235\264\354\210\230\354\232\251/\353\202\264\353\240\244\352\260\200\352\270\260.java" @@ -0,0 +1,50 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 내려가기 { + static int N; + static int[][] lineList; + static int[][] maxDp; + static int[][] minDp; + static int maxAnswer = 0; + static int minAnswer = 900_000; + private static final int MAX_VALUE = 900_000; + private static final int MIN_VALUE = -900_000; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + lineList = new int[N][3]; + maxDp = new int[N][3]; + minDp = new int[N][3]; + for(int i = 0; i < N; i++){ + StringTokenizer st = new StringTokenizer(br.readLine()); + for(int j = 0; j < 3; j++){ + lineList[i][j] = Integer.parseInt(st.nextToken()); + } + } + for(int i = 0; i < 3; i++){ + maxDp[0][i] = lineList[0][i]; + minDp[0][i] = lineList[0][i]; + } + for(int i = 1; i < N; i++){ + int maxOneTwo = Math.max(maxDp[i-1][0], maxDp[i-1][1]); + int maxTwoThree = Math.max(maxDp[i-1][1], maxDp[i-1][2]); + int maxOneTwoThree = Math.max(maxDp[i-1][2], Math.max(maxDp[i-1][0], maxDp[i-1][1])); + int minOneTwo = Math.min(minDp[i-1][0], minDp[i-1][1]); + int minTwoThree = Math.min(minDp[i-1][1], minDp[i-1][2]); + int minOneTwoThree = Math.min(minDp[i-1][2], Math.min(minDp[i-1][0], minDp[i-1][1])); + maxDp[i][0] = lineList[i][0] + maxOneTwo; + minDp[i][0] = lineList[i][0] + minOneTwo; + maxDp[i][1] = lineList[i][1] + maxOneTwoThree; + minDp[i][1] = lineList[i][1] + minOneTwoThree; + maxDp[i][2] = lineList[i][2] + maxTwoThree; + minDp[i][2] = lineList[i][2] + minTwoThree; + } + maxAnswer = Math.max(maxAnswer, Arrays.stream(maxDp[N-1]).max().getAsInt()); + minAnswer = Math.min(minAnswer, Arrays.stream(minDp[N-1]).min().getAsInt()); + System.out.printf("%d %d", maxAnswer, minAnswer); + } +} From 5fc8eb1287ff6e21e59cbce23f7f017853bb327a Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 31 Aug 2023 11:40:06 +0900 Subject: [PATCH 746/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20=EB=B6=99=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\266\231\354\235\264\352\270\260.java" | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 "2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" diff --git "a/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" "b/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" new file mode 100644 index 0000000..7b18002 --- /dev/null +++ "b/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" @@ -0,0 +1,118 @@ +import java.io.*; +import java.util.*; + +public class Main { + static final int DEGREE = 90; + static int[][] notebook; + static int[][] rotateSticker; + static List directions; + static int answer = 0; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + notebook = new int[n][m]; + + for (int i = 0; i < k; i++) { + st = new StringTokenizer(br.readLine()); + int r = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + int[][] sticker = new int[r][c]; + + for (int j = 0; j < r; j++) { + st = new StringTokenizer(br.readLine()); + + for (int l = 0; l < c; l++) { + sticker[j][l] = Integer.parseInt(st.nextToken()); + } + } + + directions = new ArrayList<>(); + + for (int j = 0; j < 4; j++) { + rotate(sticker, r, c, DEGREE * j); + if (stick()) break; // 붙일 수 있으면 종료 + } + } + + bw.write(String.valueOf(answer)); + + bw.flush(); + bw.close(); + } + + static void rotate(int[][] sticker, int r, int c, int degree) { + switch (degree) { // 각도에 따른 스티커 배열 생성 + case 90: + case 270: + rotateSticker = new int[c][r]; + break; + case 0: + case 180: + rotateSticker = new int[r][c]; + break; + } + + for (int i = 0; i < rotateSticker.length; i++) { // 회전 시킨 값 할당 + for (int j = 0; j < rotateSticker[0].length; j++) { + switch (degree) { + case 0: + rotateSticker[i][j] = sticker[i][j]; + break; + case 90: + rotateSticker[i][j] = sticker[r - 1 - j][i]; + break; + case 180: + rotateSticker[i][j] = sticker[r - 1 - i][c - 1 - j]; + break; + case 270: + rotateSticker[i][j] = sticker[j][c - 1 - i]; + break; + } + } + } + } + + static boolean stick() { + for (int i = 0; i < notebook.length; i++) { + for (int j = 0; j < notebook[0].length; j++) { + if (search(j, i)) return true; + } + } + return false; + } + + static boolean search(int x, int y) { + int n = notebook.length; + int m = notebook[0].length; + int r = rotateSticker.length; + int c = rotateSticker[0].length; + + if (x + c > m || y + r > n) return false; // 범위를 벗어나면 종료 + + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (rotateSticker[i][j] == 1 && notebook[i + y][j + x] == 1) { // 스티커를 붙일 벽이 1이라면 종료 + return false; + } + } + } + + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + if (rotateSticker[i][j] == 1) { + notebook[i + y][j + x] = 1; + answer++; + } + } + } + return true; + } +} \ No newline at end of file From deb247c6bb1c1f8ef09f1a49724522ebf1bdffb5 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 31 Aug 2023 11:42:31 +0900 Subject: [PATCH 747/822] =?UTF-8?q?[MOD]=20@josooyeon11=20:=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20=EB=B6=99=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" | 3 --- 1 file changed, 3 deletions(-) diff --git "a/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" "b/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" index 7b18002..7c34011 100644 --- "a/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" +++ "b/2023/08.31/\354\241\260\354\210\230\354\227\260/\354\212\244\355\213\260\354\273\244_\353\266\231\354\235\264\352\270\260.java" @@ -5,7 +5,6 @@ public class Main { static final int DEGREE = 90; static int[][] notebook; static int[][] rotateSticker; - static List directions; static int answer = 0; public static void main(String[] args) throws Exception { @@ -34,8 +33,6 @@ public static void main(String[] args) throws Exception { } } - directions = new ArrayList<>(); - for (int j = 0; j < 4; j++) { rotate(sticker, r, c, DEGREE * j); if (stick()) break; // 붙일 수 있으면 종료 From 538ea2d118616f2d3ec4b775dc5ec473a5d3b944 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 31 Aug 2023 14:48:16 +0900 Subject: [PATCH 748/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=82=B4?= =?UTF-8?q?=EB=A0=A4=EA=B0=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\240\244\352\260\200\352\270\260.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "2023/08.31/\354\241\260\354\210\230\354\227\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" diff --git "a/2023/08.31/\354\241\260\354\210\230\354\227\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" "b/2023/08.31/\354\241\260\354\210\230\354\227\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" new file mode 100644 index 0000000..8998883 --- /dev/null +++ "b/2023/08.31/\354\241\260\354\210\230\354\227\260/\353\202\264\353\240\244\352\260\200\352\270\260.java" @@ -0,0 +1,70 @@ +import java.io.*; +import java.util.*; + +public class Main { + static final int MAX = 1000000; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int n = Integer.parseInt(br.readLine()); + int[][] arr = new int[n + 1][3]; + + for (int i = 1; i <= n; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 3; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + int[][] minDp = new int[n + 1][3]; + int[][] maxDp = new int[n + 1][3]; + + for (int i = 0; i < 3; i++) { + minDp[1][i] = arr[1][i]; + maxDp[1][i] = arr[1][i]; + } + + if (n >= 2) { + for (int i = 2; i <= n; i++) { + Arrays.fill(minDp[i], MAX); + } + + for (int i = 2; i <= n; i++) { + for (int j = 0; j < 3; j++) { + switch (j) { + case 0: + minDp[i][j] = Math.min(minDp[i][j], minDp[i - 1][j] + arr[i][j]); + minDp[i][j + 1] = Math.min(minDp[i][j + 1], minDp[i - 1][j] + arr[i][j + 1]); + maxDp[i][j] = Math.max(maxDp[i][j], maxDp[i - 1][j] + arr[i][j]); + maxDp[i][j + 1] = Math.max(maxDp[i][j + 1], maxDp[i - 1][j] + arr[i][j + 1]); + break; + case 1: + minDp[i][j] = Math.min(minDp[i][j], minDp[i - 1][j] + arr[i][j]); + minDp[i][j + 1] = Math.min(minDp[i][j + 1], minDp[i - 1][j] + arr[i][j + 1]); + minDp[i][j - 1] = Math.min(minDp[i][j - 1], minDp[i - 1][j] + arr[i][j - 1]); + maxDp[i][j] = Math.max(maxDp[i][j], maxDp[i - 1][j] + arr[i][j]); + maxDp[i][j + 1] = Math.max(maxDp[i][j + 1], maxDp[i - 1][j] + arr[i][j + 1]); + maxDp[i][j - 1] = Math.max(maxDp[i][j - 1], maxDp[i - 1][j] + arr[i][j - 1]); + break; + case 2: + minDp[i][j] = Math.min(minDp[i][j], minDp[i - 1][j] + arr[i][j]); + minDp[i][j - 1] = Math.min(minDp[i][j - 1], minDp[i - 1][j] + arr[i][j - 1]); + maxDp[i][j] = Math.max(maxDp[i][j], maxDp[i - 1][j] + arr[i][j]); + maxDp[i][j - 1] = Math.max(maxDp[i][j - 1], maxDp[i - 1][j] + arr[i][j - 1]); + break; + } + } + } + } + + int max = Arrays.stream(maxDp[n]).max().getAsInt(); + int min = Arrays.stream(minDp[n]).min().getAsInt(); + + bw.write(max + " " + min); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From 8babb68fca29fd7076140e48ac27eaeb3e234c43 Mon Sep 17 00:00:00 2001 From: Bucket <77010707+suyong5713@users.noreply.github.com> Date: Thu, 31 Aug 2023 21:26:51 +0900 Subject: [PATCH 749/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20=EB=B6=99=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\341\205\265\341\204\200\341\205\265.java" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "2023/08.31/\354\235\264\354\210\230\354\232\251/\341\204\211\341\205\263\341\204\220\341\205\265\341\204\217\341\205\245\341\204\207\341\205\256\341\207\200\341\204\213\341\205\265\341\204\200\341\205\265.java" diff --git "a/2023/08.31/\354\235\264\354\210\230\354\232\251/\341\204\211\341\205\263\341\204\220\341\205\265\341\204\217\341\205\245\341\204\207\341\205\256\341\207\200\341\204\213\341\205\265\341\204\200\341\205\265.java" "b/2023/08.31/\354\235\264\354\210\230\354\232\251/\341\204\211\341\205\263\341\204\220\341\205\265\341\204\217\341\205\245\341\204\207\341\205\256\341\207\200\341\204\213\341\205\265\341\204\200\341\205\265.java" new file mode 100644 index 0000000..07d6bc9 --- /dev/null +++ "b/2023/08.31/\354\235\264\354\210\230\354\232\251/\341\204\211\341\205\263\341\204\220\341\205\265\341\204\217\341\205\245\341\204\207\341\205\256\341\207\200\341\204\213\341\205\265\341\204\200\341\205\265.java" @@ -0,0 +1,101 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 스티커붙이기 { + static int N; + static int M; + static int K; + static int[][] board; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + board = new int[N][M]; + for (int i = 0; i < board.length; i++) { + Arrays.fill(board[i], 0); + } + ArrayList stickerList = new ArrayList<>(); + for (int k = 0; k < K; k++) { + st = new StringTokenizer(br.readLine()); + int height = Integer.parseInt(st.nextToken()); + int width = Integer.parseInt(st.nextToken()); + int[][] sticker = new int[height][width]; + for (int i = 0; i < height; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < width; j++) { + sticker[i][j] = Integer.parseInt(st.nextToken()); + } + } + stickerList.add(sticker); + } + int rotateCount = 0; + while (!stickerList.isEmpty()) { + int[][] sticker = stickerList.remove(0); + boolean attached = false; + for (int i = 0; i < N && !attached; i++) { + for (int j = 0; j < M && !attached; j++) { + boolean available = true; + for (int k = 0; k < sticker.length && available; k++) { + if (i + k >= N) break; + for (int l = 0; l < sticker[0].length; l++) { + if (j + l >= M) break; + if (sticker[k][l] != 0) { + if (board[i + k][j + l] != 0) { + available = false; + break; + } + } + // 정상적으로 스티커 배열 끝까지 다 돌았으면, 붙임 + if (k == sticker.length - 1 && l == sticker[0].length - 1) { + attached = true; + for (int x = 0; x < sticker.length; x++) { + for (int y = 0; y < sticker[0].length; y++) { + if (sticker[x][y] == 1) board[i + x][j + y] = 1; + } + } + } + } + } + } + } + if (!attached) { + // 90도 180도 270도 다안되면 + if (rotateCount == 4) { + rotateCount = 0; + } else { + int[][] rotatedSticker = rotateSticker(sticker); + stickerList.add(0, rotatedSticker); + rotateCount++; + } + }else{ + rotateCount = 0; + } + } + int answer = 0; + for(int[] row : board){ + for(int val: row){ + answer += val; + } + } + System.out.println(answer); + } + + static int[][] rotateSticker(int[][] sticker) { + int height = sticker.length; + int width = sticker[0].length; + int[][] rotatedSticker = new int[width][height]; + for (int i = 0; i < rotatedSticker.length; i++) { + for (int j = 0; j < rotatedSticker[i].length; j++) { + rotatedSticker[i][j] = sticker[height - 1 - j][i]; + } + } + return rotatedSticker; + } +} From 6684ccb7b54901df6498212f4c73b6786c98db22 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 1 Sep 2023 17:39:31 +0900 Subject: [PATCH 750/822] [SOLVE] @josooyeon11 : PPAP --- .../PPAP.java" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "2023/09.04/\354\241\260\354\210\230\354\227\260/PPAP.java" diff --git "a/2023/09.04/\354\241\260\354\210\230\354\227\260/PPAP.java" "b/2023/09.04/\354\241\260\354\210\230\354\227\260/PPAP.java" new file mode 100644 index 0000000..2c2863a --- /dev/null +++ "b/2023/09.04/\354\241\260\354\210\230\354\227\260/PPAP.java" @@ -0,0 +1,32 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + String str = br.readLine(); + Stack stack = new Stack<>(); + + for (int i = 0; i < str.length(); i++) { + if (stack.size() < 3) stack.add(str.charAt(i)); + else { + if (str.charAt(i) == 'P' + && stack.get(stack.size() - 3) == 'P' + && stack.get(stack.size() - 2) == 'P' + && stack.get(stack.size() - 1) == 'A') { + for (int j = 0; j < 2; j++) { + stack.pop(); + } + } else stack.add(str.charAt(i)); + } + } + + if (stack.size() == 1 && stack.peek() == 'P') bw.write("PPAP"); + else bw.write("NP"); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From 7368d7412ca7a45f8fd9f43c76dc63951762db95 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 3 Sep 2023 15:12:19 +0900 Subject: [PATCH 751/822] 0831 kihun --- ...\353\240\244\352\260\200\352\270\260.java" | 59 ++++++++++ ...\353\266\231\354\235\264\352\270\260.java" | 104 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 "2023/08.31/\354\206\241\352\270\260\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260.java" create mode 100644 "2023/08.31/\354\206\241\352\270\260\355\233\210/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" diff --git "a/2023/08.31/\354\206\241\352\270\260\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260.java" "b/2023/08.31/\354\206\241\352\270\260\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260.java" new file mode 100644 index 0000000..8b4c355 --- /dev/null +++ "b/2023/08.31/\354\206\241\352\270\260\355\233\210/\353\202\264\353\240\244\352\260\200\352\270\260.java" @@ -0,0 +1,59 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class 내려가기 { + + static int N; + static int[][] matrix; + static int[][][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + matrix = new int[N+1][3]; + dp = new int[2][N+1][3]; + for (int i = 1; i <= N; i++) { + String[] inputs = br.readLine().split(" "); + matrix[i][0] = Integer.parseInt(inputs[0]); + matrix[i][1] = Integer.parseInt(inputs[1]); + matrix[i][2] = Integer.parseInt(inputs[2]); + + } + + StringBuilder sb = new StringBuilder(); + if (N == 1) { + sb.append(Math.max(Math.max(matrix[1][0], matrix[1][1]), matrix[1][2])); + sb.append(" "); + sb.append(Math.min(Math.min(matrix[1][0], matrix[1][1]), matrix[1][2])); + } else { + for (int i = 0; i < 3; i++) { + dp[0][1][i] = matrix[1][i]; + dp[1][1][i] = matrix[1][i]; + } + + for (int i = 2; i <= N; i++) { + int maxOneTwo = Math.max(dp[0][i-1][0], dp[0][i-1][1]); + int maxTwoThree = Math.max(dp[0][i-1][1], dp[0][i-1][2]); + int minOneTwo = Math.min(dp[1][i-1][0], dp[1][i-1][1]); + int minTwoThree = Math.min(dp[1][i-1][1], dp[1][i-1][2]); + + dp[0][i][0] = maxOneTwo + matrix[i][0]; + dp[0][i][1] = Math.max(maxOneTwo, maxTwoThree) + matrix[i][1]; + dp[0][i][2] = maxTwoThree + matrix[i][2]; + + dp[1][i][0] = minOneTwo + matrix[i][0]; + dp[1][i][1] = Math.min(minOneTwo, minTwoThree) + matrix[i][1]; + dp[1][i][2] = minTwoThree + matrix[i][2]; + } + + sb.append(Arrays.stream(dp[0][N]).max().getAsInt() + " " + Arrays.stream(dp[1][N]).min().getAsInt()); + System.out.println(sb); + } + + } +} diff --git "a/2023/08.31/\354\206\241\352\270\260\355\233\210/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" "b/2023/08.31/\354\206\241\352\270\260\355\233\210/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" new file mode 100644 index 0000000..5a05cb7 --- /dev/null +++ "b/2023/08.31/\354\206\241\352\270\260\355\233\210/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" @@ -0,0 +1,104 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 스티커붙이기 { + + static int N, M, K, R, C; + static boolean[][] matrix = new boolean[40][40]; + static int[][] sticker = new int[10][10]; + static int[][] tempArr = new int[10][10]; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); // 세로 + M = Integer.parseInt(st.nextToken()); // 가로 + K = Integer.parseInt(st.nextToken()); // 스티커의 수 + + for (int k = 0; k < K; k++) { + st = new StringTokenizer(br.readLine()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + + for (int r = 0; r < R; r++) { + st = new StringTokenizer(br.readLine()); + for (int c = 0; c < C; c++) { + sticker[r][c] = Integer.parseInt(st.nextToken()); + } + } + + for (int i = 0; i < 4; i++) { + if (solve()) { + break; + } else { + rotate(); + } + } + } + + int answer = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (matrix[i][j]) answer += 1; + } + } + + System.out.println(answer); + } + + static boolean solve() { + for (int i = 0; i <= N - R; i++) { + for (int j = 0; j <= M - C; j++) { + if (check(i, j)) { + putSticker(i, j); + return true; + } + } + } + return false; + } + + static boolean check(int y, int x) { + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + // 스티커를 둘 곳에 이미 자리를 차지하고 있다면 false + if (matrix[y + i][x + j] && sticker[i][j] == 1) { + return false; + } + } + } + return true; + } + + static void putSticker(int y, int x) { + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + if (sticker[i][j] == 1) { + matrix[y + i][x + j] = true; + } + } + } + } + + static void rotate() { + for (int i = 0; i < C; i++) { + for (int j = 0, k = R - 1; j < R; j++, k--) { + tempArr[i][j] = sticker[k][i]; + } + } + + int swap = R; + R = C; + C = swap; + + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + sticker[i][j] = tempArr[i][j]; + } + } + } +} \ No newline at end of file From 2472989e209e4a5c1ddab428c4a4edd20cc3f226 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 3 Sep 2023 15:14:05 +0900 Subject: [PATCH 752/822] Create README.md --- 2023/09.04/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/09.04/README.md diff --git a/2023/09.04/README.md b/2023/09.04/README.md new file mode 100644 index 0000000..97c0f10 --- /dev/null +++ b/2023/09.04/README.md @@ -0,0 +1,5 @@ +# 9.4(목) 스터디 + +- 백준 + - [PPAP](https://www.acmicpc.net/problem/16120) + - [팰린드롬 공장](https://www.acmicpc.net/problem/1053) From 8331489921e7bd6b037ace0ce71053159b604215 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 3 Sep 2023 15:14:58 +0900 Subject: [PATCH 753/822] 0904 kihun --- .../PPAP.java" | 43 ++++++++++++ ...\353\241\254\352\263\265\354\236\245.java" | 66 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 "2023/09.04/\354\206\241\352\270\260\355\233\210/PPAP.java" create mode 100644 "2023/09.04/\354\206\241\352\270\260\355\233\210/\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.java" diff --git "a/2023/09.04/\354\206\241\352\270\260\355\233\210/PPAP.java" "b/2023/09.04/\354\206\241\352\270\260\355\233\210/PPAP.java" new file mode 100644 index 0000000..112766a --- /dev/null +++ "b/2023/09.04/\354\206\241\352\270\260\355\233\210/PPAP.java" @@ -0,0 +1,43 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +public class PPAP { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String inputString = br.readLine(); + int length = inputString.length(); + int pCount = 0; + + for (int i = 0; i < length; i++) { + // P인 경우 + if (inputString.charAt(i) == 'P') { + pCount += 1; + } + // A인 경우 + else { + // PP가 되어야하므로 pCount는 2개 이상 + // A 뒤에 따라올 P가 있어야 하므로 index는 끝에서 두번째 이하 + // 다음 index에 P인지 확인 + if (pCount >= 2 && i < length - 1 && inputString.charAt(i+1) == 'P') { + pCount -= 1; + i += 1; + } else { + pCount = 0; + break; + } + } + } + + if (pCount == 1) { + System.out.println("PPAP"); + } else { + System.out.println("NP"); + } + + } +} \ No newline at end of file diff --git "a/2023/09.04/\354\206\241\352\270\260\355\233\210/\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.java" "b/2023/09.04/\354\206\241\352\270\260\355\233\210/\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.java" new file mode 100644 index 0000000..cf3ff9d --- /dev/null +++ "b/2023/09.04/\354\206\241\352\270\260\355\233\210/\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.java" @@ -0,0 +1,66 @@ +package baekjoon.gold.one; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 팰린드롬공장 { + +// https://velog.io/@deserve82/DP-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EA%B3%B5%EC%9E%A5-%EB%AC%B8%EC%A0%9C%EC%97%90-%EB%8C%80%ED%95%9C-%EA%B3%A0%EC%B0%B0-python +// 문자열의 어떤 위치에 어떤 문자를 삽입 (시작과 끝도 가능) +// 어떤 위치에 있는 문자를 삭제 +// 어떤 위치에 있는 문자를 교환 +// 서로 다른 문자를 교환 + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String inputString = br.readLine(); + + int result = palindrome(inputString); + + String tempString; + + for (int i = 0; i < inputString.length(); i++) { + for (int j = i + 1; j < inputString.length() - 1; j++) { + if (inputString.charAt(i) == inputString.charAt(j)) continue; + tempString = swap(i, j, inputString); + result = Math.min(result, palindrome(tempString) + 1); + } + } + System.out.println(result); + + } + + public static int palindrome(String str) { + int size = str.length(); + int[][] dp = new int[size][size]; + + for (int i = 0; i < size; i++) { + dp[i][i] = 0; + if (i != size - 1) { + dp[i][i + 1] = str.charAt(i) == str.charAt(i + 1) ? 0 : 1; + } + } + + for (int i = 2; i < size; i++) { + for (int j = 0; j < size - i; j++) { + dp[j][j + i] = Math.min(dp[j + 1][j + i] + 1, dp[j][j + i - 1] + 1); + if (str.charAt(j) == str.charAt(j + i)) { + dp[j][j + i] = Math.min(dp[j + 1][j + i - 1], dp[j][j + i]); + } else { + dp[j][j + i] = Math.min(dp[j + 1][j + i - 1] + 1, dp[j][j + i]); + } + } + } + return dp[0][size - 1]; + } + + public static String swap(int a, int b, String tempString) { + StringBuilder sb = new StringBuilder(tempString); + char temp = tempString.charAt(a); + sb.setCharAt(a, tempString.charAt(b)); + sb.setCharAt(b, temp); + return sb.toString(); + } +} \ No newline at end of file From f8c1fae2a34e3c11618bbb1d3a21075e77d75ca5 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:10:36 +0900 Subject: [PATCH 754/822] Create README.md --- 2023/0907/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/0907/README.md diff --git a/2023/0907/README.md b/2023/0907/README.md new file mode 100644 index 0000000..59cc4bc --- /dev/null +++ b/2023/0907/README.md @@ -0,0 +1,5 @@ +# 9.7(목) 스터디 + +- 프로그래머스 + - [야근 지수](https://school.programmers.co.kr/learn/courses/30/lessons/12927?language=java) + - [등굣길](https://school.programmers.co.kr/learn/courses/30/lessons/42898) From cd3d1d744c6c0d2a4219c857a1055024925b5af4 Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:11:20 +0900 Subject: [PATCH 755/822] Create README.md --- 2023/{0907 => 09.07}/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 2023/{0907 => 09.07}/README.md (100%) diff --git a/2023/0907/README.md b/2023/09.07/README.md similarity index 100% rename from 2023/0907/README.md rename to 2023/09.07/README.md From 515800adcb9a029b72bd892207d3329d8973179a Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:11:46 +0900 Subject: [PATCH 756/822] =?UTF-8?q?=EC=95=BC=EA=B7=BC=20=EC=A7=80=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\274\352\267\274 \354\247\200\354\210\230" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "2023/09.07/\352\271\200\354\247\200\355\233\210/\354\225\274\352\267\274 \354\247\200\354\210\230" diff --git "a/2023/09.07/\352\271\200\354\247\200\355\233\210/\354\225\274\352\267\274 \354\247\200\354\210\230" "b/2023/09.07/\352\271\200\354\247\200\355\233\210/\354\225\274\352\267\274 \354\247\200\354\210\230" new file mode 100644 index 0000000..51767fc --- /dev/null +++ "b/2023/09.07/\352\271\200\354\247\200\355\233\210/\354\225\274\352\267\274 \354\247\200\354\210\230" @@ -0,0 +1,24 @@ +import java.io.*; +import java.util.*; + +class Solution { + public long solution(int n, int[] works) { + long answer = 0; + int sum = 0; + PriorityQueue pq = new PriorityQueue<>((o1,o2)->-(o1-o2)); + for(int work : works){ + pq.add(work); + sum+=work; + } + //안해도 되는 경우 + if(sum-n<=0) return 0; + while(n-->0){ + int top = pq.poll(); + pq.offer(top-1); + } + while(!pq.isEmpty()){ + answer+=Math.pow(pq.poll(),2); + } + return answer; + } +} From 1cb51f96b9bc2142b332b6f4c694d423815a576f Mon Sep 17 00:00:00 2001 From: KimJiHun <68943993+GGE2@users.noreply.github.com> Date: Wed, 6 Sep 2023 18:40:39 +0900 Subject: [PATCH 757/822] =?UTF-8?q?=EB=93=B1=EA=B5=A3=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\223\261\352\265\243\352\270\270" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "2023/09.07/\352\271\200\354\247\200\355\233\210/\353\223\261\352\265\243\352\270\270" diff --git "a/2023/09.07/\352\271\200\354\247\200\355\233\210/\353\223\261\352\265\243\352\270\270" "b/2023/09.07/\352\271\200\354\247\200\355\233\210/\353\223\261\352\265\243\352\270\270" new file mode 100644 index 0000000..88b50e8 --- /dev/null +++ "b/2023/09.07/\352\271\200\354\247\200\355\233\210/\353\223\261\352\265\243\352\270\270" @@ -0,0 +1,43 @@ +import java.util.*; +import java.io.*; + +class Solution { + static int[][] dp; + static int[] dx={1,0}; + static int[] dy={0,1}; + public int solution(int m, int n, int[][] puddles) { + int answer = 0; + dp = new int[n][m]; + for(int i=0;iendX||ny>endY) continue; + for(int r=0;r1000000007) + dp[x][y] %=1000000007; + } + + return dp[x][y]; + } +} From 141e923580efd1103c5728ddccd2db4c6846c7cd Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 7 Sep 2023 00:09:23 +0900 Subject: [PATCH 758/822] =?UTF-8?q?Create=20=EB=93=B1=EA=B5=A3=EA=B8=B8.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\223\261\352\265\243\352\270\270.java" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "2023/09.07/\353\223\261\352\265\243\352\270\270.java" diff --git "a/2023/09.07/\353\223\261\352\265\243\352\270\270.java" "b/2023/09.07/\353\223\261\352\265\243\352\270\270.java" new file mode 100644 index 0000000..1d55eb1 --- /dev/null +++ "b/2023/09.07/\353\223\261\352\265\243\352\270\270.java" @@ -0,0 +1,42 @@ +public class 등굣길 { + public static void main(String[] args) { + int m = 4; + int n = 3; + int puddles[][] = {{2, 2}}; + + Solution s = new Solution(); + + System.out.println(s.solution(m, n, puddles)); + } + + static class Solution { + + public int solution(int m, int n, int[][] puddles) { + int answer = 0; + + int[][] map = new int[n + 1][m + 1]; + + for (int i = 0; i < puddles.length; i++) { + for (int j = 0; j < puddles[i].length; j += 2) { + map[puddles[i][j + 1]][puddles[i][j]] = -1; + } + } + + map[1][1] = 1; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + if (map[i][j] == -1) continue; + if (i == 1 && j == 1) continue; + + int left = map[i][j - 1] == -1 ? 0 : map[i][j - 1]; + int up = map[i - 1][j] == -1 ? 0 : map[i - 1][j]; + map[i][j] = (left + up) % 1_000_000_007; + } + } + + answer = map[n][m]; + return answer; + } + } +} From db3e4585391e3f98c0d257660a615a479e72e72c Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 7 Sep 2023 00:09:41 +0900 Subject: [PATCH 759/822] =?UTF-8?q?Rename=202023/09.07/=EB=93=B1=EA=B5=A3?= =?UTF-8?q?=EA=B8=B8.java=20to=202023/09.07/=EC=A0=95=ED=98=B8=EC=A1=B0/?= =?UTF-8?q?=EB=93=B1=EA=B5=A3=EA=B8=B8.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\223\261\352\265\243\352\270\270.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "2023/09.07/\353\223\261\352\265\243\352\270\270.java" => "2023/09.07/\354\240\225\355\230\270\354\241\260/\353\223\261\352\265\243\352\270\270.java" (100%) diff --git "a/2023/09.07/\353\223\261\352\265\243\352\270\270.java" "b/2023/09.07/\354\240\225\355\230\270\354\241\260/\353\223\261\352\265\243\352\270\270.java" similarity index 100% rename from "2023/09.07/\353\223\261\352\265\243\352\270\270.java" rename to "2023/09.07/\354\240\225\355\230\270\354\241\260/\353\223\261\352\265\243\352\270\270.java" From 98d7eb7e2a538ebbfd450ea8dc12d3eb556c34e6 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 7 Sep 2023 00:10:00 +0900 Subject: [PATCH 760/822] =?UTF-8?q?Create=20=EC=95=BC=EA=B7=BC=EC=A7=80?= =?UTF-8?q?=EC=88=98.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\267\274\354\247\200\354\210\230.java" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "2023/09.07/\354\240\225\355\230\270\354\241\260/\354\225\274\352\267\274\354\247\200\354\210\230.java" diff --git "a/2023/09.07/\354\240\225\355\230\270\354\241\260/\354\225\274\352\267\274\354\247\200\354\210\230.java" "b/2023/09.07/\354\240\225\355\230\270\354\241\260/\354\225\274\352\267\274\354\247\200\354\210\230.java" new file mode 100644 index 0000000..b19317c --- /dev/null +++ "b/2023/09.07/\354\240\225\355\230\270\354\241\260/\354\225\274\352\267\274\354\247\200\354\210\230.java" @@ -0,0 +1,35 @@ +import java.util.Collections; +import java.util.PriorityQueue; + +public class 야근지수 { + public static void main(String[] args) { + int n = 3; + int[] works = {1, 1}; + + System.out.println(solution(n, works)); + } + + static long solution(int n, int[] works) { + long answer = 0; + + PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); + + for (int i = 0; i < works.length; i++) { + pq.add(works[i]); + } + + for(int i=0; i Date: Thu, 7 Sep 2023 10:08:13 +0900 Subject: [PATCH 761/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=93=B1?= =?UTF-8?q?=EA=B5=A3=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\223\261\352\265\243\352\270\270.java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "2023/09.07/\354\241\260\354\210\230\354\227\260/\353\223\261\352\265\243\352\270\270.java" diff --git "a/2023/09.07/\354\241\260\354\210\230\354\227\260/\353\223\261\352\265\243\352\270\270.java" "b/2023/09.07/\354\241\260\354\210\230\354\227\260/\353\223\261\352\265\243\352\270\270.java" new file mode 100644 index 0000000..9f81da9 --- /dev/null +++ "b/2023/09.07/\354\241\260\354\210\230\354\227\260/\353\223\261\352\265\243\352\270\270.java" @@ -0,0 +1,44 @@ +import java.util.*; + +class Solution { + int[][] dp; + int[] dx = {0, 1}; + int[] dy = {1, 0}; + final int MOD = 1000000007; + + public int solution(int m, int n, int[][] puddles) { + int answer = 0; + + dp = new int[n][m]; + + for (int i = 0; i < n; i++) { + Arrays.fill(dp[i], -1); + } + + for (int i = 0; i < puddles.length; i++) { + dp[puddles[i][1] - 1][puddles[i][0] - 1] = -2; + } + + return dfs(0, 0, m, n); + } + + public int dfs(int x, int y, int m, int n) { + if (x == m - 1 && y == n - 1) return 1; // 도착하면 경로 +1 + + if (dp[y][x] != -1) return dp[y][x]; // 해당 위치에 경로의 갯수가 있으면 불러오기 + + dp[y][x] = 0; + + for (int i = 0; i < 2; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if (nx < m && ny < n && dp[ny][nx] != -2) { + dp[y][x] += dfs(nx, ny, m, n); + dp[y][x] %= MOD; + } + } + + return dp[y][x]; + } +} \ No newline at end of file From d5c22b409d46b241a9a03060959b82ce949ac45b Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 7 Sep 2023 10:28:10 +0900 Subject: [PATCH 762/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=95=BC?= =?UTF-8?q?=EA=B7=BC=20=EC=A7=80=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\267\274_\354\247\200\354\210\230.java" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "2023/09.07/\354\241\260\354\210\230\354\227\260/\354\225\274\352\267\274_\354\247\200\354\210\230.java" diff --git "a/2023/09.07/\354\241\260\354\210\230\354\227\260/\354\225\274\352\267\274_\354\247\200\354\210\230.java" "b/2023/09.07/\354\241\260\354\210\230\354\227\260/\354\225\274\352\267\274_\354\247\200\354\210\230.java" new file mode 100644 index 0000000..a18ea4d --- /dev/null +++ "b/2023/09.07/\354\241\260\354\210\230\354\227\260/\354\225\274\352\267\274_\354\247\200\354\210\230.java" @@ -0,0 +1,25 @@ +import java.util.*; + +class Solution { + public long solution(int n, int[] works) { + if (Arrays.stream(works).sum() <= n) return 0; // 남은 작업량보다 퇴근까지 남은 시간이 더 많으면 + + long answer = 0; + PriorityQueue pq = new PriorityQueue(Collections.reverseOrder()); + + for (Integer work : works) { + pq.add(Long.valueOf(work)); + } + + for (int i = 0; i < n; i++) { + long work = pq.poll(); + + if (work - 1 != 0) pq.add(work - 1); + } + + while (!pq.isEmpty()) { + answer += Math.pow(pq.poll(), 2); + } + return answer; + } +} \ No newline at end of file From d564a9b733889a523a673545d498391a7647915c Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 8 Sep 2023 10:06:30 +0900 Subject: [PATCH 763/822] 0907 kihun --- ...\353\223\261\352\265\243\352\270\270.java" | 26 ++++++++++++++ ...\352\267\274\354\247\200\354\210\230.java" | 36 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 "2023/09.07/\354\206\241\352\270\260\355\233\210/\353\223\261\352\265\243\352\270\270.java" create mode 100644 "2023/09.07/\354\206\241\352\270\260\355\233\210/\354\225\274\352\267\274\354\247\200\354\210\230.java" diff --git "a/2023/09.07/\354\206\241\352\270\260\355\233\210/\353\223\261\352\265\243\352\270\270.java" "b/2023/09.07/\354\206\241\352\270\260\355\233\210/\353\223\261\352\265\243\352\270\270.java" new file mode 100644 index 0000000..0b31ee4 --- /dev/null +++ "b/2023/09.07/\354\206\241\352\270\260\355\233\210/\353\223\261\352\265\243\352\270\270.java" @@ -0,0 +1,26 @@ +package programmers.lv3; + +import java.util.Arrays; + +public class 등굣길 { + + public int solution(int m, int n, int[][] puddles) { + int mod = 1000000007; + + int[][] dp = new int[n + 1][m + 1]; + + for (int i = 0; i < puddles.length; i++) { + dp[puddles[i][1]][puddles[i][0]] = -1; + } + + dp[1][1] = 1; + for (int i = 1; i < n + 1; i++) { + for (int j = 1; j < m + 1; j++) { + if (dp[i][j] == -1) continue; + if (dp[i - 1][j] != -1) dp[i][j] += dp[i - 1][j] % mod; + if (dp[i][j - 1] != -1) dp[i][j] += dp[i][j - 1] % mod; + } + } + return dp[n][m] % mod; + } +} \ No newline at end of file diff --git "a/2023/09.07/\354\206\241\352\270\260\355\233\210/\354\225\274\352\267\274\354\247\200\354\210\230.java" "b/2023/09.07/\354\206\241\352\270\260\355\233\210/\354\225\274\352\267\274\354\247\200\354\210\230.java" new file mode 100644 index 0000000..358f123 --- /dev/null +++ "b/2023/09.07/\354\206\241\352\270\260\355\233\210/\354\225\274\352\267\274\354\247\200\354\210\230.java" @@ -0,0 +1,36 @@ +package programmers.lv3; + +import java.util.Collections; +import java.util.PriorityQueue; + +public class 야근지수 { + + public long solution(int n, int[] works) { + long answer = 0; + + // 내림차순 PQ + PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); + + for (int work : works) { + pq.offer(work); + } + + while (n-- > 0) { + int work = pq.poll(); + + // 제일 큰 게 0이니까 더 줄일게 없다 + if (work == 0) break; + + work -= 1; + pq.offer(work); + } + + for (int work : pq) { + long workL = (long) work; + answer += workL * workL; + } + + return answer; + } + +} From bf10f960d1a5827ee68e88e00f5a12d57e26babb Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 8 Sep 2023 15:58:21 +0900 Subject: [PATCH 764/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=B3=B4?= =?UTF-8?q?=EC=84=9D=20=EC=87=BC=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\204\235_\354\207\274\355\225\221.java" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "2023/09.11/\354\241\260\354\210\230\354\227\260/\353\263\264\354\204\235_\354\207\274\355\225\221.java" diff --git "a/2023/09.11/\354\241\260\354\210\230\354\227\260/\353\263\264\354\204\235_\354\207\274\355\225\221.java" "b/2023/09.11/\354\241\260\354\210\230\354\227\260/\353\263\264\354\204\235_\354\207\274\355\225\221.java" new file mode 100644 index 0000000..bfed42e --- /dev/null +++ "b/2023/09.11/\354\241\260\354\210\230\354\227\260/\353\263\264\354\204\235_\354\207\274\355\225\221.java" @@ -0,0 +1,43 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + String[] gems = {"DIA", "RUBY", "RUBY", "DIA", "DIA", "EMERALD", "SAPPHIRE", "DIA"}; + new Solution().solution(gems); + } +} + +class Solution { + public int[] solution(String[] gems) { + int[] answer = new int[2]; + HashMap gemMap = new HashMap<>(); + + for (String gem : gems) { + gemMap.put(gem, gemMap.getOrDefault(gem, 0) + 1); + } + + int start = 0; + int size = gemMap.size(); + int count = 100000; + HashMap map = new HashMap<>(); + + // 투포인터 개념으로 접근 + for (int end = 0; end < gems.length; end++) { + map.put(gems[end], map.getOrDefault(gems[end], 0) + 1); + + while (true) { // 시작부분을 기준으로 중복 요소 제거하고 start++ + if (map.get(gems[start]) <= 1) break; + + map.put(gems[start],map.get(gems[start]) - 1); + start++; + } + + if (map.size() == size && count > end - start) { + count = end - start; + answer[0] = start + 1; + answer[1] = end + 1; + } + } + return answer; + } +} \ No newline at end of file From 8d0bb8c5a9683d71932b6697a65dd4c61c26fa13 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 8 Sep 2023 17:26:08 +0900 Subject: [PATCH 765/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=96=91?= =?UTF-8?q?=EA=B3=BC=20=EB=8A=91=EB=8C=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\263\274_\353\212\221\353\214\200.java" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" diff --git "a/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" "b/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" new file mode 100644 index 0000000..eae05c8 --- /dev/null +++ "b/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" @@ -0,0 +1,56 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + int[] info = {0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1}; + int[][] edges = {{0, 1}, {1, 2}, {1, 4}, {0, 8}, {8, 7}, {9, 10}, {9, 11}, {4, 3}, {6, 5}, {4, 6}, {8, 9}}; + new Solution().solution(info, edges); + } +} + +class Solution { + int[] info; + int[][] graph; + int[] visited; + int answer = 0; + + public int solution(int[] info, int[][] edges) { + this.info = info.clone(); + graph = new int[info.length][info.length]; + visited = new int[info.length]; + + for (int i = 0; i < edges.length; i++) { + graph[edges[i][0]][edges[i][1]] = 1; + } + + List list = new ArrayList<>(); + list.add(0); + + if (info[0] == 0) dfs(0, 1, 0, list); + else dfs(0, 0, 1, list); + + return answer; + } + + public void dfs(int node, int sheep, int wolf, List nextList) { + if (sheep <= wolf) return; // dfs 탐색 종료 + + answer = Math.max(answer, sheep); + + List list = new ArrayList<>(); + + list.addAll(nextList); + list.remove(Integer.valueOf(node)); // 탐색할 위치에서 현재 인덱스는 뺴고 시작 -> 되돌아가기 X + + for (int i = 0; i < graph[node].length; i++) { + if (graph[node][i] == 1) { + list.add(i); + } + } + + for (int next : list) { + if (info[next] == 0) dfs(next, sheep + 1, wolf, list); + else dfs(next, sheep, wolf + 1, list); + } + } +} \ No newline at end of file From bb632fdedd2cd55a2d6ecab19e57a6c81ca6a760 Mon Sep 17 00:00:00 2001 From: su6378 Date: Fri, 8 Sep 2023 17:29:34 +0900 Subject: [PATCH 766/822] =?UTF-8?q?[MOD]=20@josooyeon11=20:=20=EC=96=91?= =?UTF-8?q?=EA=B3=BC=20=EB=8A=91=EB=8C=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\226\221\352\263\274_\353\212\221\353\214\200.java" | 2 -- 1 file changed, 2 deletions(-) diff --git "a/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" "b/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" index eae05c8..c840e12 100644 --- "a/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" +++ "b/2023/09.11/\354\241\260\354\210\230\354\227\260/\354\226\221\352\263\274_\353\212\221\353\214\200.java" @@ -11,13 +11,11 @@ public static void main(String[] args) { class Solution { int[] info; int[][] graph; - int[] visited; int answer = 0; public int solution(int[] info, int[][] edges) { this.info = info.clone(); graph = new int[info.length][info.length]; - visited = new int[info.length]; for (int i = 0; i < edges.length; i++) { graph[edges[i][0]][edges[i][1]] = 1; From baf4f65618f2ded5e2c55e67b2fb7ed5f0b3c574 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 9 Sep 2023 20:14:37 +0900 Subject: [PATCH 767/822] Create README.md --- 2023/09.11/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/09.11/README.md diff --git a/2023/09.11/README.md b/2023/09.11/README.md new file mode 100644 index 0000000..7e22475 --- /dev/null +++ b/2023/09.11/README.md @@ -0,0 +1,5 @@ +# 9.11(월) 스터디 + +- 프로그래머스 + - [양과 늑대](https://school.programmers.co.kr/learn/courses/30/lessons/12927) + - [보석 쇼핑](https://school.programmers.co.kr/learn/courses/30/lessons/67258) From 294044972d8382a3be452e33b24c3b0def48361b Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sat, 9 Sep 2023 20:15:09 +0900 Subject: [PATCH 768/822] 0911 kihun --- ...\354\204\235\354\207\274\355\225\221.java" | 38 +++++++++++++ ...\352\263\274\353\212\221\353\214\200.java" | 56 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 "2023/09.11/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" create mode 100644 "2023/09.11/\354\206\241\352\270\260\355\233\210/\354\226\221\352\263\274\353\212\221\353\214\200.java" diff --git "a/2023/09.11/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" "b/2023/09.11/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" new file mode 100644 index 0000000..30de214 --- /dev/null +++ "b/2023/09.11/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" @@ -0,0 +1,38 @@ +package programmers.lv3; + +import java.util.*; + +public class 보석쇼핑 { + + public int[] solution(String[] gems) { + int[] answer = new int[2]; + + HashSet gemSet = new HashSet<>(Arrays.asList(gems)); + int kind = gemSet.size(); + + int start = 0; + int size = Integer.MAX_VALUE; + + Map gemMap = new HashMap<>(); + + for (int end = 0; end < gems.length; end++) { + gemMap.put(gems[end], gemMap.getOrDefault(gems[end], 0) + 1); + + // 1개보다 많으면 1개 빼고 start index를 하나 올린다 + while (gemMap.get(gems[start]) > 1) { + gemMap.put(gems[start], gemMap.get(gems[start]) - 1); + start++; + } + + // gemMap의 크기와 종류가 같다 & 더 작은 사이즈면 갱신 + if (gemMap.size() == kind && size > (end - start)) { + size = end - start; + answer[0] = start + 1; + answer[1] = end + 1; + } + } + + return answer; + } + +} diff --git "a/2023/09.11/\354\206\241\352\270\260\355\233\210/\354\226\221\352\263\274\353\212\221\353\214\200.java" "b/2023/09.11/\354\206\241\352\270\260\355\233\210/\354\226\221\352\263\274\353\212\221\353\214\200.java" new file mode 100644 index 0000000..eacdaf0 --- /dev/null +++ "b/2023/09.11/\354\206\241\352\270\260\355\233\210/\354\226\221\352\263\274\353\212\221\353\214\200.java" @@ -0,0 +1,56 @@ +package programmers.lv3; + +import java.util.ArrayList; + +public class 양과늑대 { + + static ArrayList> graph; + static int maxValue = Integer.MIN_VALUE; + static int[] pos; + + public int solution(int[] info, int[][] edges) { + pos = info; + graph = new ArrayList<>(); + for (int i = 0; i < info.length; i++) { + graph.add(new ArrayList<>()); + } + + for (int i = 0; i < edges.length; i++) { + int parent = edges[i][0]; + int child = edges[i][1]; + graph.get(parent).add(child); + } + + ArrayList temp = new ArrayList(); + temp.add(0); + dfs(0, 1, 0, temp); + + return maxValue; + } + + static void dfs(int index, int sheep, int wolf, ArrayList visited) { + if (pos[index] == 0) { + sheep += 1; + } else { + wolf += 1; + } + + if (wolf >= sheep) { + return; + } + + maxValue = Math.max(sheep, maxValue); + + ArrayList next = new ArrayList(visited); + next.remove(Integer.valueOf(index)); + if (!graph.get(index).isEmpty()) { + next.addAll(graph.get(index)); + } + + for (int node : next) { + dfs(node, sheep, wolf, next); + } + + } + +} From 610dfd952eddd6005e6eef2731d713d49ed674b1 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 11 Sep 2023 13:40:50 +0900 Subject: [PATCH 769/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=B9=97?= =?UTF-8?q?=EB=AC=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "2023/09.14/\353\271\227\353\254\274.java" | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "2023/09.14/\353\271\227\353\254\274.java" diff --git "a/2023/09.14/\353\271\227\353\254\274.java" "b/2023/09.14/\353\271\227\353\254\274.java" new file mode 100644 index 0000000..cb9aeca --- /dev/null +++ "b/2023/09.14/\353\271\227\353\254\274.java" @@ -0,0 +1,42 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int answer = 0; + + StringTokenizer st = new StringTokenizer(br.readLine()); + int h = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + + int[] block = new int[w]; + st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < w; i++) { + block[i] = Integer.parseInt(st.nextToken()); + } + + for (int i = 1; i < w - 1; i++) { + int left = 0; + int right = 0; + + for (int j = 0; j < i; j++) { + left = Math.max(left, block[j]); + } + + for (int j = i + 1; j < w; j++) { + right = Math.max(right, block[j]); + } + + if (block[i] < left && block[i] < right) answer += Math.min(left, right) - block[i]; + } + + bw.write(String.valueOf(answer)); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From cf21f5a36b38a354f7c5ff284779b8e0512fb55d Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 13 Sep 2023 16:04:40 +0900 Subject: [PATCH 770/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=ED=85=9C=20=EC=A4=8D=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\271\227\353\254\274.java" | 0 ...355\205\234_\354\244\215\352\270\260.java" | 72 +++++++++++++++++++ 2 files changed, 72 insertions(+) rename "2023/09.14/\353\271\227\353\254\274.java" => "2023/09.14/\354\241\260\354\210\230\354\227\260/\353\271\227\353\254\274.java" (100%) create mode 100644 "2023/09.14/\354\241\260\354\210\230\354\227\260/\354\225\204\354\235\264\355\205\234_\354\244\215\352\270\260.java" diff --git "a/2023/09.14/\353\271\227\353\254\274.java" "b/2023/09.14/\354\241\260\354\210\230\354\227\260/\353\271\227\353\254\274.java" similarity index 100% rename from "2023/09.14/\353\271\227\353\254\274.java" rename to "2023/09.14/\354\241\260\354\210\230\354\227\260/\353\271\227\353\254\274.java" diff --git "a/2023/09.14/\354\241\260\354\210\230\354\227\260/\354\225\204\354\235\264\355\205\234_\354\244\215\352\270\260.java" "b/2023/09.14/\354\241\260\354\210\230\354\227\260/\354\225\204\354\235\264\355\205\234_\354\244\215\352\270\260.java" new file mode 100644 index 0000000..2b6a5e1 --- /dev/null +++ "b/2023/09.14/\354\241\260\354\210\230\354\227\260/\354\225\204\354\235\264\355\205\234_\354\244\215\352\270\260.java" @@ -0,0 +1,72 @@ +import java.util.*; +import java.awt.*; + +class Test { + public static void main(String[] args) { + int[][] rectangle = {{1, 1, 7, 4}, {3, 2, 5, 5}, {4, 3, 6, 9}, {2, 6, 8, 8}}; + int characterX = 1, characterY = 3, itemX = 7, itemY = 8; + new Solution().solution(rectangle, characterX, characterY, itemX, itemY); + } +} + +class Solution { + static final int SIZE = 100; + static int[][] board; + static boolean[][] visited; + static int[] dx = {0, 0, -1, 1}; + static int[] dy = {-1, 1, 0, 0}; + + public int solution(int[][] rectangle, int characterX, int characterY, int itemX, int itemY) { + board = new int[SIZE + 1][SIZE + 1]; + visited = new boolean[SIZE + 1][SIZE + 1]; + + // 테두리 선에 이동이 가능하도록 board 배열 갱신 + for (int i = 0; i < rectangle.length; i++) { + for (int j = SIZE - 2 * rectangle[i][3]; j <= SIZE - 2 * rectangle[i][1]; j++) { + for (int k = 2 * rectangle[i][0]; k <= 2 * rectangle[i][2]; k++) { + // 이미 이전 사각형 안에 있는 곳이라면 pass + if (board[j][k] == 2) continue; + + // 테두리 선인 경우에는 1 아닌 경우에는 내부이므로 2 + if (j == SIZE - 2 * rectangle[i][3] || j == SIZE - 2 * rectangle[i][1] || k == 2 * rectangle[i][0] || k == 2 * rectangle[i][2]) { + board[j][k] = 1; + } else board[j][k] = 2; + } + } + } + + return bfs(2 * characterX, 2 * characterY, 2 * itemX, 2 * itemY) / 2; + } + + static int bfs(int characterX, int characterY, int itemX, int itemY) { + Queue q = new LinkedList<>(); + int count = 0; + + q.add(new Point(characterX, SIZE - characterY)); + visited[SIZE - characterY][characterX] = true; + + while (!q.isEmpty()) { + int qSize = q.size(); + + for (int i = 0; i < qSize; i++) { + Point now = q.poll(); + + if (now.x == itemX && now.y == SIZE - itemY) return count; + + for (int j = 0; j < 4; j++) { + int nx = now.x + dx[j]; + int ny = now.y + dy[j]; + + if (nx < 0 || nx > SIZE || ny < 0 || ny > SIZE) continue; + + if (board[ny][nx] != 1 || visited[ny][nx]) continue; + + visited[ny][nx] = true; + q.add(new Point(nx, ny)); + } + } + count++; + } + return -1; + } +} \ No newline at end of file From 77d63f68fa0c49abdf4089d70a4a4e75f79460e3 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 14 Sep 2023 09:58:06 +0900 Subject: [PATCH 771/822] 0914 kihun --- .../\353\271\227\353\254\274.java" | 47 ++++++++++ ...\355\205\234\354\244\215\352\270\260.java" | 85 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 "2023/09.14/\354\206\241\352\270\260\355\233\210/\353\271\227\353\254\274.java" create mode 100644 "2023/09.14/\354\206\241\352\270\260\355\233\210/\354\225\204\354\235\264\355\205\234\354\244\215\352\270\260.java" diff --git "a/2023/09.14/\354\206\241\352\270\260\355\233\210/\353\271\227\353\254\274.java" "b/2023/09.14/\354\206\241\352\270\260\355\233\210/\353\271\227\353\254\274.java" new file mode 100644 index 0000000..1df952a --- /dev/null +++ "b/2023/09.14/\354\206\241\352\270\260\355\233\210/\353\271\227\353\254\274.java" @@ -0,0 +1,47 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 빗물 { + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int H = Integer.parseInt(st.nextToken()); + int W = Integer.parseInt(st.nextToken()); + + int[] walls = new int[W]; + int[] maxWalls = new int[W]; + int temp = Integer.MIN_VALUE; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < W; i++) { + walls[i] = Integer.parseInt(st.nextToken()); + temp = Integer.max(temp, walls[i]); + + // 현재까지 제일 높은 벽 기록 + maxWalls[i] = temp; + } + + int answer = 0; + for (int i = 1; i < W - 1; i++) { + int rightMax = walls[i]; + int leftMax = maxWalls[i]; + + for (int j = i + 1; j < W; j++) { + rightMax = Math.max(rightMax, walls[j]); + } + + if (Math.min(leftMax, rightMax) > walls[i]) { + answer += Math.min(leftMax, rightMax) - walls[i]; + } + } + + System.out.println(answer); + + } + +} diff --git "a/2023/09.14/\354\206\241\352\270\260\355\233\210/\354\225\204\354\235\264\355\205\234\354\244\215\352\270\260.java" "b/2023/09.14/\354\206\241\352\270\260\355\233\210/\354\225\204\354\235\264\355\205\234\354\244\215\352\270\260.java" new file mode 100644 index 0000000..7be02d5 --- /dev/null +++ "b/2023/09.14/\354\206\241\352\270\260\355\233\210/\354\225\204\354\235\264\355\205\234\354\244\215\352\270\260.java" @@ -0,0 +1,85 @@ +package programmers.lv3; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; + +public class 아이템줍기 { + + static int answer; + + static int[][] matrix; + static boolean[][] visited; + + static int[] dX = {1, 0, -1, 0}; + static int[] dY = {0, 1, 0, -1}; + + public int solution(int[][] rectangle, int characterX, int characterY, int itemX, int itemY) { + answer = 0; + matrix = new int[101][101]; + visited = new boolean[101][101]; + + // 테두리를 1로 내부는 -1 + // 좌표는 2배 해줘야 한다...경로가 아니어도 모두 인접한 한칸이니까 + for (int i = 0; i < rectangle.length; i++) { + int x1 = rectangle[i][0] * 2; + int y1 = rectangle[i][1] * 2; + int x2 = rectangle[i][2] * 2; + int y2 = rectangle[i][3] * 2; + + for (int x = x1 ; x <= x2; x++) { + for (int y = y1; y <= y2; y++) { + // 이미 다른 도형의 내부이면 테두리가 될 수 없음 + if (matrix[x][y] == -1) continue; + matrix[x][y] = -1; + if (x == x1 || x == x2 || y == y1 || y == y2) { + matrix[x][y] = 1; + } + } + } + } + + bfs(characterX * 2, characterY * 2, itemX * 2, itemY * 2); + + return answer / 2; + } + + public void bfs(int characterX, int characterY, int itemX, int itemY) { + LinkedList queue = new LinkedList<>(); + queue.offer(characterX); + queue.offer(characterY); + visited[characterX][characterY] = true; + + while (!queue.isEmpty()) { + int x = queue.poll(); + int y = queue.poll(); + + for (int i = 0; i < 4; i++) { + int nX = x + dX[i]; + int nY = y + dY[i]; + + if (nX < 0 || nY < 0 || nX > 100 || nY > 100) continue; + if (matrix[nX][nY] != 1) continue; + if (visited[nX][nY]) continue; + + matrix[nX][nY] = matrix[x][y] + 1; + + // 도착? + if (nX == itemX && nY == itemY) { + if (answer == 0) { + answer = matrix[nX][nY]; + } else { + answer = Math.min(answer, matrix[nX][nY]); + } + continue; + } + + // 도착 판별 이후에 큐에 넣고 visited 체크해야 여러 곳에서 올 수 있음 + visited[nX][nY] = true; + queue.offer(nX); + queue.offer(nY); + } + } + + } +} From fd5926cbcb9ecfdac0e1f47cb046361e1e5b0be2 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 14 Sep 2023 10:01:43 +0900 Subject: [PATCH 772/822] Create README.md --- 2023/09.14/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/09.14/README.md diff --git a/2023/09.14/README.md b/2023/09.14/README.md new file mode 100644 index 0000000..6772e79 --- /dev/null +++ b/2023/09.14/README.md @@ -0,0 +1,5 @@ +# 9.14(목) 스터디 + +- 프로그래머스 + - [아이템 줍기](https://school.programmers.co.kr/learn/courses/30/lessons/87694) + - [빗물](https://www.acmicpc.net/problem/14719) From 4cada523cb23ae1e20742a0080c9b873e6871c8c Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 15 Sep 2023 20:08:49 +0900 Subject: [PATCH 773/822] Create README.md --- 2023/09.21/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/09.21/README.md diff --git a/2023/09.21/README.md b/2023/09.21/README.md new file mode 100644 index 0000000..bcdfb44 --- /dev/null +++ b/2023/09.21/README.md @@ -0,0 +1,5 @@ +# 9.21(목) 스터디 + +- 프로그래머스 + - [여행경로](https://school.programmers.co.kr/learn/courses/30/lessons/43164) + - [에어컨](https://school.programmers.co.kr/learn/courses/30/lessons/214289) From 1b28c4a6b94e87eba3a670b65936847c82b7e0a4 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 15 Sep 2023 20:09:46 +0900 Subject: [PATCH 774/822] Update README.md --- 2023/09.14/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/2023/09.14/README.md b/2023/09.14/README.md index 6772e79..c5f1cb9 100644 --- a/2023/09.14/README.md +++ b/2023/09.14/README.md @@ -2,4 +2,5 @@ - 프로그래머스 - [아이템 줍기](https://school.programmers.co.kr/learn/courses/30/lessons/87694) +- 백준 - [빗물](https://www.acmicpc.net/problem/14719) From 9103202a68e611fae41f4f78f43a3853a8682a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Thu, 21 Sep 2023 09:28:01 +0900 Subject: [PATCH 775/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=EA=B2=BD=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\226\211\352\262\275\353\241\234.java" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "2023/09.21/\354\241\260\354\210\230\354\227\260/\354\227\254\355\226\211\352\262\275\353\241\234.java" diff --git "a/2023/09.21/\354\241\260\354\210\230\354\227\260/\354\227\254\355\226\211\352\262\275\353\241\234.java" "b/2023/09.21/\354\241\260\354\210\230\354\227\260/\354\227\254\355\226\211\352\262\275\353\241\234.java" new file mode 100644 index 0000000..6e75dd1 --- /dev/null +++ "b/2023/09.21/\354\241\260\354\210\230\354\227\260/\354\227\254\355\226\211\352\262\275\353\241\234.java" @@ -0,0 +1,101 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + String[][] tickets = {{"ICN", "SFO"}, {"ICN", "ATL"}, {"SFO", "ATL"}, {"ATL", "ICN"}, + {"ATL", "SFO"}}; + System.out.println(Arrays.toString(new Solution().solution(tickets))); + } +} + +class Solution { + static final int MAX_SIZE = 10000; + static Map map; + static ArrayList> graph; + static ArrayList paths; + static String[] cities; + static int[][] visited; // 주어진 티켓이 중복일 경우를 고려한 체크 배열 + + public String[] solution(String[][] tickets) { + String[] answer = new String[tickets.length + 1]; + int value = 0; + int start; + int end; + map = new HashMap<>(); + graph = new ArrayList<>(); + paths = new ArrayList<>(); + cities = new String[MAX_SIZE]; + visited = new int[MAX_SIZE][MAX_SIZE]; + + // 인천공항에서 모든 경로가 시작되니 0으로 초기화 + map.put("ICN", 0); + cities[0] = "ICN"; + + for (int i = 0; i < MAX_SIZE; i++) { + graph.add(new ArrayList<>()); + } + + for (String[] ticket : tickets) { // 경로 갱신 + if (!map.containsKey(ticket[0])) { + value++; + start = value; + map.put(ticket[0], start); + cities[start] = ticket[0]; + } else start = map.get(ticket[0]); + + if (!map.containsKey(ticket[1])) { + value++; + end = value; + map.put(ticket[1], end); + cities[end] = ticket[1]; + } else end = map.get(ticket[1]); + + visited[start][end]++; + graph.get(start).add(end); + } + + int[] arr = new int[tickets.length + 1]; + + dfs(0, 1, tickets.length + 1, arr); + + Collections.sort(paths); // 사전순으로 정렬 + + String path = paths.get(0); + StringBuilder sb = new StringBuilder(); + int idx = 0; + + for (int i = 0; i < path.length(); i++) { + sb.append(path.charAt(i)); + + if (i % 3 == 2) { + answer[idx++] = sb.toString(); + sb.setLength(0); + } + } + + return answer; + } + + public void dfs(int city, int idx, int size, int[] arr) { + if (idx == size) { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < arr.length; i++) { + sb.append(cities[arr[i]]); + } + + paths.add(sb.toString()); + + return; + } + + for (int next : graph.get(city)) { + if (visited[city][next] > 0) { + visited[city][next]--; + arr[idx] = next; + dfs(next, idx + 1, size, arr); + visited[city][next]++; + } + } + } +} \ No newline at end of file From 9cf9236550b6ec31eea5082dcf5ed2eab5950ce3 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 21 Sep 2023 09:43:51 +0900 Subject: [PATCH 776/822] 0921 kihun --- ...\354\227\220\354\226\264\354\273\250.java" | 62 +++++++++++++++++++ ...\355\226\211\352\262\275\353\241\234.java" | 39 ++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 "2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\220\354\226\264\354\273\250.java" create mode 100644 "2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\254\355\226\211\352\262\275\353\241\234.java" diff --git "a/2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\220\354\226\264\354\273\250.java" "b/2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\220\354\226\264\354\273\250.java" new file mode 100644 index 0000000..155a2b3 --- /dev/null +++ "b/2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\220\354\226\264\354\273\250.java" @@ -0,0 +1,62 @@ +package programmers.lv3; + +import java.util.Arrays; + +public class 에어컨 { + public int solution(int temperature, int t1, int t2, int a, int b, int[] onboard) { + // a가 100 이하, onboard 길이가 1000 이하 + int maxValue = 100 * 1000; + // -10도에서 40도까지, t1과 t2의 좌표도 그에 맞게 바꾸어준다 + t1 += 10; + t2 += 10; + temperature += 10; + int[][] dp = new int[onboard.length][51]; + for (int[] d : dp) { + Arrays.fill(d, maxValue); + } + + // 에어컨을 켜지 않았을 때 생기는 온도 변화 + int delta = -1; + if (temperature > t2) { + delta = 1; + } + dp[0][temperature] = 0; + for (int i = 1; i < onboard.length; i++) { + for (int t = 0; t < 51; t++) { + int minValue = 50000; + if ((onboard[i] == 1 && t1 <= t && t <= t2) || onboard[i] == 0) { + + // 에어컨을 켜지 않음 + 실외온도와 다름 + if (0 <= t - delta && t - delta <= 50) { + minValue = Math.min(minValue, dp[i - 1][t - delta]); + } + + // 에어컨을 켜지 않음 + 실외온도와 같음 + if (t == temperature) { + minValue = Math.min(minValue, dp[i - 1][t]); + } + + // 에어컨을 켬 + 적정 온도가 아님 + if (0 <= t + delta && t + delta <= 50) { + minValue = Math.min(minValue, dp[i - 1][t + delta] + a); + } + + // 에어컨을 켬 + 적정 온도임 + if (t1 <= t && t <= t2) { + minValue = Math.min(minValue, dp[i - 1][t] + b); + } + + dp[i][t] = minValue; + } + } + } + + int answer = maxValue; + for (int t = 1; t < 51; t++) { + answer = Math.min(dp[onboard.length - 1][t], answer); + } + + return answer; + } + +} \ No newline at end of file diff --git "a/2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\254\355\226\211\352\262\275\353\241\234.java" "b/2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\254\355\226\211\352\262\275\353\241\234.java" new file mode 100644 index 0000000..eecbace --- /dev/null +++ "b/2023/09.21/\354\206\241\352\270\260\355\233\210/\354\227\254\355\226\211\352\262\275\353\241\234.java" @@ -0,0 +1,39 @@ +package programmers.lv3; + +import java.util.*; + +public class 여행경로 { + + boolean[] visited; + ArrayList answer; + int maxDepth; + + public String[] solution(String[][] tickets) { + visited = new boolean[tickets.length]; + answer = new ArrayList<>(); + maxDepth = tickets.length; + + dfs(0, "ICN", "ICN", tickets); + + Collections.sort(answer); + + return answer.get(0).split(" "); + } + + public void dfs(int depth, String now, String path, String[][] tickets) { + if (depth == maxDepth) { + answer.add(path); + return; + } + + for (int i = 0; i < maxDepth; i++) { + String start = tickets[i][0]; + String end = tickets[i][1]; + if (!visited[i] && start.equals(now)) { + visited[i] = true; + dfs(depth + 1, tickets[i][1], path + " " + end, tickets); + visited[i] = false; + } + } + } +} From 015cf7f613613f8ba52ca10ccb2b2d80aa176388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Thu, 21 Sep 2023 21:42:34 +0900 Subject: [PATCH 777/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=ED=83=9D?= =?UTF-8?q?=EB=B0=B0=20=EB=B0=B0=EB=8B=AC=EA=B3=BC=20=EC=88=98=EA=B1=B0?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\261\260\355\225\230\352\270\260.java" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "2023/09.25/\354\241\260\354\210\230\354\227\260/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" diff --git "a/2023/09.25/\354\241\260\354\210\230\354\227\260/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" "b/2023/09.25/\354\241\260\354\210\230\354\227\260/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" new file mode 100644 index 0000000..166351c --- /dev/null +++ "b/2023/09.25/\354\241\260\354\210\230\354\227\260/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" @@ -0,0 +1,63 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + int cap = 4, n = 5; + int[] deliveries = {1, 0, 3, 1, 2}; + int[] pickups = {0, 3, 0, 4, 0}; + System.out.println((new Solution().solution(cap, n, deliveries, pickups))); + } +} + +class Solution { + public long solution(int cap, int n, int[] deliveries, int[] pickups) { + long answer = 0; + + Stack dStack = new Stack<>(); + Stack pStack = new Stack<>(); + + for (int i = 0; i < n; i++) { + if (deliveries[i] > 0) dStack.add(i); + } + + for (int i = 0; i < n; i++) { + if (pickups[i] > 0) pStack.add(i); + } + + while (true) { + if (!dStack.isEmpty() && !pStack.isEmpty()) { // 배달과 수거할 물품이 있는 경우 + answer += (Math.max(dStack.peek(), pStack.peek()) + 1) * 2L; + } + if (!dStack.isEmpty() && pStack.isEmpty()) { // 수거할 물품만 있는 경우 + answer += (dStack.peek() + 1) * 2L; + } + if (dStack.isEmpty() && !pStack.isEmpty()) { // 배달할 물품만 있는 경우 + answer += (pStack.peek() + 1) * 2L; + } + if (dStack.isEmpty() && pStack.isEmpty()) break; + + int dCount = cap; + + while (!dStack.isEmpty()) { + if (dCount <= 0) break; + if (deliveries[dStack.peek()] <= dCount) dCount -= deliveries[dStack.pop()]; + else { + deliveries[dStack.peek()] -= dCount; + break; + } + } + + int pCount = 0; + + while (!pStack.isEmpty()) { + if (pCount == cap) break; + if (pickups[pStack.peek()] + pCount <= cap) pCount += pickups[pStack.pop()]; + else { + pickups[pStack.peek()] -= cap - pCount; + break; + } + } + } + return answer; + } +} \ No newline at end of file From bbb6a3cde283ec4e084cbdac4aa45b155750274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=88=98=EC=97=B0?= Date: Fri, 22 Sep 2023 09:08:33 +0900 Subject: [PATCH 778/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=B6=88?= =?UTF-8?q?=EB=9F=89=20=EC=82=AC=EC=9A=A9=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\254\354\232\251\354\236\220.java" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "2023/09.25/\354\241\260\354\210\230\354\227\260/\353\266\210\353\237\211_\354\202\254\354\232\251\354\236\220.java" diff --git "a/2023/09.25/\354\241\260\354\210\230\354\227\260/\353\266\210\353\237\211_\354\202\254\354\232\251\354\236\220.java" "b/2023/09.25/\354\241\260\354\210\230\354\227\260/\353\266\210\353\237\211_\354\202\254\354\232\251\354\236\220.java" new file mode 100644 index 0000000..9dc5dfc --- /dev/null +++ "b/2023/09.25/\354\241\260\354\210\230\354\227\260/\353\266\210\353\237\211_\354\202\254\354\232\251\354\236\220.java" @@ -0,0 +1,87 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + String[] user_id = {"frodo", "fradi", "crodo", "abc123", "frodoc"}; + String[] banned_id = {"fr*d*", "*rodo", "******", "******"}; + System.out.println((new Solution().solution(user_id, banned_id))); + } +} + +class Solution { + static Set set; + Map map; + List[] banList; + boolean[] visited; + + public int solution(String[] user_id, String[] banned_id) { + set = new HashSet<>(); + map = new HashMap<>(); + banList = new List[banned_id.length]; + visited = new boolean[user_id.length]; + + for (int i = 0; i < banned_id.length; i++) { + banList[i] = new ArrayList<>(); + } + + for (int i = 0; i < user_id.length; i++) { + map.put(user_id[i], i); + } + + for (int i = 0; i < banned_id.length; i++) { + for (int j = 0; j < user_id.length; j++) { + if (banned_id[i].length() != user_id[j].length()) continue; + + boolean isMatch = true; + + for (int k = 0; k < banned_id[i].length(); k++) { + if (banned_id[i].charAt(k) == '*') continue; // *은 패스 + + if (banned_id[i].charAt(k) != user_id[j].charAt(k)) { // 문자가 일치하지 않는 경우 + isMatch = false; + break; + } + } + + if (isMatch) banList[i].add(map.get(user_id[j])); + } + } + + int[] banArr = new int[banned_id.length]; + + comb(0, banned_id.length, banArr); + + return set.size(); + } + + public void comb(int idx, int size, int[] banArr) { + if (idx == size) { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < banArr.length; i++) { + sb.append(banArr[i]); + } + + // 중복 되는 경우의 수를 체크하기 위해 정려 + char[] charArr = sb.toString().toCharArray(); + Arrays.sort(charArr); + + String result = new String(charArr); + + set.add(result); + + return; + } + + for (int i = 0; i < banList[idx].size(); i++) { + if (!visited[banList[idx].get(i)]) { + visited[banList[idx].get(i)] = true; + banArr[idx] = banList[idx].get(i); + + comb(idx + 1, size, banArr); + + visited[banList[idx].get(i)] = false; + } + } + } +} \ No newline at end of file From 0e6806787426de6fbabfaea4fe6988b05eea41b5 Mon Sep 17 00:00:00 2001 From: suyong5713 Date: Fri, 22 Sep 2023 23:24:34 +0900 Subject: [PATCH 779/822] =?UTF-8?q?[SOLVE]=20@suyong5713=20-=20=EB=B6=88?= =?UTF-8?q?=EB=9F=89=20=EC=82=AC=EC=9A=A9=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\266\231\354\235\264\352\270\260.java" | 101 ++++++++++++++++++ ...\354\202\254\354\232\251\354\236\220.java" | 45 ++++++++ 2 files changed, 146 insertions(+) create mode 100644 "2023/08.31/\354\235\264\354\210\230\354\232\251/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" create mode 100644 "2023/09.25/\354\235\264\354\210\230\354\232\251/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" diff --git "a/2023/08.31/\354\235\264\354\210\230\354\232\251/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" "b/2023/08.31/\354\235\264\354\210\230\354\232\251/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" new file mode 100644 index 0000000..07d6bc9 --- /dev/null +++ "b/2023/08.31/\354\235\264\354\210\230\354\232\251/\354\212\244\355\213\260\354\273\244\353\266\231\354\235\264\352\270\260.java" @@ -0,0 +1,101 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 스티커붙이기 { + static int N; + static int M; + static int K; + static int[][] board; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + board = new int[N][M]; + for (int i = 0; i < board.length; i++) { + Arrays.fill(board[i], 0); + } + ArrayList stickerList = new ArrayList<>(); + for (int k = 0; k < K; k++) { + st = new StringTokenizer(br.readLine()); + int height = Integer.parseInt(st.nextToken()); + int width = Integer.parseInt(st.nextToken()); + int[][] sticker = new int[height][width]; + for (int i = 0; i < height; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < width; j++) { + sticker[i][j] = Integer.parseInt(st.nextToken()); + } + } + stickerList.add(sticker); + } + int rotateCount = 0; + while (!stickerList.isEmpty()) { + int[][] sticker = stickerList.remove(0); + boolean attached = false; + for (int i = 0; i < N && !attached; i++) { + for (int j = 0; j < M && !attached; j++) { + boolean available = true; + for (int k = 0; k < sticker.length && available; k++) { + if (i + k >= N) break; + for (int l = 0; l < sticker[0].length; l++) { + if (j + l >= M) break; + if (sticker[k][l] != 0) { + if (board[i + k][j + l] != 0) { + available = false; + break; + } + } + // 정상적으로 스티커 배열 끝까지 다 돌았으면, 붙임 + if (k == sticker.length - 1 && l == sticker[0].length - 1) { + attached = true; + for (int x = 0; x < sticker.length; x++) { + for (int y = 0; y < sticker[0].length; y++) { + if (sticker[x][y] == 1) board[i + x][j + y] = 1; + } + } + } + } + } + } + } + if (!attached) { + // 90도 180도 270도 다안되면 + if (rotateCount == 4) { + rotateCount = 0; + } else { + int[][] rotatedSticker = rotateSticker(sticker); + stickerList.add(0, rotatedSticker); + rotateCount++; + } + }else{ + rotateCount = 0; + } + } + int answer = 0; + for(int[] row : board){ + for(int val: row){ + answer += val; + } + } + System.out.println(answer); + } + + static int[][] rotateSticker(int[][] sticker) { + int height = sticker.length; + int width = sticker[0].length; + int[][] rotatedSticker = new int[width][height]; + for (int i = 0; i < rotatedSticker.length; i++) { + for (int j = 0; j < rotatedSticker[i].length; j++) { + rotatedSticker[i][j] = sticker[height - 1 - j][i]; + } + } + return rotatedSticker; + } +} diff --git "a/2023/09.25/\354\235\264\354\210\230\354\232\251/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" "b/2023/09.25/\354\235\264\354\210\230\354\232\251/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" new file mode 100644 index 0000000..05fc9f3 --- /dev/null +++ "b/2023/09.25/\354\235\264\354\210\230\354\232\251/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" @@ -0,0 +1,45 @@ +import java.util.ArrayList; +import java.util.HashSet; + +class 불량사용자 { + HashSet> result; + ArrayList> bannedUserList; + + public int solution(String[] user_id, String[] banned_id) { + result = new HashSet>(); + bannedUserList = new ArrayList>(); + for (String bannedId : banned_id) { + bannedUserList.add(getMatchesId(bannedId, user_id)); + } + backTracking(new HashSet(), 0); + + return result.size(); + } + + ArrayList getMatchesId(String bannedId, String[] user_id) { + bannedId = bannedId.replace("*", "."); + + ArrayList valueList = new ArrayList<>(); + for (String userId : user_id) { + if (userId.matches(bannedId)){ + valueList.add(userId); + } + } + return valueList; + } + + void backTracking(HashSet set, int depth) { + if (depth == bannedUserList.size()) { + result.add(new HashSet<>(set)); + return; + } + + for (String userId : bannedUserList.get(depth)) { + if (!set.contains(userId)) { + set.add(userId); + backTracking(set, depth + 1); + set.remove(userId); + } + } + } +} \ No newline at end of file From a558dbd41113ed627f48606ca63b69c4c76c276a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 24 Sep 2023 15:01:49 +0900 Subject: [PATCH 780/822] Create README.md --- 2023/09.25/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/09.25/README.md diff --git a/2023/09.25/README.md b/2023/09.25/README.md new file mode 100644 index 0000000..a611c78 --- /dev/null +++ b/2023/09.25/README.md @@ -0,0 +1,5 @@ +# 9.25(월) 스터디 + +- 프로그래머스 + - [택배 배달과 수거하기](https://school.programmers.co.kr/learn/courses/30/lessons/150369) + - [불량 사용자](https://school.programmers.co.kr/learn/courses/30/lessons/64064) From 0493b3d0d4fbe30a38244ede97becedec88ba6b2 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 24 Sep 2023 15:02:17 +0900 Subject: [PATCH 781/822] 0925 kihun --- ...\354\202\254\354\232\251\354\236\220.java" | 64 +++++++++++ ...\352\261\260\355\225\230\352\270\260.java" | 108 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 "2023/09.25/\354\206\241\352\270\260\355\233\210/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" create mode 100644 "2023/09.25/\354\206\241\352\270\260\355\233\210/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" diff --git "a/2023/09.25/\354\206\241\352\270\260\355\233\210/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" "b/2023/09.25/\354\206\241\352\270\260\355\233\210/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" new file mode 100644 index 0000000..6efdf07 --- /dev/null +++ "b/2023/09.25/\354\206\241\352\270\260\355\233\210/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" @@ -0,0 +1,64 @@ +package programmers.lv3; + +import java.util.Arrays; +import java.util.HashSet; + +class Test { + public static void main(String[] args) { + String[] user_Id = {"frodo", "fradi", "crodo", "abc123", "frodoc"}; + String[] banned_id = {"fr*d*", "abc1**"}; + + new 불량사용자().solution(user_Id, banned_id); + } +} + + +public class 불량사용자 { + + String[] userId; + String[] bannedId; + boolean[] visited; + HashSet hashSet; + + public int solution(String[] user_id, String[] banned_id) { + userId = user_id; + bannedId = banned_id; + visited = new boolean[user_id.length]; + hashSet = new HashSet<>(); + + for (int i = 0; i < bannedId.length; i++) { + bannedId[i] = bannedId[i].replace('*', '.'); + } + + dfs(0, ""); + + return hashSet.size(); + } + + public void dfs(int depth, String ids) { + if (depth == bannedId.length) { + if (!ids.isBlank() && !ids.isEmpty()) { + String[] result = ids.split(" "); + Arrays.sort(result); + + StringBuilder sb = new StringBuilder(); + for (String r : result) { + sb.append(r); + } + hashSet.add(sb.toString()); + } + + return; + } + + for (int i = 0; i < userId.length; i++) { + if (visited[i]) continue; + if (!userId[i].matches(bannedId[depth])) continue; + + visited[i] = true; + dfs(depth + 1, ids + " " + userId[i]); + visited[i] = false; + } + } + +} diff --git "a/2023/09.25/\354\206\241\352\270\260\355\233\210/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" "b/2023/09.25/\354\206\241\352\270\260\355\233\210/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" new file mode 100644 index 0000000..e631be1 --- /dev/null +++ "b/2023/09.25/\354\206\241\352\270\260\355\233\210/\355\203\235\353\260\260_\353\260\260\353\213\254\352\263\274_\354\210\230\352\261\260\355\225\230\352\270\260.java" @@ -0,0 +1,108 @@ +package programmers.lv2; + +import java.util.Arrays; + +class Test { + public static void main(String[] args) { +// int cap = 2; +// int n = 7; +// int[] deliveries = {1, 0, 2, 0, 1, 0, 2}; +// int[] pickups = {0, 2, 0, 1, 0, 2, 0}; + + int cap = 4; + int n = 5; + int[] deliveries = {1, 0, 3, 1, 2}; + int[] pickups = {0, 3, 0, 4, 0}; + + new 택배_배달과_수거하기().solution(cap, n, deliveries, pickups); + } +} + + +public class 택배_배달과_수거하기 { + +// public long solution(int cap, int n, int[] deliveries, int[] pickups) { +// long answer = 0; +// int d = 0; +// int p = 0; +// +// for (int i = n-1; i >= 0; i--) { +// if (deliveries[i] > 0 || pickups[i] > 0) { +// int count = 0; +// // 몇 번 와야됨? +// while (d < deliveries[i] || p < pickups[i]) { +// count += 1; +// d += cap; +// p += cap; +// } +// d -= deliveries[i]; +// p -= pickups[i]; +// answer += (long) (i + 1) * count * 2; +// } +// } +// +// return answer; +// } + + + public long solution(int cap, int n, int[] deliveries, int[] pickups) { + long answer = 0; + + int dIndex = n - 1; + int pIndex = n - 1; + + while (dIndex >= 0 || pIndex >= 0) { + + while (dIndex >= 0 && deliveries[dIndex] == 0) { + dIndex--; + } + while (pIndex >= 0 && pickups[pIndex] == 0) { + pIndex--; + } + + int carry = 0; + + answer += (Math.max(dIndex, pIndex) + 1) * 2L; + + // 배달 + while (dIndex >= 0 && carry < cap) { + carry += deliveries[dIndex]; + deliveries[dIndex] = 0; + dIndex -= 1; + } + System.out.println("c: " + carry); + System.out.println("d1: " + Arrays.toString(deliveries)); + if (carry > cap) { + dIndex += 1; + deliveries[dIndex] = carry - cap; + } + System.out.println("dI: " + dIndex); + System.out.println("d2: " + Arrays.toString(deliveries)); + + carry = 0; + // 수거 + while (pIndex >= 0 && carry < cap) { + carry += pickups[pIndex]; + pickups[pIndex] = 0; + pIndex -= 1; + } + System.out.println("c: " + carry); + System.out.println("p1: " + Arrays.toString(pickups)); + if (carry > cap) { + pIndex += 1; + pickups[pIndex] = carry - cap; + } + System.out.println("pI: " + pIndex); + System.out.println("p2: " + Arrays.toString(pickups)); + } + + + return answer; + } + + +} + + + + From ea7de7774a225a2f9e989ec682a5a44201f5603a Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 25 Sep 2023 12:11:37 +0900 Subject: [PATCH 782/822] =?UTF-8?q?Create=20=EB=B6=88=EB=9F=89=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\254\354\232\251\354\236\220.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "2023/09.25/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" diff --git "a/2023/09.25/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" "b/2023/09.25/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" new file mode 100644 index 0000000..1d5637f --- /dev/null +++ "b/2023/09.25/\353\266\210\353\237\211\354\202\254\354\232\251\354\236\220.java" @@ -0,0 +1,70 @@ +import java.util.*; + +public class 불량사용자 { + public static void main(String[] args) { + String[] user_id = {"frodo", "fradi", "crodo", "abc123", "frodoc"}; + String[] banned_id = {"*rodo", "*rodo", "******"}; + + Solution s = new Solution(); + + s.solution(user_id, banned_id); + } + + static class Solution { + + String[] userIds; + String[] bannedIds; + Set> result = new HashSet<>(); + + public int solution(String[] user_id, String[] banned_id) { + userIds = user_id; + bannedIds = banned_id; + + dfs(new HashSet<>(), 0); + + System.out.println("최종 : " + result.toString()); + + return result.size(); + } + + void dfs(Set set, int depth) { + if (depth == bannedIds.length) { +// System.out.println(Arrays.toString(set.toArray())); + result.add(set); + System.out.println(set); + +// System.out.println(result.toString()); + System.out.println(); + return; + } + + for (int i = 0; i < userIds.length; i++) { + if (set.contains(userIds[i])) { + continue; + } + + if (check(userIds[i], bannedIds[depth])) { + set.add(userIds[i]); + dfs(new HashSet<>(set), depth + 1); + set.remove(userIds[i]); + } + } + } + + boolean check(String userId, String bannedId) { + if (userId.length() != bannedId.length()) { + return false; + } + + boolean match = true; + for (int i = 0; i < userId.length(); i++) { + if (bannedId.charAt(i) != '*' && userId.charAt(i) != bannedId.charAt(i)) { + match = false; + break; + } + } + + return match; + } + } +} From 44a58f147a6c4d961662f2a3e26a7fe4503eb22e Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 27 Sep 2023 11:33:13 +0900 Subject: [PATCH 783/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=A7=95?= =?UTF-8?q?=EA=B2=80=EB=8B=A4=EB=A6=AC=20=EA=B1=B4=EB=84=88=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\261\264\353\204\210\352\270\260.java" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" diff --git "a/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" "b/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" new file mode 100644 index 0000000..d172ebb --- /dev/null +++ "b/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" @@ -0,0 +1,42 @@ +class Test { + public static void main(String[] args) { + int[] stones = {2, 4, 5, 3, 2, 1, 4, 2, 5, 1}; + int k = 3; + new Solution().solution(stones, k); + } +} + +class Solution { + public int solution(int[] stones, int k) { + int answer = 0; + int min = 1; + int max = 200000000; + + while (min <= max) { + int mid = (min + max) / 2; + + if (canCross(k, mid, stones)) { // 해당 인원이 다리를 건널 수 있으면 최소 인원을 증가시켜 다시 탐색 + min = mid + 1; + answer = Math.max(answer, mid); + } else { // 해당 인원이 다리를 못 건너는 경우 최대 인원을 감소시켜 다시 탐색 + max = mid - 1; + } + } + return answer; + } + + public boolean canCross(int k, int people, int[] stones) { + int cnt = 0; + + for (int stone : stones) { + if (stone < people) { // 디딤돌의 갯수가 건너는 사람 수보다 작다 -> 건너뛰는 시작점 + cnt++; // 건너뛰는 칸수 갱신 + } else { // 시작점 이후에 디딤돌의 갯수가 건너는 사람 수보다 많으면 건너뛰는 칸수 다시 0으로 초기화 + cnt = 0; + } + + if (cnt == k) return false; // 최대 칸수를 넘으면 종료 + } + return true; + } +} \ No newline at end of file From 49166ad29c7fc974d7549a86610ca8626c7bb92d Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 27 Sep 2023 19:42:26 +0900 Subject: [PATCH 784/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=9E=90?= =?UTF-8?q?=EB=AC=BC=EC=87=A0=EC=99=80=20=EC=97=B4=EC=87=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\231\200_\354\227\264\354\207\240.java" | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" diff --git "a/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" "b/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" new file mode 100644 index 0000000..e6c7b64 --- /dev/null +++ "b/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" @@ -0,0 +1,78 @@ +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; + +class Test { + public static void main(String[] args) { + int[][] key = {{0, 0, 0}, {1, 0, 0}, {0, 1, 1}}; + int[][] lock = {{1, 1, 1}, {1, 1, 0}, {1, 0, 1}}; + new Solution().solution(key, lock); + } +} + +class Solution { + static int n; + static int m; + static int move; // key 이동거리 + + public boolean solution(int[][] key, int[][] lock) { + n = lock.length; + m = key.length; + move = m - 1; + + // 이동 거리는 자물쇠의 길이 + 열쇠의 길이 - 겹치는 부분(1) + for (int x = 0; x < move + n; x++) { + for (int y = 0; y < move + n; y++) { + for (int r = 0; r < 4; r++) { + int[][] map = new int[n + m * 2][n + m * 2]; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + map[i + move][j + move] = lock[i][j]; + } + } + + rotate(map, key, r, x, y); + + if (check(map)) return true; + } + } + } + + return false; + } + + + // 키를 회전한 후 map 배열에 더해준다. + public void rotate(int[][] map, int[][] key, int degree, int x, int y) { + for (int i = 0; i < m; i++) { + for (int j = 0; j < m; j++) { + switch (degree) { + case 0: + map[y + i][x + j] += key[i][j]; + break; + case 1: + map[y + i][x + j] += key[j][m - i - 1]; + break; + case 2: + map[y + i][x + j] += key[m - i - 1][m - j - 1]; + break; + case 3: + map[y + i][x + j] += key[m - j - 1][i]; + break; + } + } + } + } + + public boolean check(int[][] map) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + // map 영역에 자물쇠에 값이 0이거나 2이면 열쇠가 맞지 않음 + if (map[move + i][move + j] != 1) return false; + } + } + + return true; + } +} \ No newline at end of file From 01acdf81cd0eb416c69a72e1a1afb2fe5603bc1b Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 5 Oct 2023 10:17:57 +0900 Subject: [PATCH 785/822] rename folder --- ...254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" | 0 ...213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename "2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" => "2023/10.05/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" (100%) rename "2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" => "2023/10.05/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" (100%) diff --git "a/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" "b/2023/10.05/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" similarity index 100% rename from "2023/09.28/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" rename to "2023/10.05/\354\241\260\354\210\230\354\227\260/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" diff --git "a/2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" "b/2023/10.05/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" similarity index 100% rename from "2023/09.28/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" rename to "2023/10.05/\354\241\260\354\210\230\354\227\260/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" From 8d39c8b5c0ea7138f6ca6f5260862652cfbd9baf Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 5 Oct 2023 10:18:27 +0900 Subject: [PATCH 786/822] 1005 kihun --- ...354\231\200_\354\227\264\354\207\240.java" | 90 +++++++++++++++++++ ...\352\261\264\353\204\210\352\270\260.java" | 57 ++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 "2023/10.05/\354\206\241\352\270\260\355\233\210/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" create mode 100644 "2023/10.05/\354\206\241\352\270\260\355\233\210/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" diff --git "a/2023/10.05/\354\206\241\352\270\260\355\233\210/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" "b/2023/10.05/\354\206\241\352\270\260\355\233\210/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" new file mode 100644 index 0000000..8adbf37 --- /dev/null +++ "b/2023/10.05/\354\206\241\352\270\260\355\233\210/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240.java" @@ -0,0 +1,90 @@ +package programmers.lv3; + +class Test { + public static void main(String[] args) { + int[][] key = {{0, 0, 0}, {1, 0, 0}, {0, 1, 1}}; + int[][] lock = {{1, 1, 1}, {1, 1, 0}, {1, 0, 1}}; + System.out.println(new 자물쇠와_열쇠().solution(key, lock)); + } + +} + +public class 자물쇠와_열쇠 { + + int m, n, mLen; + int[][] matrix; + public boolean solution(int[][] key, int[][] lock) { + m = key.length; + n = lock.length; + mLen = m * 2 + n - 2; + matrix = new int[mLen][mLen]; + + for (int i = m - 1; i < m + n - 1; i++) { + for (int j = m - 1; j < m + n - 1; j++) { + matrix[i][j] = lock[i - m + 1][j - m + 1]; + } + } + + for (int i = 0; i < 4; i++) { + if (check(key)) { + return true; + } + rotate(key); + } + + return false; + } + + public void rotate(int[][] temp) { + int[][] res = new int[m][m]; + + for (int i = 0; i < m; i++) { + for (int j = 0; j < m; j++) { + res[i][j] = temp[m - j - 1][i]; + } + } + + for (int i = 0; i < m; i++) { + for (int j = 0; j < m; j++) { + temp[i][j] = res[i][j]; + } + } + } + + public boolean check(int[][] key) { + + for (int i = 0; i < mLen - m + 1; i++) { + for (int j = 0; j < mLen - m + 1; j++) { + + for (int y = 0; y < m; y++) { + for (int x = 0; x < m; x++) { + matrix[i + y][j + x] += key[y][x]; + } + } + + boolean flag = true; + for (int y = m - 1; y < m + n - 1; y++) { + for (int x = m - 1; x < m + n - 1; x++) { + if (matrix[y][x] != 1) { + flag = false; + break; + } + } + if (!flag) break; + } + + if (flag) return true; + + // 원상복구 + for (int y = 0; y < m; y++) { + for (int x = 0; x < m; x++) { + matrix[i + y][j + x] -= key[y][x]; + } + } + } + } + + return false; + } + +} diff --git "a/2023/10.05/\354\206\241\352\270\260\355\233\210/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" "b/2023/10.05/\354\206\241\352\270\260\355\233\210/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" new file mode 100644 index 0000000..7274448 --- /dev/null +++ "b/2023/10.05/\354\206\241\352\270\260\355\233\210/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" @@ -0,0 +1,57 @@ +package programmers.lv3; + +import java.util.Arrays; + +class Test { + + public static void main(String[] args) { + int[] stones = {2, 4, 5, 3, 2, 1, 4, 2, 5, 1}; + int k = 3; + new 징검다리_건너기().solution(stones, k); + } + +} + +public class 징검다리_건너기 { + public int solution(int[] stones, int k) { + int answer = 0; + + int minValue = 1; + int maxValue = 200000000; + + while (minValue <= maxValue) { + int mid = (minValue + maxValue) / 2; + + if (check(stones, k, mid)) { + minValue = mid + 1; + answer = Math.max(answer, mid); + } else { + maxValue = mid - 1; + } + + } + + return answer; + } + + boolean check(int[] stones, int k, int value) { + int count = 0; + + for (int i = 0; i < stones.length; i++) { + if (stones[i] < value) { + // value 명 만큼 건널 수 없음 -> 점프 + count += 1; + } else { + count = 0; + } + + if (count == k) { + // 점프 최대거리 + return false; + } + } + + return true; + } + +} From 7662e156df7d729ca9bd42599c88276e8927239d Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 5 Oct 2023 10:21:19 +0900 Subject: [PATCH 787/822] Create README.md --- 2023/10.05/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/10.05/README.md diff --git a/2023/10.05/README.md b/2023/10.05/README.md new file mode 100644 index 0000000..5b7cb73 --- /dev/null +++ b/2023/10.05/README.md @@ -0,0 +1,5 @@ +# 10.5(목) 스터디 + +- 프로그래머스 + - [자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059) + - [징검다리 건너기](https://school.programmers.co.kr/learn/courses/30/lessons/64062) From d05152625156820d5aee560a20d11ca4f9b9dc49 Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 5 Oct 2023 17:03:56 +0900 Subject: [PATCH 788/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20110=20?= =?UTF-8?q?=EC=98=AE=EA=B8=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\230\256\352\270\260\352\270\260.java" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "2023/10.09/\354\241\260\354\210\230\354\227\260/110_\354\230\256\352\270\260\352\270\260.java" diff --git "a/2023/10.09/\354\241\260\354\210\230\354\227\260/110_\354\230\256\352\270\260\352\270\260.java" "b/2023/10.09/\354\241\260\354\210\230\354\227\260/110_\354\230\256\352\270\260\352\270\260.java" new file mode 100644 index 0000000..1bdc72f --- /dev/null +++ "b/2023/10.09/\354\241\260\354\210\230\354\227\260/110_\354\230\256\352\270\260\352\270\260.java" @@ -0,0 +1,69 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + String[] s = {"1110", "100111100", "0111111010"}; + new Solution().solution(s); + } +} + +class Solution { + public String[] solution(String[] s) { + int sLen = s.length; + String[] answer = new String[sLen]; + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < sLen; i++) { + String str = s[i]; + Stack stack = new Stack<>(); + int cnt = 0; + + for (int j = 0; j < str.length(); j++) { + char c = str.charAt(j); + + if (stack.size() > 1) { // 스택의 크기가 2이상일 경우 "110" 문자열 체크 + char b = stack.pop(); + char a = stack.pop(); + + if (a == '1' && b == '1' && c == '0') cnt++; + else { // "110"이 아니라면 다시 스택에 넣기 + stack.push(a); + stack.push(b); + stack.push(c); + } + } else { + stack.push(c); + } + } + + // 문자열에 "110"이 존재할 경우 + if (cnt > 0) { + int insertIdx = stack.size(); // 삽입할 위치 + boolean isZero = false; + + // 마지막 0 위치 찾기 + while (!stack.isEmpty()) { + if (!isZero) { + if (stack.peek() == '1') insertIdx--; + else isZero = true; + } + + sb.insert(0, stack.pop()); + } + + // 마지막 0 위치 뒤에 "110" 삽입 + while (cnt-- > 0) { + sb.insert(insertIdx, "110"); + insertIdx += 3; + } + + answer[i] = sb.toString(); + + } else answer[i] = s[i]; + + sb.setLength(0); + } + + return answer; + } +} \ No newline at end of file From 3fb80d3a23de67f7184af032beb670723ba929be Mon Sep 17 00:00:00 2001 From: su6378 Date: Thu, 5 Oct 2023 21:23:21 +0900 Subject: [PATCH 789/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=202=EC=B0=A8?= =?UTF-8?q?=EC=9B=90=20=EB=8F=99=EC=A0=84=20=EB=92=A4=EC=A7=91=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\222\244\354\247\221\352\270\260.java" | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 "2023/10.09/\354\241\260\354\210\230\354\227\260/2\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" diff --git "a/2023/10.09/\354\241\260\354\210\230\354\227\260/2\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" "b/2023/10.09/\354\241\260\354\210\230\354\227\260/2\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" new file mode 100644 index 0000000..db3eb43 --- /dev/null +++ "b/2023/10.09/\354\241\260\354\210\230\354\227\260/2\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" @@ -0,0 +1,103 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + int[][] beginning = {{0, 1, 0, 0, 0}, {1, 0, 1, 0, 1}, {0, 1, 1, 1, 0}, {1, 0, 1, 1, 0}, {0, 1, 0, 1, 0}}; + int[][] target = {{0, 0, 0, 1, 1}, {0, 0, 0, 0, 1}, {0, 0, 1, 0, 1}, {0, 0, 0, 1, 0}, {0, 0, 0, 0, 1}}; + new Solution().solution(beginning, target); + } +} + +class Solution { + class Coin { + String state; + int count; + ArrayList commandList; + + public Coin(String state, int count, ArrayList commandList) { + this.state = state; + this.count = count; + this.commandList = commandList; + } + } + + static int row; + static int col; + static StringBuilder beginSb; + static StringBuilder targetSb; + HashMap stateMap; + + public int solution(int[][] beginning, int[][] target) { + row = beginning.length; + col = beginning[0].length; + beginSb = new StringBuilder(); + targetSb = new StringBuilder(); + stateMap = new HashMap<>(); + + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { + beginSb.append(beginning[i][j]); + } + } + + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { + targetSb.append(target[i][j]); + } + } + + return bfs(); + } + + public int bfs() { + Queue queue = new LinkedList<>(); + ArrayList commandList = new ArrayList<>(); + + stateMap.put(beginSb.toString(), 1); + queue.add(new Coin(beginSb.toString(), 0, commandList)); + + while (!queue.isEmpty()) { + Coin now = queue.poll(); + + if (now.state.equals(targetSb.toString())) return now.count; + + for (int i = 0; i < row + col; i++) { + ArrayList tempList = new ArrayList<>(now.commandList); + + if (tempList.contains(i)) continue; // 이미 실행한 명령이면 pass + + String change = reverseCoin(now.state, i); + + if (stateMap.containsKey(change)) continue; // 이미 나온 상태이면 pass + + stateMap.put(change, 1); + tempList.add(i); + queue.add(new Coin(change, now.count + 1, tempList)); + } + } + + return -1; + } + + public String reverseCoin(String state, int command) { + StringBuilder changeSb = new StringBuilder(); + + if (command < row) { // 행 뒤집기 + for (int i = 0; i < row * col; i++) { + if (i >= command * col && i < (command + 1) * col) { + if (state.charAt(i) == '1') changeSb.append('0'); + else changeSb.append('1'); + } else changeSb.append(state.charAt(i)); + } + } else { // 열 뒤집기 + for (int i = 0; i < row * col; i++) { + if (i % col == (command - 1) % col) { + if (state.charAt(i) == '1') changeSb.append('0'); + else changeSb.append('1'); + } else changeSb.append(state.charAt(i)); + } + } + + return changeSb.toString(); + } +} \ No newline at end of file From 388ba1b9994621ac7008dd54bfa2d911adaf3437 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 9 Oct 2023 21:27:40 +0900 Subject: [PATCH 790/822] Create README.md --- 2023/10.09/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/10.09/README.md diff --git a/2023/10.09/README.md b/2023/10.09/README.md new file mode 100644 index 0000000..b7fa181 --- /dev/null +++ b/2023/10.09/README.md @@ -0,0 +1,5 @@ +# 10.9(월) 스터디 + +- 프로그래머스 + - [2차원 동전 뒤집기](https://school.programmers.co.kr/learn/courses/30/lessons/131703) + - [110 옮기기](https://school.programmers.co.kr/learn/courses/30/lessons/77886) From 50185aa1f96c35b63fb237ad0ed5cf29a1e1bafe Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 9 Oct 2023 21:27:58 +0900 Subject: [PATCH 791/822] 1009 kihun --- ...\353\222\244\354\247\221\352\270\260.java" | 87 +++++++++++++++++++ ...\354\230\256\352\270\260\352\270\260.java" | 57 ++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 "2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\264\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" create mode 100644 "2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\274\354\230\201_\354\230\256\352\270\260\352\270\260.java" diff --git "a/2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\264\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" "b/2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\264\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" new file mode 100644 index 0000000..8ee13b9 --- /dev/null +++ "b/2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\264\354\260\250\354\233\220_\353\217\231\354\240\204_\353\222\244\354\247\221\352\270\260.java" @@ -0,0 +1,87 @@ +package programmers.lv3; + +//class Test { +// public static void main(String[] args) { +// int[][] beginning = {{0, 1, 0, 0, 0}, {1, 0, 1, 0, 1}, {0, 1, 1, 1, 0}, {1, 0, 1, 1, 0}, {0, 1, 0, 1, 0}}; +// int[][] target = {{0, 0, 0, 1, 1}, {0, 0, 0, 0, 1}, {0, 0, 1, 0, 1}, {0, 0, 0, 1, 0}, {0, 0, 0, 0, 1}}; +// +// System.out.println(new 이차원_동전_뒤집기().solution(beginning, target)); +// } +//} + + +public class 이차원_동전_뒤집기 { + + int n, m; + int answer = Integer.MAX_VALUE; + int[][] beg; + int[][] tar; + + public int solution(int[][] beginning, int[][] target) { + n = beginning.length; + m = beginning[0].length; + beg = beginning; + tar = target; + + dfs(0, 0); + + if (answer == Integer.MAX_VALUE) { + answer = -1; + } + + return answer; + } + + public void flip(int y) { + for (int i = 0; i < m; i++) { + if (beg[y][i] == 1) { + beg[y][i] = 0; + } else { + beg[y][i] = 1; + } + } + } + + public int check(int x) { + int result = 0; + for (int i = 0; i < n; i++) { + if (tar[i][x] == beg[i][x]) { + result += 1; + } + } + if (result == n) { + return 0; + } else if (result == 0) { + return 1; + } else { + return -1; + } + } + + public void dfs(int y, int flipCount) { + if (n == y) { + boolean flag = true; + for (int i = 0; i < m; i++) { + int result = check(i); + if (result == -1) { + flag = false; + break; + } + flipCount += result; + } + + if (flag) { + answer = Math.min(answer, flipCount); + } + return; + } + + flip(y); + dfs(y + 1, flipCount + 1); + + // 원상 복구 + flip(y); + dfs(y + 1, flipCount); + + } +} diff --git "a/2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\274\354\230\201_\354\230\256\352\270\260\352\270\260.java" "b/2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\274\354\230\201_\354\230\256\352\270\260\352\270\260.java" new file mode 100644 index 0000000..86cf7a3 --- /dev/null +++ "b/2023/10.09/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\274\354\230\201_\354\230\256\352\270\260\352\270\260.java" @@ -0,0 +1,57 @@ +package programmers.lv3; + +import java.util.*; + +//class Test { +// +// public static void main(String[] args) { +// String[] s = {"1110", "100111100", "0111111010"}; +// String[] sol = new 일일영_옮기기().solution(s); +// System.out.println(Arrays.toString(sol)); +// } +// +//} + +public class 일일영_옮기기 { + + public String[] solution(String[] s) { + String[] answer = new String[s.length]; + + for (int i = 0; i < s.length; i++) { + int count = 0; + int idx = 0; + StringBuilder sb = new StringBuilder(); + + while (idx < s[i].length()) { + // 110 찾기 + if (s[i].charAt(idx) == '0' && sb.length() >= 2 && + sb.substring(sb.length() - 2).equals("11")) { + sb.setLength(sb.length() - 2); + count += 1; + } else { + sb.append(s[i].charAt(idx)); + } + idx++; + } + + idx = sb.indexOf("111"); // 111의 인덱스 찾기, sb에는 110이 없다 + + if (idx == -1) { + // 111이 없을 경우 마지막 0 뒤에 110을 count번만큼 넣기 + idx = sb.lastIndexOf("0"); + sb.insert(idx + 1, repeatString("110", count)); + } else { + // 111이 있을 경우 앞에 110을 count번만큼 넣기 + sb.insert(idx, repeatString("110", count)); + } + + answer[i] = sb.toString(); + } + + return answer; + } + + private static String repeatString(String str, int times) { + return new String(new char[times]).replace("\0", str); + } +} From 75228c4f3e21b84880a6d6148506605f19217272 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 10 Oct 2023 17:47:36 +0900 Subject: [PATCH 792/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EC=84=AC?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\262\260\355\225\230\352\270\260.java" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "2023/10.13/\354\241\260\354\210\230\354\227\260/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" diff --git "a/2023/10.13/\354\241\260\354\210\230\354\227\260/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" "b/2023/10.13/\354\241\260\354\210\230\354\227\260/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" new file mode 100644 index 0000000..09098ce --- /dev/null +++ "b/2023/10.13/\354\241\260\354\210\230\354\227\260/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" @@ -0,0 +1,66 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + int n = 4; + int[][] costs = {{0, 1, 1}, {0, 2, 2}, {1, 2, 5}, {1, 3, 1}, {2, 3, 8}}; + new Solution().solution(n, costs); + } +} + +class Solution { + class Node implements Comparable { + int index; + int cost; + + public Node(int index, int cost) { + this.index = index; + this.cost = cost; + } + + @Override + public int compareTo(Node o) { + return this.cost - o.cost; + } + } + + public int solution(int n, int[][] costs) { + int answer = 0; + boolean[] visited = new boolean[n]; + ArrayList> graph = new ArrayList<>(); + + graph = new ArrayList<>(); + + for (int i = 0; i < n; i++) { + graph.add(new ArrayList<>()); + } + + for (int i = 0; i < costs.length; i++) { + int s = costs[i][0]; + int e = costs[i][1]; + int c = costs[i][2]; + + graph.get(s).add(new Node(e, c)); + graph.get(e).add(new Node(s, c)); + } + + PriorityQueue pq = new PriorityQueue<>(); + + pq.add(new Node(0, 0)); + + while (!pq.isEmpty()) { + Node now = pq.poll(); + + if (visited[now.index]) continue; + + visited[now.index] = true; + answer += now.cost; + + for (Node next : graph.get(now.index)) { + if (!visited[next.index]) pq.add(next); + } + } + + return answer; + } +} \ No newline at end of file From 0afdcfcaad311a6a56f5ef591ebc8b4774964ea9 Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 11 Oct 2023 10:37:44 +0900 Subject: [PATCH 793/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A8=BC=20=EB=85=B8=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\250\274_\353\205\270\353\223\234.java" | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 "2023/10.13/\354\241\260\354\210\230\354\227\260/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" diff --git "a/2023/10.13/\354\241\260\354\210\230\354\227\260/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" "b/2023/10.13/\354\241\260\354\210\230\354\227\260/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" new file mode 100644 index 0000000..9601e70 --- /dev/null +++ "b/2023/10.13/\354\241\260\354\210\230\354\227\260/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" @@ -0,0 +1,76 @@ +import java.util.*; + +class Test { + public static void main(String[] args) { + int n = 6; + int[][] edge = {{3, 6}, {4, 3}, {3, 2}, {1, 3}, {1, 2}, {2, 4}, {5, 2}}; + new Solution().solution(n, edge); + } +} + +class Solution { + class Node implements Comparable { + int idx; + int cost; + + public Node(int idx, int cost) { + this.idx = idx; + this.cost = cost; + } + + @Override + public int compareTo(Node o) { + return this.cost - o.cost; + } + } + + static final int INF = 20000; + + public int solution(int n, int[][] edge) { + int answer = 0; + int maxDepth = 0; + List> graph = new ArrayList<>(); + int[] dist = new int[n + 1]; + boolean[] visited = new boolean[n + 1]; + + Arrays.fill(dist, INF); + dist[1] = 0; + + for (int i = 0; i <= n; i++) { + graph.add(new ArrayList<>()); + } + + for (int i = 0; i < edge.length; i++) { + int s = edge[i][0]; + int e = edge[i][1]; + + graph.get(s).add(e); + graph.get(e).add(s); + } + + PriorityQueue pq = new PriorityQueue<>(); + + pq.add(new Node(1, 0)); + + while (!pq.isEmpty()) { + Node now = pq.poll(); + + if (visited[now.idx]) continue; + visited[now.idx] = true; + + for (int next : graph.get(now.idx)) { + if (dist[next] > now.cost + 1) { + dist[next] = now.cost + 1; + maxDepth = Math.max(maxDepth, dist[next]); + pq.add(new Node(next, dist[next])); + } + } + } + + for (int i = 1; i < dist.length; i++) { + if (dist[i] == maxDepth) answer++; + } + + return answer; + } +} \ No newline at end of file From fdfea263146a8aa5e1ee747fd8134bf080eae796 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 13 Oct 2023 14:33:11 +0900 Subject: [PATCH 794/822] 1013 kihun --- ...353\250\274_\353\205\270\353\223\234.java" | 64 +++++++++++++ ...\352\262\260\355\225\230\352\270\260.java" | 91 +++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 "2023/10.13/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" create mode 100644 "2023/10.13/\354\206\241\352\270\260\355\233\210/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" diff --git "a/2023/10.13/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" "b/2023/10.13/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" new file mode 100644 index 0000000..7887ae3 --- /dev/null +++ "b/2023/10.13/\354\206\241\352\270\260\355\233\210/\352\260\200\354\236\245_\353\250\274_\353\205\270\353\223\234.java" @@ -0,0 +1,64 @@ +package programmers.lv3; + +import java.util.ArrayList; +import java.util.Arrays; + +//class Test { +// +// public static void main(String[] args) { +// int n = 6; +// int[][] edge = {{3, 6}, {4, 3}, {3, 2}, {1, 3}, {1, 2}, {2, 4}, {5, 2}}; +// System.out.println(new 가장_먼_노드().solution(n, edge)); +// } +// +//} + +public class 가장_먼_노드 { + + int[] distance; + ArrayList> nodeList; + + public int solution(int n, int[][] edge) { + int answer = 0; + distance = new int[n + 1]; + Arrays.fill(distance, Integer.MAX_VALUE); + nodeList = new ArrayList<>(); + for (int i = 0; i < n + 1; i++) { + nodeList.add(new ArrayList()); + } + + for (int[] e : edge) { + nodeList.get(e[0]).add(e[1]); + nodeList.get(e[1]).add(e[0]); + } + + distance[1] = 1; + dfs(1, 1); + + int maxDepth = 1; + for (int i = 2; i < n + 1; i++) { + if (distance[i] > maxDepth) { + maxDepth = distance[i]; + answer = 1; + } else if (distance[i] == maxDepth) { + answer += 1; + } + } + + return answer; + } + + public void dfs(int node, int depth) { + + ArrayList nodes = nodeList.get(node); + + for (int n : nodes) { + if (distance[n] > depth + 1) { + distance[n] = Math.min(distance[n], depth + 1); + dfs(n, depth + 1); + } + } + + } + +} diff --git "a/2023/10.13/\354\206\241\352\270\260\355\233\210/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" "b/2023/10.13/\354\206\241\352\270\260\355\233\210/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" new file mode 100644 index 0000000..d69936b --- /dev/null +++ "b/2023/10.13/\354\206\241\352\270\260\355\233\210/\354\204\254_\354\227\260\352\262\260\355\225\230\352\270\260.java" @@ -0,0 +1,91 @@ +package programmers.lv3; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.PriorityQueue; + +//class Test { +// public static void main(String[] args) { +// int n = 4; +// int[][] costs = {{0, 1, 1}, {0, 2, 2}, {1, 2, 5}, {1, 3, 1}, {2, 3, 8}}; +// +// new 섬_연결하기().solution(n, costs); +// } +//} + +public class 섬_연결하기 { + + class Node implements Comparable { + int end, distance; + + public Node(int end, int distance) { + this.end = end; + this.distance = distance; + } + + @Override + public int compareTo(Node o) { + return this.distance - o.distance; + } + } + + int N; + ArrayList> nodes; + + public int solution(int n, int[][] costs) { + int answer = Integer.MAX_VALUE; + N = n; + nodes = new ArrayList<>(); + for (int i = 0; i < n; i++) { + nodes.add(new ArrayList<>()); + } + + for (int[] c : costs) { + nodes.get(c[0]).add(new Node(c[1], c[2])); + nodes.get(c[1]).add(new Node(c[0], c[2])); + } + + for (int i = 0; i < n; i++) { + int[] distance = dijkstra(i); + + int temp = 0; + for (int d : distance) { + if (d != Integer.MAX_VALUE) { + temp += d; + } + } + + answer = Math.min(answer, temp); + } + + return answer; + } + + public int[] dijkstra(int index) { + int[] distances = new int[N]; + boolean[] visited = new boolean[N]; + Arrays.fill(distances, Integer.MAX_VALUE); + + PriorityQueue pq = new PriorityQueue<>(); + pq.add(new Node(index, 0)); + + distances[index] = 0; + visited[index] = true; + + while (!pq.isEmpty()) { + Node now = pq.poll(); + visited[now.end] = true; + + ArrayList nodeList = nodes.get(now.end); + + for (Node node : nodeList) { + if (!visited[node.end] && distances[node.end] > node.distance) { + distances[node.end] = node.distance; + pq.add(new Node(node.end, distances[node.end])); + } + } + } + + return distances; + } +} From 4eec9345a9dccc9444ac525703de9873382b13e8 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 13 Oct 2023 14:34:43 +0900 Subject: [PATCH 795/822] Create README.md --- 2023/10.13/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/10.13/README.md diff --git a/2023/10.13/README.md b/2023/10.13/README.md new file mode 100644 index 0000000..8543c07 --- /dev/null +++ b/2023/10.13/README.md @@ -0,0 +1,5 @@ +# 10.13(금) 스터디 + +- 프로그래머스 + - [섬 연결하기](https://school.programmers.co.kr/learn/courses/30/lessons/42861) + - [가장 먼 노드](https://school.programmers.co.kr/learn/courses/30/lessons/49189) From 86b5a8609d3beead0c8862451432090762e63e33 Mon Sep 17 00:00:00 2001 From: su6378 Date: Mon, 16 Oct 2023 11:25:09 +0900 Subject: [PATCH 796/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20:=20=EB=AF=BC?= =?UTF-8?q?=EC=A4=80=EC=9D=B4=EC=99=80=20=EB=A7=88=EC=82=B0=20=EA=B7=B8?= =?UTF-8?q?=EB=A6=AC=EA=B3=A0=20=EA=B1=B4=EC=9A=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\263\240 \352\261\264\354\232\260.java" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "2023/10.19/\354\241\260\354\210\230\354\227\260/\353\257\274\354\244\200\354\235\264\354\231\200 \353\247\210\354\202\260 \352\267\270\353\246\254\352\263\240 \352\261\264\354\232\260.java" diff --git "a/2023/10.19/\354\241\260\354\210\230\354\227\260/\353\257\274\354\244\200\354\235\264\354\231\200 \353\247\210\354\202\260 \352\267\270\353\246\254\352\263\240 \352\261\264\354\232\260.java" "b/2023/10.19/\354\241\260\354\210\230\354\227\260/\353\257\274\354\244\200\354\235\264\354\231\200 \353\247\210\354\202\260 \352\267\270\353\246\254\352\263\240 \352\261\264\354\232\260.java" new file mode 100644 index 0000000..829a42b --- /dev/null +++ "b/2023/10.19/\354\241\260\354\210\230\354\227\260/\353\257\274\354\244\200\354\235\264\354\231\200 \353\247\210\354\202\260 \352\267\270\353\246\254\352\263\240 \352\261\264\354\232\260.java" @@ -0,0 +1,88 @@ +import java.io.*; +import java.util.*; + +public class Main { + static class Road implements Comparable { + int node; + int cost; + List route; + + public Road(int node, int cost) { + this.node = node; + this.cost = cost; + } + + public Road(int node, int cost, List route) { + this.node = node; + this.cost = cost; + this.route = route; + } + + @Override + public int compareTo(Road o) { + return this.cost - o.cost; + } + } + + static final int INF = 1000000000; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + int v = Integer.parseInt(st.nextToken()); + int e = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] dist = new int[v + 1]; + List> graph = new ArrayList<>(); + + Arrays.fill(dist, INF); + dist[1] = 0; + + for (int i = 0; i <= v; i++) { + graph.add(new ArrayList<>()); + } + + for (int i = 0; i < e; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + graph.get(a).add(new Road(b, c)); + graph.get(b).add(new Road(a, c)); + } + + boolean isFind = false; + PriorityQueue pq = new PriorityQueue<>(); + List initRoute = new ArrayList<>(); + initRoute.add(1); + + pq.add(new Road(1, 0, initRoute)); + + while (!pq.isEmpty()) { + Road now = pq.poll(); + + if (now.node == v) { + if (now.route.contains(p)) isFind = true; + } + + for (Road next : graph.get(now.node)) { + if (dist[next.node] >= now.cost + next.cost) { + List nextRoute = new ArrayList<>(); + nextRoute.addAll(now.route); + nextRoute.add(next.node); + dist[next.node] = now.cost + next.cost; + pq.add(new Road(next.node, dist[next.node], nextRoute)); + } + } + } + + if (isFind) bw.write("SAVE HIM"); + else bw.write("GOOD BYE"); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From 1a9330ec26cab0a22a7d84a3b79d489f9908fd0f Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 20 Oct 2023 16:20:23 +0900 Subject: [PATCH 797/822] [SOLVE] @sindorim5 1019 --- 2023/10.19/README.md | 5 + ...352\263\240_\352\261\264\354\232\260.java" | 80 +++++++++ ...53\217\214\353\246\254\352\270\260_3.java" | 164 ++++++++++++++++++ 3 files changed, 249 insertions(+) create mode 100644 2023/10.19/README.md create mode 100644 "2023/10.19/\354\206\241\352\270\260\355\233\210/\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" create mode 100644 "2023/10.19/\354\206\241\352\270\260\355\233\210/\353\260\260\354\227\264_\353\217\214\353\246\254\352\270\260_3.java" diff --git a/2023/10.19/README.md b/2023/10.19/README.md new file mode 100644 index 0000000..a4c086a --- /dev/null +++ b/2023/10.19/README.md @@ -0,0 +1,5 @@ +# 10.19(목) 스터디 + +- 백준 + - [민준이와 마산 그리고 건우](https://www.acmicpc.net/problem/18223) + - [배열 돌리기 3](https://www.acmicpc.net/problem/16935) diff --git "a/2023/10.19/\354\206\241\352\270\260\355\233\210/\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" "b/2023/10.19/\354\206\241\352\270\260\355\233\210/\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" new file mode 100644 index 0000000..fe5608f --- /dev/null +++ "b/2023/10.19/\354\206\241\352\270\260\355\233\210/\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" @@ -0,0 +1,80 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 민준이와_마산_그리고_건우 { + + static class Node implements Comparable { + int end, d; + + public Node(int end, int d) { + this.end = end; + this.d = d; + } + + @Override + public int compareTo(Node node) { + return this.d - node.d; + } + } + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int V, E, P; + static ArrayList> nodeList; + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + V = Integer.parseInt(st.nextToken()); + E = Integer.parseInt(st.nextToken()); + P = Integer.parseInt(st.nextToken()); + + nodeList = new ArrayList<>(); + for (int i = 0; i <= V; i++) { + nodeList.add(new ArrayList<>()); + } + + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int d = Integer.parseInt(st.nextToken()); + nodeList.get(a).add(new Node(b, d)); + nodeList.get(b).add(new Node(a, d)); + } + + int[] distanceA = dijkstra(1); + int[] distanceB = dijkstra(P); + + if (distanceA[V] == distanceA[P] + distanceB[V]) { + System.out.println("SAVE HIM"); + } else { + System.out.println("GOOD BYE"); + } + + } + + static int[] dijkstra(int index) { + int[] distances = new int[V+1]; + Arrays.fill(distances, Integer.MAX_VALUE); + distances[index] = 0; + + PriorityQueue pq = new PriorityQueue<>(); + pq.offer(new Node(index, 0)); + + while (!pq.isEmpty()) { + Node now = pq.poll(); + ArrayList nodes = nodeList.get(now.end); + + for (Node node : nodes) { + if (distances[node.end] > node.d + distances[now.end]) { + distances[node.end] = node.d + distances[now.end]; + pq.offer(new Node(node.end, distances[node.end])); + } + } + } + + return distances; + } +} diff --git "a/2023/10.19/\354\206\241\352\270\260\355\233\210/\353\260\260\354\227\264_\353\217\214\353\246\254\352\270\260_3.java" "b/2023/10.19/\354\206\241\352\270\260\355\233\210/\353\260\260\354\227\264_\353\217\214\353\246\254\352\270\260_3.java" new file mode 100644 index 0000000..e38c2ca --- /dev/null +++ "b/2023/10.19/\354\206\241\352\270\260\355\233\210/\353\260\260\354\227\264_\353\217\214\353\246\254\352\270\260_3.java" @@ -0,0 +1,164 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class 배열_돌리기_3 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M, R; + static int[][] matrix; + + public static void main(String[] args) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + R = Integer.parseInt(st.nextToken()); + + matrix = new int[N][M]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + matrix[i][j] = Integer.parseInt(st.nextToken()); + } + } + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < R; i++) { + int action = Integer.parseInt(st.nextToken()); + transform(action); + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + sb.append(matrix[i][j]); + if (j != M - 1) { + sb.append(" "); + } + } + if (i != N - 1) { + sb.append("\n"); + } + } + System.out.println(sb); + + } + + static void transform(int action) { + int[][] temp; + if (action == 1) { + temp = new int[N][M]; + + for (int i = N - 1; i >= 0; i--) { + temp[N - 1 - i] = matrix[i]; + } + } else if (action == 2) { + temp = new int[N][M]; + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + temp[i][j] = matrix[i][M - 1 - j]; + } + } + } else if (action == 3) { + temp = new int[M][N]; + + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + temp[i][j] = matrix[N - 1 - j][i]; + } + } + + int swap = N; + N = M; + M = swap; + } else if (action == 4) { + temp = new int[M][N]; + + for (int i = 0; i < M; i++) { + for (int j = 0; j < N; j++) { + temp[i][j] = matrix[j][M - 1 - i]; + } + } + int swap = N; + N = M; + M = swap; + } else if (action == 5) { + temp = new int[N][M]; + + int halfN = N / 2; + int halfM = M / 2; + + // 4사분면 + for (int i = 0; i < halfN; i++) { + for (int j = 0; j < halfM; j++) { + temp[i][j] = matrix[i + halfN][j]; + } + } + + // 1사분면 + for (int i = 0; i < halfN; i++) { + for (int j = halfM; j < M; j++) { + temp[i][j] = matrix[i][j - halfM]; + } + } + + // 2사분면 + for (int i = halfN; i < N; i++) { + for (int j = halfM; j < M; j++) { + temp[i][j] = matrix[i - halfN][j]; + } + } + + // 3사분면 + for (int i = halfN; i < N; i++) { + for (int j = 0; j < halfM; j++) { + temp[i][j] = matrix[i][j + halfM]; + } + } + } else { + temp = new int[N][M]; + + int halfN = N / 2; + int halfM = M / 2; + + // 4사분면 + for (int i = 0; i < halfN; i++) { + for (int j = 0; j < halfM; j++) { + temp[i][j] = matrix[i][j + halfM]; + } + } + + // 1사분면 + for (int i = 0; i < halfN; i++) { + for (int j = halfM; j < M; j++) { + temp[i][j] = matrix[i + halfN][j]; + } + } + + // 2사분면 + for (int i = halfN; i < N; i++) { + for (int j = halfM; j < M; j++) { + temp[i][j] = matrix[i][j - halfM]; + } + } + + // 3사분면 + for (int i = halfN; i < N; i++) { + for (int j = 0; j < halfM; j++) { + temp[i][j] = matrix[i - halfN][j]; + } + } + + } + + matrix = temp; + + } + +} From 0743b28f0c4e2e5d623b25036cd79daf071aa0b3 Mon Sep 17 00:00:00 2001 From: chang0-0 Date: Sat, 21 Oct 2023 15:42:46 +0900 Subject: [PATCH 798/822] =?UTF-8?q?=EC=B0=BD=EC=98=81=20BOJ=2018223=20Solv?= =?UTF-8?q?e=20with=20Java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\263\240_\352\261\264\354\232\260.java" | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 "2023/10.19/\354\265\234\354\260\275\354\230\201/BOJ_18223_\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" diff --git "a/2023/10.19/\354\265\234\354\260\275\354\230\201/BOJ_18223_\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" "b/2023/10.19/\354\265\234\354\260\275\354\230\201/BOJ_18223_\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" new file mode 100644 index 0000000..eb4fb3c --- /dev/null +++ "b/2023/10.19/\354\265\234\354\260\275\354\230\201/BOJ_18223_\353\257\274\354\244\200\354\235\264\354\231\200_\353\247\210\354\202\260_\352\267\270\353\246\254\352\263\240_\352\261\264\354\232\260.java" @@ -0,0 +1,126 @@ +package BOJ_18223; + +import java.io.*; +import java.util.*; + +public class BOJ_18223_민준이와_마산_그리고_건우 { + + /* + 1번에서 마지막 노드까지 + 민준이가 건우를 도와주는 경로의 길이가 최단 경로의 길이보다 길어지지 않는다면, + 민준이는 반드시 건우를 도와주러 간다. + */ + + // https://www.acmicpc.net/problem/18223 + // input + private static BufferedReader br; + + // variables + private static final int INF = Integer.MAX_VALUE / 4; + private static final String saveHim = "SAVE HIM"; + private static final String goodBye = "GOOD BYE"; + + private static int V, E, P, startToV, pToV, startToP; + private static List> adjList; + private static int[] dists; + + private static class Node implements Comparable { + int num; + int weight; + + private Node(int num, int weight) { + this.num = num; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return weight - o.weight; + } + + @Override + public String toString() { + return "{ num : " + num + " weight : " + weight + " }"; + } + } // End of Node class + + public static void main(String[] args) throws IOException { + System.setIn(new FileInputStream("C:\\Users\\bigyo\\Desktop\\알고리즘\\JavaAlgorithm\\src\\BOJ_18223\\res.txt")); + br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + input(); + + bw.write(solve()); + bw.close(); + } // End of main() + + private static String solve() { + StringBuilder sb = new StringBuilder(); + + // 최단 거리의 경로를 먼저 구해보기. + dijkstra(1, V); + startToV = dists[V]; + startToP = dists[P]; + + dijkstra(P, V); + pToV = dists[V]; + + if (startToP + pToV == startToV) { + sb.append(saveHim); + } else { + sb.append(goodBye); + } + return sb.toString(); + } // End of solve() + + private static int dijkstra(int start, int target) { + PriorityQueue pQ = new PriorityQueue<>(); + pQ.offer(new Node(start, 0)); + dists = new int[V + 1]; + Arrays.fill(dists, INF); + dists[start] = 0; + + while (!pQ.isEmpty()) { + Node nowNode = pQ.poll(); + + for (Node nextNode : adjList.get(nowNode.num)) { + if (dists[nextNode.num] > dists[nowNode.num] + nextNode.weight) { + dists[nextNode.num] = dists[nowNode.num] + nextNode.weight; + pQ.offer(new Node(nextNode.num, dists[nextNode.num])); + } + } + } + + /* + 1 부터 모든 노드까지의 최단 거리를 구하고, + 1에서 P까지의 거리와 P에서 V까지의 거리의 합이 + 1에서 V까지의 거리 합과 같은지를 파악하기 + 거리를 넘는경우에는, 불가 + */ + + return dists[target]; + } // End of dijkstra + + private static void input() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + V = Integer.parseInt(st.nextToken()); + E = Integer.parseInt(st.nextToken()); + P = Integer.parseInt(st.nextToken()); + + adjList = new ArrayList<>(); + for (int i = 0; i <= V; i++) { + adjList.add(new ArrayList<>()); + } + + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + adjList.get(a).add(new Node(b, c)); + adjList.get(b).add(new Node(a, c)); + } + } // End of input() +} // End of Main class From 43f1794a782adb57dd88ca42c7aa74c743df8085 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 27 Oct 2023 20:49:02 +0900 Subject: [PATCH 799/822] Create README.md --- 2023/10.28/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/10.28/README.md diff --git a/2023/10.28/README.md b/2023/10.28/README.md new file mode 100644 index 0000000..5d357e2 --- /dev/null +++ b/2023/10.28/README.md @@ -0,0 +1,5 @@ +# 10.28(토) 스터디 + +- 백준 + - [동전 바꿔주기](https://www.acmicpc.net/problem/2624) + - [주간 달력](https://www.acmicpc.net/problem/22936) From 720165b14909f9a4dfd06af246547cfe38476f3a Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 27 Oct 2023 20:49:27 +0900 Subject: [PATCH 800/822] [SOLVE] @sindorim5 1028 --- ...\352\277\224\354\243\274\352\270\260.java" | 46 +++++++++++ ...352\260\204_\353\213\254\353\240\245.java" | 77 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 "2023/10.28/\354\206\241\352\270\260\355\233\210/\353\217\231\354\240\204_\353\260\224\352\277\224\354\243\274\352\270\260.java" create mode 100644 "2023/10.28/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204_\353\213\254\353\240\245.java" diff --git "a/2023/10.28/\354\206\241\352\270\260\355\233\210/\353\217\231\354\240\204_\353\260\224\352\277\224\354\243\274\352\270\260.java" "b/2023/10.28/\354\206\241\352\270\260\355\233\210/\353\217\231\354\240\204_\353\260\224\352\277\224\354\243\274\352\270\260.java" new file mode 100644 index 0000000..53da41f --- /dev/null +++ "b/2023/10.28/\354\206\241\352\270\260\355\233\210/\353\217\231\354\240\204_\353\260\224\352\277\224\354\243\274\352\270\260.java" @@ -0,0 +1,46 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 동전_바꿔주기 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int T, K; + static int[][] coins, dp; + + public static void main(String[] args) throws IOException { + T = Integer.parseInt(br.readLine()); + K = Integer.parseInt(br.readLine()); + coins = new int[K+1][2]; // i번째 j개 + dp = new int[K+1][T+1]; + + for (int i = 1; i <= K; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + coins[i][0] = Integer.parseInt(st.nextToken()); + coins[i][1] = Integer.parseInt(st.nextToken()); + } + + dp[0][0] = 1; + + for (int k = 1; k <= K; k++) { + int coin = coins[k][0]; + int count = coins[k][1]; + + for (int i = 0; i <= T; i++) { + for (int c = 0; c <= count; c++) { + if (i - coin * c >= 0 && i - coin * c <= T) { + dp[k][i] += dp[k - 1][i - coin * c]; + } + } + } + } + + System.out.println(dp[K][T]); + + } + +} diff --git "a/2023/10.28/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204_\353\213\254\353\240\245.java" "b/2023/10.28/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204_\353\213\254\353\240\245.java" new file mode 100644 index 0000000..1ab95d2 --- /dev/null +++ "b/2023/10.28/\354\206\241\352\270\260\355\233\210/\354\243\274\352\260\204_\353\213\254\353\240\245.java" @@ -0,0 +1,77 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.StringTokenizer; + +// https://vapor3965.tistory.com/78 + +public class 주간_달력 { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int N, M, T; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + T = N * 7; + + int[] times = new int[50001 + (N*7)]; + int[] prefix = new int[50001 + (N*7)]; + + for (int i = 0; i < M; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + times[start] += 1; + times[end + 1] -= 1; + prefix[end + 1] += 1; + } + + for (int i = 1; i <= 50000; i++) { + times[i] = times[i - 1] + times[i]; + } + for (int i = 1; i <= 50000; i++) { + times[i] = times[i - 1] + times[i]; + } + + ArrayList schedules = new ArrayList<>(); + for (int i = 1; i <= 50000; i++) { + schedules.add(new int[]{i, times[i + (N * 7) - 1] - times[i - 1]}); + } + + schedules.sort(new Comparator() { + @Override + public int compare(int[] t0, int[] t1) { + if (t0[1] == t1[1]) { + return t0[0] - t1[0]; + } else { + return t1[1] - t0[1]; + } + } + // 뒤의 내림차순 + // 뒤가 같으면 앞은 오름차순 + }); + + for (int[] d : schedules) { + System.out.println(Arrays.toString(d)); + } + + int date = schedules.get(0)[0]; + + int answer = 0; + for (int i = 0; i < N; i++) { + int start = (i * 7) + date; + for (int j = start + 1; j < start + 7; j++) { + answer += prefix[j]; + } + answer += times[start + 6] - times[start + 5]; + } + System.out.println(answer); + } + +} From 4e3327d9c8bd762d2e2b7c8e17f5f88e19716d48 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 1 Nov 2023 21:24:12 +0900 Subject: [PATCH 801/822] Create README.md --- 2023/11.02/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 2023/11.02/README.md diff --git a/2023/11.02/README.md b/2023/11.02/README.md new file mode 100644 index 0000000..722089a --- /dev/null +++ b/2023/11.02/README.md @@ -0,0 +1,6 @@ +# 11.02(목) 스터디 + +- 백준 + - [인증된 쉬운 게임](https://www.acmicpc.net/problem/22846) + - [서로 다른 소수의 합](https://www.acmicpc.net/problem/3908) + - [모두싸인 출근길](https://www.acmicpc.net/problem/24229) From 04f997e98c771d95094d9fa9456700dc76c57a49 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Wed, 1 Nov 2023 21:24:36 +0900 Subject: [PATCH 802/822] [SOLVE] @sindorim5 1102 --- ...\354\266\234\352\267\274\352\270\270.java" | 77 +++++++++++++++++++ ...354\210\230\354\235\230_\355\225\251.java" | 62 +++++++++++++++ ...354\232\264_\352\262\214\354\236\204.java" | 66 ++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 "2023/11.02/\354\206\241\352\270\260\355\233\210/\353\252\250\353\221\220\354\213\270\354\235\270_\354\266\234\352\267\274\352\270\270.java" create mode 100644 "2023/11.02/\354\206\241\352\270\260\355\233\210/\354\204\234\353\241\234_\353\213\244\353\245\270_\354\206\214\354\210\230\354\235\230_\355\225\251.java" create mode 100644 "2023/11.02/\354\206\241\352\270\260\355\233\210/\354\235\270\354\246\235\353\220\234_\354\211\254\354\232\264_\352\262\214\354\236\204.java" diff --git "a/2023/11.02/\354\206\241\352\270\260\355\233\210/\353\252\250\353\221\220\354\213\270\354\235\270_\354\266\234\352\267\274\352\270\270.java" "b/2023/11.02/\354\206\241\352\270\260\355\233\210/\353\252\250\353\221\220\354\213\270\354\235\270_\354\266\234\352\267\274\352\270\270.java" new file mode 100644 index 0000000..25ee1da --- /dev/null +++ "b/2023/11.02/\354\206\241\352\270\260\355\233\210/\353\252\250\353\221\220\354\213\270\354\235\270_\354\266\234\352\267\274\352\270\270.java" @@ -0,0 +1,77 @@ +package baekjoon.gold.four; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 모두싸인_출근길 { + + static class Node implements Comparable { + + int start, end; + + public Node(int start, int end) { + this.start = start; + this.end = end; + } + + @Override + public int compareTo(Node o) { + if (this.start != o.start) { + return this.start - o.start; + } else { + return this.end - o.end; + } + } + + @Override + public String toString() { + return String.format("(%d, %d)", this.start, this.end); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + ArrayList nodeList = new ArrayList<>(); + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + nodeList.add(new Node( + Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()) + )); + } + + Collections.sort(nodeList); + + // 노드를 정리 + ArrayList jump = new ArrayList<>(); + int start = nodeList.get(0).start; + int end = nodeList.get(0).end; + for (int i = 1; i < N; i++) { + if (end >= nodeList.get(i).start) { + end = Math.max(end, nodeList.get(i).end); + } else { + jump.add(new Node(start, end)); + start = nodeList.get(i).start; + end = nodeList.get(i).end; + } + } + jump.add(new Node(start, end)); + + int range = 0; + int index = 0; + for (int i = 0; i < jump.size(); i++) { + if (range >= jump.get(i).start) { + index = i; + range = Math.max(range, jump.get(i).end + jump.get(i).end - jump.get(i).start); + } + } + + System.out.println(jump.get(index).end); + + } + +} diff --git "a/2023/11.02/\354\206\241\352\270\260\355\233\210/\354\204\234\353\241\234_\353\213\244\353\245\270_\354\206\214\354\210\230\354\235\230_\355\225\251.java" "b/2023/11.02/\354\206\241\352\270\260\355\233\210/\354\204\234\353\241\234_\353\213\244\353\245\270_\354\206\214\354\210\230\354\235\230_\355\225\251.java" new file mode 100644 index 0000000..e880c8a --- /dev/null +++ "b/2023/11.02/\354\206\241\352\270\260\355\233\210/\354\204\234\353\241\234_\353\213\244\353\245\270_\354\206\214\354\210\230\354\235\230_\355\225\251.java" @@ -0,0 +1,62 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 서로_다른_소수의_합 { + + static int MAX = 1120; + static boolean[] isPrime = new boolean[MAX + 1]; + static ArrayList primeNumbers = new ArrayList<>(); + static int[][] dp = new int[MAX + 1][15]; + + public static void main(String[] args) throws IOException { + getPrimeNumbers(); + dp[0][0] = 1; + for (int num : primeNumbers) { + for (int j = MAX; j >= num; j--) { + for (int k = 1; k < 15; k++) { + dp[j][k] += dp[j - num][k - 1]; + } + } + } + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + for (int i = 0; i < T; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + System.out.println(dp[n][k]); + } + + } + + public static void getPrimeNumbers() { + Arrays.fill(isPrime, true); + + isPrime[0] = false; + isPrime[1] = false; + + int sqrtMax = (int) Math.sqrt(MAX); + for (int i = 2; i <= sqrtMax; i++) { + if (isPrime[i]) { + for (int j = i * i; j <= MAX; j += i) { + isPrime[j] = false; + } + } + } + + for (int i = 0; i <= MAX; i++) { + if (isPrime[i]) { + primeNumbers.add(i); + } + } + + } + +} diff --git "a/2023/11.02/\354\206\241\352\270\260\355\233\210/\354\235\270\354\246\235\353\220\234_\354\211\254\354\232\264_\352\262\214\354\236\204.java" "b/2023/11.02/\354\206\241\352\270\260\355\233\210/\354\235\270\354\246\235\353\220\234_\354\211\254\354\232\264_\352\262\214\354\236\204.java" new file mode 100644 index 0000000..3f6f46a --- /dev/null +++ "b/2023/11.02/\354\206\241\352\270\260\355\233\210/\354\235\270\354\246\235\353\220\234_\354\211\254\354\232\264_\352\262\214\354\236\204.java" @@ -0,0 +1,66 @@ +package baekjoon.gold.three; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class 인증된_쉬운_게임 { + // K를 만드는 사람이 이긴다 + // dp[i] = i로 시작했을 때 이길 수 있는가? + // https://velog.io/@qwerty1434/%EB%B0%B1%EC%A4%80-22846%EB%B2%88-%EC%9D%B8%EC%A6%9D%EB%90%9C-%EC%89%AC%EC%9A%B4-%EA%B2%8C%EC%9E%84 + // https://steadily-worked.tistory.com/662 + // https://kwoncorin.tistory.com/115 + + static int[] dp; + static int K; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + K = Integer.parseInt(br.readLine()); + dp = new int[K+1]; + + playGame(1); + + if (dp[1] == 1) { + System.out.println("Kali"); + } else { + System.out.println("Ringo"); + } + + System.out.println(Arrays.toString(dp)); + + } + + static int playGame(int start) { + if (start >= K) { + return -1; + } + if (dp[start] != 0) { + return dp[start]; + } + + ArrayList divisors = findDiv(start); + for (int i = 0; i < divisors.size(); i++) { + if (start + divisors.get(i) <= K && playGame(start + divisors.get(i)) == -1) { + dp[start] = 1; + return dp[start]; + } + } + dp[start] = -1; + return dp[start]; + } + + static ArrayList findDiv(int number) { + ArrayList divisors = new ArrayList<>(); + for (int i = 1; i * i <= number; i++) { + if (number % i == 0) { + divisors.add(i); + if (i * i != number) { + divisors.add(number / i); + } + } + } + return divisors; + } + +} From e0b9574ce1101a9fec012f292d89b4ec655f2d0e Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:05:09 +0900 Subject: [PATCH 803/822] =?UTF-8?q?Create=20=EC=9D=B8=EC=A6=9D=EB=90=9C?= =?UTF-8?q?=EC=89=AC=EC=9A=B4=EA=B2=8C=EC=9E=84.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이걸어떻게떠올리죠 --- ...\354\232\264\352\262\214\354\236\204.java" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "2023/11.02/\354\240\225\355\230\270\354\241\260/\354\235\270\354\246\235\353\220\234\354\211\254\354\232\264\352\262\214\354\236\204.java" diff --git "a/2023/11.02/\354\240\225\355\230\270\354\241\260/\354\235\270\354\246\235\353\220\234\354\211\254\354\232\264\352\262\214\354\236\204.java" "b/2023/11.02/\354\240\225\355\230\270\354\241\260/\354\235\270\354\246\235\353\220\234\354\211\254\354\232\264\352\262\214\354\236\204.java" new file mode 100644 index 0000000..0d3298f --- /dev/null +++ "b/2023/11.02/\354\240\225\355\230\270\354\241\260/\354\235\270\354\246\235\353\220\234\354\211\254\354\232\264\352\262\214\354\236\204.java" @@ -0,0 +1,56 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.List; + + +public class 인증된쉬운게임 { + // 자연수 K + public static int K; + // dp 배열 + // 모니터의 값이 x일때부터 게임을 시작할때 Kali가 이기면 True, 지면 False + public static boolean [] dp; + + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + K = Integer.parseInt(br.readLine()); + dp = new boolean[K+1]; + + for (int cur = K; cur >= 1; cur--) { + // 시간 절약을 위해 y*y<=x 인 범위만큼만 약수 확인 + for (int divisor = 1; divisor * divisor <= cur; divisor++) { + + if (cur % divisor == 0) { + // cur에 divisor를 더했을 때 범위를 벗어나지 않고 cur에 divisor를 더한 값이 false 일 때(링고가 지는 경우) true + // 범위를 벗어날 경우 자동적으로 지는 것이기 때문에 범위 벗어나면 안됨 + + // Kali의 다음 차례는 Ringo + // Kali가 이기는 최선의 전략은 Ringo가 지는 경우 + // 따라서 cur에 divisor를 더해 Ringo의 차례를 갔을 때 dp의 값이 False라면 dp[cur]=true + if (cur + divisor <= K && !dp[cur + divisor]) { + dp[cur]=true; + break; + } + // divisor*divisor<=cur인 경우만큼만 구했기에 cur/divisor도 추가적으로 구해줘야 함. + if (cur + cur / divisor <= K && !dp[cur + cur / divisor]) { + dp[cur]=true; + break; + } + } + + } + } + + // 초기 모니터의 숫자가 1이기 때문에 dp[1]의 값을 비교 + // Kali가 1부터 시작해서 이긴다면 (dp[1]=True)라면 Kali 출력 + if (dp[1]) { + bw.write("Kali"); + } else { + bw.write("Ringo"); + } + bw.flush(); + } +} From 3ef85245454c2e611d1efd60fd6c1a762316de43 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:10:59 +0900 Subject: [PATCH 804/822] =?UTF-8?q?Create=20=EC=84=9C=EB=A1=9C=EB=8B=A4?= =?UTF-8?q?=EB=A5=B8=EC=86=8C=EC=88=98=EC=9D=98=ED=95=A9.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\354\235\230\355\225\251.java" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "2023/11.02/\354\240\225\355\230\270\354\241\260/\354\204\234\353\241\234\353\213\244\353\245\270\354\206\214\354\210\230\354\235\230\355\225\251.java" diff --git "a/2023/11.02/\354\240\225\355\230\270\354\241\260/\354\204\234\353\241\234\353\213\244\353\245\270\354\206\214\354\210\230\354\235\230\355\225\251.java" "b/2023/11.02/\354\240\225\355\230\270\354\241\260/\354\204\234\353\241\234\353\213\244\353\245\270\354\206\214\354\210\230\354\235\230\355\225\251.java" new file mode 100644 index 0000000..78cfce2 --- /dev/null +++ "b/2023/11.02/\354\240\225\355\230\270\354\241\260/\354\204\234\353\241\234\353\213\244\353\245\270\354\206\214\354\210\230\354\235\230\355\225\251.java" @@ -0,0 +1,60 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +//에라토스테네스의 채 + dp 문제 +public class 서로다른소수의합 { + static int MAX = 1120; + static boolean[] isPrime; + static ArrayList primeList; + static int[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int tc = Integer.parseInt(br.readLine()); + isPrime = new boolean[MAX + 1]; + primeList = new ArrayList<>(); + dp = new int[MAX + 1][15]; + + getPrime(); + + for (int t = 0; t < tc; t++) { + st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + System.out.println(dp[n][k]); + } + } + + static void getPrime() { + Arrays.fill(isPrime, true); + isPrime[0] = false; + isPrime[1] = false; + + for (int i = 2; (i * i) <= MAX; i++) { + if (isPrime[i]) { + for (int j = i * i; j <= MAX; j += i) { + isPrime[j] = false; + } + } + } + + for (int i = 0; i < isPrime.length; i++) { + if (isPrime[i]) primeList.add(i); + } + + dp[0][0] = 1; + for (int prime : primeList) { + for (int j = MAX; j >= prime; j--) { + for (int k = 1; k < 15; k++) { + dp[j][k] += dp[j - prime][k - 1]; + } + } + } + } +} From f9fe651dc7603aa45fa9373304052749514a901f Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 24 Nov 2023 16:11:19 +0900 Subject: [PATCH 805/822] Create README.md --- 2023/11.25/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/11.25/README.md diff --git a/2023/11.25/README.md b/2023/11.25/README.md new file mode 100644 index 0000000..86137bd --- /dev/null +++ b/2023/11.25/README.md @@ -0,0 +1,5 @@ +# 11.25(토) 스터디 + +- 프로그래머스 + - [오픈채팅방](https://school.programmers.co.kr/learn/courses/30/lessons/42888) + - [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) \ No newline at end of file From 93b526a9f820092d2ee4154e95db07d241e45514 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Fri, 24 Nov 2023 16:11:42 +0900 Subject: [PATCH 806/822] [SOLVE] @sindorim5 1125 --- ...\354\235\270\355\225\230\352\270\260.java" | 96 +++++++++++++++++++ ...\354\261\204\355\214\205\353\260\251.java" | 62 ++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 "2023/11.25/\354\206\241\352\270\260\355\233\210/\352\261\260\353\246\254\353\221\220\352\270\260_\355\231\225\354\235\270\355\225\230\352\270\260.java" create mode 100644 "2023/11.25/\354\206\241\352\270\260\355\233\210/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" diff --git "a/2023/11.25/\354\206\241\352\270\260\355\233\210/\352\261\260\353\246\254\353\221\220\352\270\260_\355\231\225\354\235\270\355\225\230\352\270\260.java" "b/2023/11.25/\354\206\241\352\270\260\355\233\210/\352\261\260\353\246\254\353\221\220\352\270\260_\355\231\225\354\235\270\355\225\230\352\270\260.java" new file mode 100644 index 0000000..e7acda3 --- /dev/null +++ "b/2023/11.25/\354\206\241\352\270\260\355\233\210/\352\261\260\353\246\254\353\221\220\352\270\260_\355\231\225\354\235\270\355\225\230\352\270\260.java" @@ -0,0 +1,96 @@ +package programmers.lv2; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; + +class Test { + + public static void main(String[] args) { + String[][] places = { + {"POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"}, + {"POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"}, + {"PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"}, + {"OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"}, + {"PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"} + }; + int[] a = new 거리두기_확인하기().solution(places); + System.out.println(Arrays.toString(a)); + } + +} + +public class 거리두기_확인하기 { + static int[] dY = {1, 0, -1, 0}; + static int[] dX = {0, 1, 0, -1}; + + public int[] solution(String[][] places) { + int[] answer = new int[places.length]; + + for (int i = 0; i < places.length; i++) { + String[] place = places[i]; + + boolean flag = true; + for (int y = 0; y < 5; y++) { + for (int x = 0; x < 5; x++) { + if (place[y].charAt(x) == 'P') { + if (!bfs(y, x, place)) { + flag = false; + } + } + + if (!flag) break; + } + if (!flag) break; + } + + if (flag) { + answer[i] = 1; + } else { + answer[i] = 0; + } + } + return answer; + } + + static boolean bfs(int y, int x, String[] place) { + boolean[][] visited = new boolean[5][5]; + visited[y][x] = true; + + Queue queue = new LinkedList<>(); + queue.offer(y); + queue.offer(x); + + while (!queue.isEmpty()) { + int nowY = queue.poll(); + int nowX = queue.poll(); + + for (int i = 0; i < 4; i++) { + int newY = nowY + dY[i]; + int newX = nowX + dX[i]; + + if (newY < 0) continue; + if (newY >= 5) continue; + if (newX < 0) continue; + if (newX >= 5) continue; + if (newY == y && newX == x) continue; + if (visited[newY][newX]) continue; + + int distance = Math.abs(newY - y) + Math.abs(newX - x); + + // 거리 내에 사람이 있다면 false + if (place[newY].charAt(newX) == 'P' && distance <= 2) { + return false; + } else if (place[newY].charAt(newX) == 'O' && distance < 2) { + // 공석인 경우 + queue.offer(newY); + queue.offer(newX); + visited[newY][newX] = true; + } + } + } + + return true; + } + +} diff --git "a/2023/11.25/\354\206\241\352\270\260\355\233\210/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" "b/2023/11.25/\354\206\241\352\270\260\355\233\210/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" new file mode 100644 index 0000000..f68c43f --- /dev/null +++ "b/2023/11.25/\354\206\241\352\270\260\355\233\210/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.java" @@ -0,0 +1,62 @@ +package programmers.lv2; + +import java.util.ArrayList; +import java.util.HashMap; + +//class Test { +// +// public static void main(String[] args) { +// String[] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; +// new 오픈채팅방().solution(record); +// } +// +//} + +public class 오픈채팅방 { + + public String[] solution(String[] record) { + ArrayList answerList = new ArrayList(); + HashMap idMap = new HashMap<>(); + + for (int i = 0; i < record.length; i++) { + String[] sRecord = record[i].split(" "); + + if (sRecord[0].equals("Enter")) { + if (!idMap.containsKey(sRecord[1])) { + idMap.put(sRecord[1], sRecord[2]); + } else { + idMap.replace(sRecord[1], sRecord[2]); + } + } else if (sRecord[0].equals("Change")) { + if (idMap.containsKey(sRecord[1])) { + idMap.replace(sRecord[1], sRecord[2]); + } + } + } + + for (int i = 0; i < record.length; i++) { + String[] sRecord = record[i].split(" "); + StringBuilder sb = new StringBuilder(); + + if (sRecord[0].equals("Change")) continue; + + sb.append(idMap.get(sRecord[1])); + sb.append("님이 "); + if(sRecord[0].equals("Enter")) { + sb.append("들어왔습니다."); + } else if (sRecord[0].equals("Leave")) { + sb.append("나갔습니다."); + } + + answerList.add(sb.toString()); + } + + String[] answer = new String[answerList.size()]; + for (int i = 0; i < answerList.size(); i++) { + answer[i] = answerList.get(i); + } + + return answer; + } + +} From 13339b6063460597c3512b4ce0bd5224ece338a8 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Fri, 24 Nov 2023 23:28:07 +0900 Subject: [PATCH 807/822] =?UTF-8?q?Create=20=EC=98=B5=EC=B1=97.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\230\265\354\261\227.java" | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 "2023/11.25/\354\240\225\355\230\270\354\241\260/\354\230\265\354\261\227.java" diff --git "a/2023/11.25/\354\240\225\355\230\270\354\241\260/\354\230\265\354\261\227.java" "b/2023/11.25/\354\240\225\355\230\270\354\241\260/\354\230\265\354\261\227.java" new file mode 100644 index 0000000..f0b08a4 --- /dev/null +++ "b/2023/11.25/\354\240\225\355\230\270\354\241\260/\354\230\265\354\261\227.java" @@ -0,0 +1,137 @@ +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class 오픈채팅방 { + public static void main(String[] args) throws IOException { + String[] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo", "Leave uid1234", "Enter uid1234 Prodo", "Change uid4567 Ryan"}; + + Solution s = new Solution(); + System.out.println(Arrays.toString(s.solution(record))); + } + + static class Solution { + public String[] solution(String[] record) { + Map userNameInfo = new HashMap<>(); //id와 nickname을 담는 map + int answerSize = 0; //Change를 제외한 횟수 + StringTokenizer st; + + //id와 nickname 정보 추출 + for (String curRecord : record) { + st = new StringTokenizer(curRecord); + + String info = st.nextToken(); + String id = st.nextToken(); + String nickname = st.hasMoreTokens() ? st.nextToken() : ""; + + switch (info) { + case "Enter": { + if (!userNameInfo.containsKey(id)) userNameInfo.put(id, nickname); + else if (!userNameInfo.get(id).equals(nickname)) userNameInfo.replace(id, nickname); + answerSize++; + break; + } + case "Change": { + userNameInfo.replace(id, nickname); + break; + } + case "Leave": { + answerSize++; + break; + } + } + } + + String[] answer = new String[answerSize]; + int idx = 0; + + //정답 배열 입력 + for (String curRecord : record) { + st = new StringTokenizer(curRecord); + + String info = st.nextToken(); + String id = st.nextToken(); + String nickname = userNameInfo.get(id); + + String msgEnter = "님이 들어왔습니다."; + String msgLeave = "님이 나갔습니다."; + + if (info.equals("Enter")) { + answer[idx++] = nickname + msgEnter; + } else if (info.equals("Leave")) { + answer[idx++] = nickname + msgLeave; + } + } + + return answer; + } + } +} + +//좋은 풀이가 있길래 가져와봤습니다. [출처 : https://school.programmers.co.kr/learn/courses/30/lessons/42888/solution_groups?language=java (이규철님)] +//class Solution { +// private static final String ENTER_FORMAT = "%s님이 들어왔습니다."; +// private static final String LEAVE_FORMAT = "%s님이 나갔습니다."; +// +// private HashMap userMap = new HashMap<>(); +// +// private class UserInfo { +// public String userId; +// public String nickName; +// +// public UserInfo(String userId, String nickName) { +// this.userId = userId; +// this.nickName = nickName; +// } +// +// } +// +// private class Command { +// public char command; +// public String userId; +// +// public Command(char command, String userName) { +// this.command = command; +// this.userId = userName; +// } +// } +// +// +// public String[] solution(String[] records) { +// ArrayList commandList = new ArrayList<>(); +// +// for (String record : records) { +// String[] split = record.split(" "); +// String command = split[0]; +// String userId = split[1]; +// String nickName = null; +// +// switch(command.charAt(0)) { +// case 'E': // Enter +// nickName = split[2]; +// if(userMap.containsKey(userId) == false) { +// userMap.put(userId, new UserInfo(userId, nickName)); +// } else { +// userMap.get(userId).nickName = nickName; +// } +// +// commandList.add(new Command(command.charAt(0), userId)); +// break; +// case 'L': // Leave +// commandList.add(new Command(command.charAt(0), userId)); +// break; +// case 'C': // Change +// nickName = split[2]; +// userMap.get(userId).nickName = nickName; +// break; +// } +// } +// +// return commandList.stream() +// .map(cmd -> String.format( cmd.command == 'E' ? ENTER_FORMAT : LEAVE_FORMAT , userMap.get(cmd.userId).nickName)) +// .toArray(ary -> new String[commandList.size()]); +// } +//} + From 7081ddad96a54eb5e7fd9254a744488c1ded226a Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Sat, 25 Nov 2023 01:40:39 +0900 Subject: [PATCH 808/822] =?UTF-8?q?Create=20=EC=BD=94=EC=8B=9C=EA=B5=AD.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\275\224\354\213\234\352\265\255.java" | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 "2023/11.25/\354\240\225\355\230\270\354\241\260/\354\275\224\354\213\234\352\265\255.java" diff --git "a/2023/11.25/\354\240\225\355\230\270\354\241\260/\354\275\224\354\213\234\352\265\255.java" "b/2023/11.25/\354\240\225\355\230\270\354\241\260/\354\275\224\354\213\234\352\265\255.java" new file mode 100644 index 0000000..753f64e --- /dev/null +++ "b/2023/11.25/\354\240\225\355\230\270\354\241\260/\354\275\224\354\213\234\352\265\255.java" @@ -0,0 +1,113 @@ +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; + +//bfs로 풀었지만 거리가 2이하일 때 X가 안나오면 무조건 answer는 0이므로 dfs 코드가 더 깔끔함 +public class 거리두기확인하기 { + public static void main(String[] args) throws IOException { + String[][] places = {{"POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"}, {"POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"}, { + "PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"}, {"OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"}, { + "PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"}}; + + Solution s = new Solution(); + + System.out.println(Arrays.toString(s.solution(places))); + } + + static class Solution { + int[] dr = {-1, 0, 1, 0}; + int[] dc = {0, 1, 0, -1}; + String[] curRoom; + Queue queue; + boolean[][] vis; + + public int[] solution(String[][] places) { + int[] answer = new int[places.length]; + queue = new LinkedList<>(); + + for (int i = 0; i < places.length; i++) { + curRoom = places[i]; + boolean checkResult = true; + + Loop: + for (int r = 0; r < 5; r++) { + for (int c = 0; c < 5; c++) { + if (curRoom[r].charAt(c) == 'P') { + queue.clear(); + vis = new boolean[5][5]; + if (!checkAround(r, c)) { + checkResult = false; + break Loop; + } + } + } + } + answer[i] = checkResult ? 1 : 0; + } + return answer; + } + + //사람 기준으로 거리 2인 곳만 BFS 탐색 + boolean checkAround(int r, int c) { + vis[r][c] = true; + queue.add(new Point(r, c, 0)); + while (!queue.isEmpty()) { + Point cur = queue.poll(); + for (int d = 0; d < 4; d++) { + int nextR = cur.r + dr[d]; + int nextC = cur.c + dc[d]; + int distance = cur.distance + 1; + + if (distance > 2) break; + + if (0 <= nextR && nextR < 5 && 0 <= nextC && nextC < 5 && !vis[nextR][nextC]) { + char nextSeat = curRoom[nextR].charAt(nextC); + if (distance <= 1) { //인접했는데 사람이면 종료 + if (nextSeat == 'P') return false; + } else { + if (nextSeat == 'P' && !checkPartition(r, c, nextR, nextC)) return false; + } + + vis[nextR][nextC] = true; + queue.add(new Point(nextR, nextC, distance)); + } + } + } + + return true; + } + + boolean checkPartition(int personR, int personC, int nextR, int nextC) { + if (personC == nextC) { //세로로 마주한 경우 + return curRoom[Math.min(personR, nextR) + 1].charAt(personC) == 'X'; + } else if (personR == nextR) { //가로로 마주한 경우 + return curRoom[personR].charAt(Math.min(personC, nextC) + 1) == 'X'; + } else { //대각으로 마주한 경우 -> 원래 사람 좌표(bfs의 시작점 == personR, personC)에서 부터 새로 발견한 사람의 좌표(nextR, nextC)까지 탐색했을 때 이미 사람이 2명이므로 파티션도 두 번 나와야함 + int startR = Math.min(personR, nextR); + int endR = Math.max(personR, nextR); + int startC = Math.min(personC, nextC); + int endC = Math.max(personC, nextC); + int partitionCnt = 0; + + for (int i = startR; i <= endR; i++) { + for (int j = startC; j <= endC; j++) { + if (curRoom[i].charAt(j) == 'X') partitionCnt++; + } + } + + return partitionCnt >= 2; + } + } + + class Point { + int r, c, distance; + + public Point(int r, int c, int distance) { + this.r = r; + this.c = c; + this.distance = distance; + } + } + } +} From 51874b6206ff9f2f7e27090ab039d6b88b79354f Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 27 Nov 2023 19:15:47 +0900 Subject: [PATCH 809/822] =?UTF-8?q?Create=20=EB=B3=B4=EC=84=9D=EC=87=BC?= =?UTF-8?q?=ED=95=91.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\204\235\354\207\274\355\225\221.java" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "2023/11.28/\354\240\225\355\230\270\354\241\260/\353\263\264\354\204\235\354\207\274\355\225\221.java" diff --git "a/2023/11.28/\354\240\225\355\230\270\354\241\260/\353\263\264\354\204\235\354\207\274\355\225\221.java" "b/2023/11.28/\354\240\225\355\230\270\354\241\260/\353\263\264\354\204\235\354\207\274\355\225\221.java" new file mode 100644 index 0000000..265c9af --- /dev/null +++ "b/2023/11.28/\354\240\225\355\230\270\354\241\260/\353\263\264\354\204\235\354\207\274\355\225\221.java" @@ -0,0 +1,54 @@ +import java.util.*; + + +/** + * 투포인터 문제 + * 1) 구매해야하는 보성 종류의 수를 구함 + * 2) 0 ~ gems.length까지 순회하면서 보석을 map에 저장 + * 3) gems[start] 보석이 2번 이상 나왔다면 그 횟수가 1이 될 때까지 -- 해주고 start는 ++ + * 3-1) end 번재에서 gems[start] 보석이 나왔기 때문에 gems[start]보석이 2 이상이 될 수 있음 + * 3-2) 따라서 현재까지 구매한 보석의 수가 한 개일 때까지 계속 start를 증가시켜줌 + * 4) 현재까지 구매한 보석의 종류(map의 크기)와 구매해야하는 보석 종류의 수가 같다면 length 갱신 + * 4-1) length를 갱신하지 않고 바로 break 해버리면 start가 더 증가했을 때 최소 길이의 경우의 수가 있음에도 불구하고 찾을 수 없음 + * 4-2) start는 0부터 시작하고 map.size() == resultSize일 때 length 크기 판별 조건식에서 length와 최소 길이(end - start)가 같은 경우를 포함하지 않으므로 시작점이 작은 것만 answer에 저장할 수 있음 + */ +public class 보석쇼핑 { + public static void main(String[] args) { + String[][] gems = {{"A", "B", "B", "B", "B", "B", "B", "C", "B", "A"}, {"DIA", "RUBY", "RUBY", "DIA", "DIA", "EMERALD", "SAPPHIRE", "DIA"}, {"AA", "AB", "AC", "AA", "AC"}, {"XYZ", "XYZ", "XYZ"}, {"ZZZ", "YYY", "NNNN", "YYY", "BBB"}}; + + Solution s = new Solution(); + for (String[] gem : gems) { + System.out.println(Arrays.toString(s.solution(gem))); + } + } + + static class Solution { + public int[] solution(String[] gems) { + int[] answer = new int[2]; + + Set gemsSet = new HashSet<>(); + Map map = new HashMap<>(); + Collections.addAll(gemsSet, gems); + int resultSize = gemsSet.size(); + + int start = 0, length = gems.length + 1; + + for (int end = 0; end < gems.length; end++) { + map.put(gems[end], map.getOrDefault(gems[end], 0) + 1); + + while (map.get(gems[start]) > 1) { + map.put(gems[start], map.get(gems[start]) - 1); + start++; + } + + if (map.size() == resultSize && length > end - start) { + length = end - start; + answer[0] = start + 1; + answer[1] = end + 1; + } + } + + return answer; + } + } +} From 2c855fde213bbf36fb0036cfc040647f5006adf3 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Mon, 27 Nov 2023 19:17:04 +0900 Subject: [PATCH 810/822] Create README.md --- 2023/11.28/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 2023/11.28/README.md diff --git a/2023/11.28/README.md b/2023/11.28/README.md new file mode 100644 index 0000000..44a37e8 --- /dev/null +++ b/2023/11.28/README.md @@ -0,0 +1,4 @@ +# 11.28(화) 스터디 + +- 프로그래머스 + - [보석쇼핑](https://school.programmers.co.kr/learn/courses/30/lessons/67258) From 342640a13940df587189fc65c8268ac8cbeb5531 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Mon, 27 Nov 2023 22:51:09 +0900 Subject: [PATCH 811/822] [SOLVE] @sindorim5 1128 --- ...\354\204\235\354\207\274\355\225\221.java" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "2023/11.28/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" diff --git "a/2023/11.28/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" "b/2023/11.28/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" new file mode 100644 index 0000000..30de214 --- /dev/null +++ "b/2023/11.28/\354\206\241\352\270\260\355\233\210/\353\263\264\354\204\235\354\207\274\355\225\221.java" @@ -0,0 +1,38 @@ +package programmers.lv3; + +import java.util.*; + +public class 보석쇼핑 { + + public int[] solution(String[] gems) { + int[] answer = new int[2]; + + HashSet gemSet = new HashSet<>(Arrays.asList(gems)); + int kind = gemSet.size(); + + int start = 0; + int size = Integer.MAX_VALUE; + + Map gemMap = new HashMap<>(); + + for (int end = 0; end < gems.length; end++) { + gemMap.put(gems[end], gemMap.getOrDefault(gems[end], 0) + 1); + + // 1개보다 많으면 1개 빼고 start index를 하나 올린다 + while (gemMap.get(gems[start]) > 1) { + gemMap.put(gems[start], gemMap.get(gems[start]) - 1); + start++; + } + + // gemMap의 크기와 종류가 같다 & 더 작은 사이즈면 갱신 + if (gemMap.size() == kind && size > (end - start)) { + size = end - start; + answer[0] = start + 1; + answer[1] = end + 1; + } + } + + return answer; + } + +} From 74d9f021bcc03a551b1f7fe2bed2e62d4020d0d6 Mon Sep 17 00:00:00 2001 From: su6378 Date: Tue, 28 Nov 2023 10:58:18 +0900 Subject: [PATCH 812/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=20=EB=91=90?= =?UTF-8?q?=20=EC=9A=A9=EC=95=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\221\220_\354\232\251\354\225\241.java" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "2023/11.30/\354\241\260\354\210\230\354\227\260/\353\221\220_\354\232\251\354\225\241.java" diff --git "a/2023/11.30/\354\241\260\354\210\230\354\227\260/\353\221\220_\354\232\251\354\225\241.java" "b/2023/11.30/\354\241\260\354\210\230\354\227\260/\353\221\220_\354\232\251\354\225\241.java" new file mode 100644 index 0000000..0788bda --- /dev/null +++ "b/2023/11.30/\354\241\260\354\210\230\354\227\260/\353\221\220_\354\232\251\354\225\241.java" @@ -0,0 +1,42 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int n = Integer.parseInt(br.readLine()); + int[] solutions = new int[n]; + StringTokenizer st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < n; i++) { + solutions[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(solutions); + + int[] answer = new int[2]; + int start = 0; + int end = n - 1; + int minSum = Integer.MAX_VALUE; // 0에 가장 가까운 특성값 + + while (start < end) { + int sum = solutions[start] + solutions[end]; // 특성값 + + if (Math.abs(sum) < minSum) { + minSum = Math.abs(sum); + answer[0] = solutions[start]; + answer[1] = solutions[end]; + } + + if (sum > 0) end--; // 산성용액값을 낮추기 + else start++; // 알칼리성용액값 낮추기 + } + + bw.write(answer[0] + " " + answer[1]); + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From b9c5806894bc5dad6f5e96916e78bc09a8b675e2 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:33:00 +0900 Subject: [PATCH 813/822] Create README.md --- 2023/11.30/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/11.30/README.md diff --git a/2023/11.30/README.md b/2023/11.30/README.md new file mode 100644 index 0000000..1ebf9a3 --- /dev/null +++ b/2023/11.30/README.md @@ -0,0 +1,5 @@ +# 11.30(목) 스터디 + +- 백준 + - [두 용액 2470](https://www.acmicpc.net/problem/2470) + - [1,2,3더하기7 15992](https://www.acmicpc.net/problem/15992) From f935b3909bc0aebb2cb2b6dd60da0a79e31b7f61 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:33:33 +0900 Subject: [PATCH 814/822] =?UTF-8?q?Create=201,2,3=EB=8D=94=ED=95=98?= =?UTF-8?q?=EA=B8=B07.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\215\224\355\225\230\352\270\2607.java" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "2023/11.30/\354\240\225\355\230\270\354\241\260/1,2,3\353\215\224\355\225\230\352\270\2607.java" diff --git "a/2023/11.30/\354\240\225\355\230\270\354\241\260/1,2,3\353\215\224\355\225\230\352\270\2607.java" "b/2023/11.30/\354\240\225\355\230\270\354\241\260/1,2,3\353\215\224\355\225\230\352\270\2607.java" new file mode 100644 index 0000000..67187e3 --- /dev/null +++ "b/2023/11.30/\354\240\225\355\230\270\354\241\260/1,2,3\353\215\224\355\225\230\352\270\2607.java" @@ -0,0 +1,42 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/**dp문제 + * 1) 점화식 : dp[n][m] = dp[n-1][m-1] + dp[n-2][m-1] + dp[n-3][m-1] + * 2) 예를 들어 3개의 숫자로 6을 만들어야한다고 했을 때(dp[6][3]) + * 2-1) 첫 번째 숫자가 1일 경우 -> 나머지 두 개의 숫자로 5를 만드는 경우 == dp[5][2], 2일 경우 -> 나머지 두 개의 숫자로 4를 만드는 경우 == dp[4][2], 3일 경우 -> 나머지 두 개의 숫자로 3을 만드는 경우 == dp[3][2] + * 3) 따라서 먼저 1001 x 1001 배열을 만들어 놓은 후 tc에 대한 값을 출력 + * */ +public class 일이삼더하기7 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + int R = 1_000_000_009; + + int[][] dp = new int[1001][1001]; + + dp[1][1] = dp[2][1] = dp[3][1] = dp[2][2] = dp[3][3] = 1; + dp[3][2] = 2; + + for (int i = 4; i <= 1000; i++) { + for (int j = 2; j <= 1000; j++) { + for (int k = 1; k <= 3; k++) { + dp[i][j] = (dp[i][j] + dp[i - k][j - 1]) % R; + } + } + } + + for (int tc = 0; tc < T; tc++) { + st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + System.out.println(dp[n][m]); + } + } +} From 893b746ff50c3487c61c3b86a827d09d3020eef1 Mon Sep 17 00:00:00 2001 From: HoJoJeong <43957736+hojoJeong@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:21:16 +0900 Subject: [PATCH 815/822] =?UTF-8?q?Create=20=EB=91=90=EC=9A=A9=EC=95=A1.ja?= =?UTF-8?q?va?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\221\220\354\232\251\354\225\241.java" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "2023/11.30/\354\240\225\355\230\270\354\241\260/\353\221\220\354\232\251\354\225\241.java" diff --git "a/2023/11.30/\354\240\225\355\230\270\354\241\260/\353\221\220\354\232\251\354\225\241.java" "b/2023/11.30/\354\240\225\355\230\270\354\241\260/\353\221\220\354\232\251\354\225\241.java" new file mode 100644 index 0000000..6a6839c --- /dev/null +++ "b/2023/11.30/\354\240\225\355\230\270\354\241\260/\353\221\220\354\232\251\354\225\241.java" @@ -0,0 +1,45 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** + * 이분탐색 + * 1) 용액 배열을 오름차순으로 정렬해줌 -> 현재 두 용액을 더한 값이 0보다 크면 right--, 작으면 left++ 해주기 위함 + * 2) while 조건식이 left < right이기 때문에 출력하는 두 용액은 오름차순임이 보장 + */ +public class 두용액 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int n = Integer.parseInt(br.readLine()); + int[] solution = new int[n]; + st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < n; i++) { + solution[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(solution); + + int left = 0, right = solution.length - 1, ans1 = 0, ans2 = 0; + int result = Integer.MAX_VALUE; + + while (left < right) { + int cur = solution[left] + solution[right]; + int absCur = Math.abs(cur); + if (result > absCur) { + result = absCur; + ans1 = solution[left]; + ans2 = solution[right]; + } + + if (cur > 0) right--; + else if (cur < 0) left++; + else break; + } + + System.out.println(ans1 + " " + ans2); + } +} From 64abdd8fe8cdb5f17cf9380df31ee0d1ff9de163 Mon Sep 17 00:00:00 2001 From: su6378 Date: Wed, 29 Nov 2023 13:30:52 +0900 Subject: [PATCH 816/822] =?UTF-8?q?[SOLVE]=20@josooyeon11=20-=201,2,3=20?= =?UTF-8?q?=EB=8D=94=ED=95=98=EA=B8=B0=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...53\215\224\355\225\230\352\270\260_7.java" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "2023/11.30/\354\241\260\354\210\230\354\227\260/1,2,3_\353\215\224\355\225\230\352\270\260_7.java" diff --git "a/2023/11.30/\354\241\260\354\210\230\354\227\260/1,2,3_\353\215\224\355\225\230\352\270\260_7.java" "b/2023/11.30/\354\241\260\354\210\230\354\227\260/1,2,3_\353\215\224\355\225\230\352\270\260_7.java" new file mode 100644 index 0000000..6c7c44f --- /dev/null +++ "b/2023/11.30/\354\241\260\354\210\230\354\227\260/1,2,3_\353\215\224\355\225\230\352\270\260_7.java" @@ -0,0 +1,39 @@ +import java.io.*; +import java.util.*; + +public class Main { + static final int MOD = 1000000009; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + int t = Integer.parseInt(br.readLine()); + + long[][] dp = new long[1001][1001]; + + dp[1][1] = 1; + dp[2][1] = 1; + dp[2][2] = 1; + dp[3][1] = 1; + dp[3][2] = 2; + dp[3][3] = 1; + + for (int i = 4; i <= 1000; i++) { + for (int j = 1; j <= i; j++) { + dp[i][j] = (dp[i - 3][j - 1] + dp[i - 2][j - 1] + dp[i - 1][j - 1]) % MOD; // 점화식 + } + } + + for (int i = 0; i < t; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + bw.write(dp[n][m] + "\n"); + } + + bw.flush(); + bw.close(); + } +} \ No newline at end of file From ff373e445e1f49107ad7ef77a5690a1c93653b35 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Thu, 30 Nov 2023 01:15:49 +0900 Subject: [PATCH 817/822] [SOLVE] @sindorim5 1130 --- ...353\221\220_\354\232\251\354\225\241.java" | 47 ++++++++++++++++ ...355\225\230\352\270\260_\354\271\240.java" | 56 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 "2023/11.30/\354\206\241\352\270\260\355\233\210/\353\221\220_\354\232\251\354\225\241.java" create mode 100644 "2023/11.30/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\264\354\202\274_\353\215\224\355\225\230\352\270\260_\354\271\240.java" diff --git "a/2023/11.30/\354\206\241\352\270\260\355\233\210/\353\221\220_\354\232\251\354\225\241.java" "b/2023/11.30/\354\206\241\352\270\260\355\233\210/\353\221\220_\354\232\251\354\225\241.java" new file mode 100644 index 0000000..e7aa476 --- /dev/null +++ "b/2023/11.30/\354\206\241\352\270\260\355\233\210/\353\221\220_\354\232\251\354\225\241.java" @@ -0,0 +1,47 @@ +package baekjoon.gold.five; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class 두_용액 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + int[] numbers = new int[N]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + numbers[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(numbers); + + int start = 0; + int end = N - 1; + int diff = Integer.MAX_VALUE; + + int temp = 0; + int min = 0, max = 0; + while (start < end) { + temp = numbers[start] + numbers[end]; + + if (Math.abs(temp) < diff) { + diff = Math.abs(temp); + min = numbers[start]; + max = numbers[end]; + } + + if (temp > 0) end -= 1; + else start += 1; + } + + System.out.println(min + " " + max); + + } + +} diff --git "a/2023/11.30/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\264\354\202\274_\353\215\224\355\225\230\352\270\260_\354\271\240.java" "b/2023/11.30/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\264\354\202\274_\353\215\224\355\225\230\352\270\260_\354\271\240.java" new file mode 100644 index 0000000..72726b8 --- /dev/null +++ "b/2023/11.30/\354\206\241\352\270\260\355\233\210/\354\235\274\354\235\264\354\202\274_\353\215\224\355\225\230\352\270\260_\354\271\240.java" @@ -0,0 +1,56 @@ +package baekjoon.silver.one; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class 일이삼_더하기_칠 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + ArrayList answer = new ArrayList<>(); + int nMax = -1; + int mMax = -1; + + for (int i = 0; i < T; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + nMax = Math.max(n, nMax); + mMax = Math.max(m, mMax); + + answer.add(new int[] {n, m}); + + } + + // m개로 n 만들기 + long[][] dp = new long[mMax+1][nMax+1]; + dp[1][1] = 1; + dp[1][2] = 1; + dp[1][3] = 1; + long mod = 1000000009; + // dp[m][n] = dp[m-1][n-1] + dp[m-1][n-2] + dp[m-1][n-3] + for(int m = 2; m <= mMax; m++) { + for (int n = 2; n <= nMax; n++) { + dp[m][n] += dp[m-1][n-1]; + if (n-2 >= 0) { + dp[m][n] += dp[m-1][n-2]; + } + if (n-3 >= 0) { + dp[m][n] += dp[m-1][n-3]; + } + dp[m][n] %= mod; + } + } + + for (int i = 0; i < answer.size(); i++) { + int[] ans = answer.get(i); + System.out.println(dp[ans[1]][ans[0]]); + } + + } +} From b018637790712fcb8e07c99dfdaf3d1202d0caa1 Mon Sep 17 00:00:00 2001 From: chang0_0 Date: Thu, 30 Nov 2023 01:58:55 +0900 Subject: [PATCH 818/822] BOJ 2470 Solve with Java --- ...353\221\220_\354\232\251\354\225\241.java" | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 "2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_2470_\353\221\220_\354\232\251\354\225\241.java" diff --git "a/2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_2470_\353\221\220_\354\232\251\354\225\241.java" "b/2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_2470_\353\221\220_\354\232\251\354\225\241.java" new file mode 100644 index 0000000..92285d3 --- /dev/null +++ "b/2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_2470_\353\221\220_\354\232\251\354\225\241.java" @@ -0,0 +1,76 @@ +package BOJ_2470; + +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BOJ_2470_두_용액 { + + // https://www.acmicpc.net/problem/2470 + // input + private static BufferedReader br; + + // variables + private static int N; + private static long leftIdx, rightIdx, ans; + private static long[] arr; + + public static void main(String[] args) throws IOException { + System.setIn(new FileInputStream("C:\\Users\\bigyo\\Desktop\\알고리즘\\JavaAlgorithm\\src\\BOJ_2470\\res.txt")); + br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + input(); + + bw.write(solve()); + bw.close(); + } // End of main() + + private static String solve() { + StringBuilder sb = new StringBuilder(); + + Arrays.sort(arr); + + for (int i = 0; i < N - 1; i++) { + binarySearch(i, i + 1, N - 1); + } + + + sb.append(arr[(int) leftIdx]).append(' ').append(arr[(int) rightIdx]); + return sb.toString(); + } // End of solve() + + private static void binarySearch(int idx, int low, int high) { + if (low > high) { + return; + } + + int mid = (low + high) / 2; + long sum = arr[idx] + arr[mid]; + + if (Math.abs(sum) < Math.abs(ans)) { + ans = sum; + leftIdx = idx; + rightIdx = mid; + } + + if (sum < 0) { + binarySearch(idx, mid + 1, high); + } else { + binarySearch(idx, low, mid - 1); + } + } // End of binarySearch() + + private static void input() throws IOException { + N = Integer.parseInt(br.readLine()); + ans = Long.MAX_VALUE; + leftIdx = 0; + rightIdx = 0; + arr = new long[N]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + } // End of input() +} // End of Main class From e76700e0968b96397a4a87cfa776ba385ff23969 Mon Sep 17 00:00:00 2001 From: chang0_0 Date: Sat, 2 Dec 2023 19:28:58 +0900 Subject: [PATCH 819/822] BOJ 15992 Solve with Java --- ...53\215\224\355\225\230\352\270\260_7.java" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_15992_1_2_3_\353\215\224\355\225\230\352\270\260_7.java" diff --git "a/2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_15992_1_2_3_\353\215\224\355\225\230\352\270\260_7.java" "b/2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_15992_1_2_3_\353\215\224\355\225\230\352\270\260_7.java" new file mode 100644 index 0000000..598bb88 --- /dev/null +++ "b/2023/11.30/\354\265\234\354\260\275\354\230\201/BOJ_15992_1_2_3_\353\215\224\355\225\230\352\270\260_7.java" @@ -0,0 +1,60 @@ +package BOJ_15992; + +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BOJ_15992_1_2_3_더하기_7 { + + // https://www.acmicpc.net/problem/15992 + // input + private static BufferedReader br; + + // variables + private static final int MOD = 1_000_000_009; + private static int N, M; + private static int[][] memo = new int[1001][1001]; + + public static void main(String[] args) throws IOException { + System.setIn(new FileInputStream("C:\\Users\\bigyo\\Desktop\\알고리즘\\JavaAlgorithm\\src\\BOJ_15992\\res.txt")); + br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + for (int[] t : memo) { + Arrays.fill(t, -1); + } + + int T = Integer.parseInt(br.readLine()); + while (T-- > 0) { + input(); + bw.write(solve()); + } + + bw.close(); + } // End of main + + private static String solve() { + StringBuilder sb = new StringBuilder(); + + sb.append(topDown(N, M, 3)).append('\n'); + return sb.toString(); + } // End of solve() + + private static int topDown(int n, int m, int currentNumber) { + if (n == 0 && m == 0) return 1; + if (n < 0 || m < 0 || currentNumber <= 0) return 0; + + if (memo[n][m] != -1) return memo[n][m]; + + memo[n][m] = (topDown(n - currentNumber, m - 1, 3) + topDown(n, m, currentNumber - 1)) % MOD; + + return memo[n][m]; + } // End of topDown() + + private static void input() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + } // End of input() +} // End of Main class From 808ff6ecc542844ee47940700f7fa13c40dc0a48 Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 3 Dec 2023 23:54:26 +0900 Subject: [PATCH 820/822] Create README.md --- 2023/12.04/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2023/12.04/README.md diff --git a/2023/12.04/README.md b/2023/12.04/README.md new file mode 100644 index 0000000..25b2116 --- /dev/null +++ b/2023/12.04/README.md @@ -0,0 +1,5 @@ +# 12.04(월) 스터디 + +- 프로그래머스 + - [경주로 건설](https://school.programmers.co.kr/learn/courses/30/lessons/67259) + - [합승 택시 요금](https://school.programmers.co.kr/learn/courses/30/lessons/72413) From 7ffb3df67460427b17a47f039a40e94d0f9c9cdd Mon Sep 17 00:00:00 2001 From: Kihun SONG Date: Sun, 3 Dec 2023 23:55:36 +0900 Subject: [PATCH 821/822] [SOLVE] @sindorim5 1204 --- ...353\241\234_\352\261\264\354\204\244.java" | 192 ++++++++++++++++++ ...354\213\234_\354\232\224\352\270\210.java" | 113 +++++++++++ 2 files changed, 305 insertions(+) create mode 100644 "2023/12.04/\354\206\241\352\270\260\355\233\210/\352\262\275\354\243\274\353\241\234_\352\261\264\354\204\244.java" create mode 100644 "2023/12.04/\354\206\241\352\270\260\355\233\210/\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" diff --git "a/2023/12.04/\354\206\241\352\270\260\355\233\210/\352\262\275\354\243\274\353\241\234_\352\261\264\354\204\244.java" "b/2023/12.04/\354\206\241\352\270\260\355\233\210/\352\262\275\354\243\274\353\241\234_\352\261\264\354\204\244.java" new file mode 100644 index 0000000..1136e51 --- /dev/null +++ "b/2023/12.04/\354\206\241\352\270\260\355\233\210/\352\262\275\354\243\274\353\241\234_\352\261\264\354\204\244.java" @@ -0,0 +1,192 @@ +package programmers.lv3; + +import java.util.*; + +//class Test { +// +// public static void main(String[] args) { +//// int[][] board = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; +// int[][] board = { +// {0, 0, 0, 0, 0, 0, 0, 0}, +// {1, 0, 1, 1, 1, 1, 1, 0}, +// {1, 0, 0, 1, 0, 0, 0, 0}, +// {1, 1, 0, 0, 0, 1, 1, 1}, +// {1, 1, 1, 1, 0, 0, 0, 0}, +// {1, 1, 1, 1, 1, 1, 1, 0}, +// {1, 1, 1, 1, 1, 1, 1, 0}, +// {1, 1, 1, 1, 1, 1, 1, 0} +// }; +// System.out.println(new 경주로_건설().solution(board)); +// } +// +//} + +public class 경주로_건설 { + + int[] dY = {1, 0, -1, 0}; + int[] dX = {0, 1, 0, -1}; + int n, minValue; + boolean[][][] visited; + int[][] nBoard, matrix; + + public int solution(int[][] board) { + int answer = 0; + + n = board.length; + minValue = Integer.MAX_VALUE; + nBoard = board; + matrix = new int[n][n]; + visited = new boolean[n][n][4]; + + for (int[] m : matrix) { + Arrays.fill(m, 9999); + } + + bfs(0, 0, -1, 0); + + answer = minValue; + + return answer; + } + + public void bfs(int y, int x, int dir, int cost) { + Queue queue = new LinkedList<>(); + queue.offer(new Node(y, x, dir, cost)); + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + if (now.y == n - 1 && now.x == n - 1) { + minValue = Math.min(now.cost, minValue); + continue; + } + + for (int i = 0; i < 4; i++) { + int nY = now.y + dY[i]; + int nX = now.x + dX[i]; + int nDir = i; + int nCost = now.cost; + + if (nY < 0) continue; + if (nX < 0) continue; + if (nY >= n) continue; + if (nX >= n) continue; + if (nBoard[nY][nX] == 1) continue; + + if (now.dir == -1 || now.dir == nDir) { + nCost += 100; + } else { + // 역주행은 가격이 비싸서 알아서 걸러짐 + nCost += 600; + } + + if (!visited[nY][nX][nDir] || matrix[nY][nX] >= nCost) { + queue.offer(new Node(nY, nX, nDir, nCost)); + visited[nY][nX][nDir] = true; + matrix[nY][nX] = nCost; + } + + } + + } + + } + + class Node { + int y, x, dir, cost; + + public Node(int y, int x, int dir, int cost) { + this.y = y; + this.x = x; + this.dir = dir; + this.cost = cost; + } + } + +} + +/* +import java.util.*; + +class Solution { + int[] dY = {1, 0, -1, 0}; + int[] dX = {0, 1, 0, -1}; + int n, minValue; + int[][] nBoard, matrix; + + public int solution(int[][] board) { + int answer = 0; + + n = board.length; + minValue = Integer.MAX_VALUE; + nBoard = board; + matrix = new int[n][n]; + for (int[] m : matrix) { + Arrays.fill(m, Integer.MAX_VALUE); + } + + + bfs(0, 0, -1, 0); + + answer = minValue; + + return answer; + } + + public void bfs(int y, int x, int dir, int cost) { + Queue queue = new LinkedList<>(); + queue.offer(new Node(y, x, dir, cost)); + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + if (now.y == n - 1 && now.x == n - 1) { + minValue = Math.min(now.cost, minValue); + continue; + } + + for (int i = 0; i < 4; i++) { + int nY = now.y + dY[i]; + int nX = now.x + dX[i]; + int nDir = i; + int nCost = now.cost; + + if (nY < 0) continue; + if (nX < 0) continue; + if (nY >= n) continue; + if (nX >= n) continue; + if (nBoard[nY][nX] == 1) continue; + + if (now.dir == -1) { + nCost += 100; + } else if (now.dir == nDir) { + nCost += 100; + } else { + // 역주행은 가격이 비싸서 알아서 걸러짐 + nCost += 600; + } + + if (matrix[nY][nX] >= nCost) { + matrix[nY][nX] = nCost; + queue.offer(new Node(nY, nX, nDir, nCost)); + } + + } + + } + + } + + class Node { + int y, x, dir, cost; + + public Node(int y, int x, int dir, int cost) { + this.y = y; + this.x = x; + this.dir = dir; + this.cost = cost; + } + } + +} + */ diff --git "a/2023/12.04/\354\206\241\352\270\260\355\233\210/\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" "b/2023/12.04/\354\206\241\352\270\260\355\233\210/\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" new file mode 100644 index 0000000..011aaf6 --- /dev/null +++ "b/2023/12.04/\354\206\241\352\270\260\355\233\210/\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" @@ -0,0 +1,113 @@ +package programmers.lv3; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.PriorityQueue; + +// class Test { +// public static void main(String[] args) { +// int n = 6; +// int s = 4; +// int a = 6; +// int b = 2; +// int[][] fares = { +// {4, 1, 10}, +// {3, 5, 24}, +// {5, 6, 2}, +// {3, 1, 41}, +// {5, 1, 24}, +// {4, 6, 50}, +// {2, 4, 66}, +// {2, 3, 22}, +// {1, 6, 25} +// }; + +// System.out.println(new 합승_택시_요금().solution(n, s, a, b, fares)); +// } +// } + +public class 합승_택시_요금 { + + ArrayList> nodeList; + int[] dpA, dpB, dpS; + int maxValue = 200 * 100000 + 1; + + public int solution(int n, int s, int a, int b, int[][] fares) { + int answer = maxValue; + nodeList = new ArrayList<>(); + for (int i = 0; i <= n; i++) { + nodeList.add(new ArrayList<>()); + } + + for (int i = 0; i < fares.length; i++) { + int nodeA = fares[i][0]; + int nodeB = fares[i][1]; + int price = fares[i][2]; + + nodeList.get(nodeA).add(new Node(nodeB, price)); + nodeList.get(nodeB).add(new Node(nodeA, price)); + } + + dpA = new int[n+1]; + dpB = new int[n+1]; + dpS = new int[n+1]; + + Arrays.fill(dpA, maxValue); + Arrays.fill(dpB, maxValue); + Arrays.fill(dpS, maxValue); + + dijksktra(a, dpA); + dijksktra(b, dpB); + dijksktra(s, dpS); + + for (int i = 1; i <= n; i++) { + int price = dpA[i] + dpB[i] + dpS[i]; + answer = Math.min(answer, price); + } + + return answer; + } + + public int[] dijksktra(int start, int[] dp) { + PriorityQueue queue = new PriorityQueue<>(); + queue.offer(new Node(start, 0)); + dp[start] = 0; + + while (!queue.isEmpty()) { + Node now = queue.poll(); + + ArrayList nodes = nodeList.get(now.end); + + for (Node node : nodes) { + int nPrice = node.price + dp[now.end]; + + if (nPrice < dp[node.end]) { + dp[node.end] = nPrice; + queue.offer(new Node(node.end, nPrice)); + } + } + } + + return dp; + } + + class Node implements Comparable { + + int end, price; + + public Node(int end, int price) { + this.end = end; + this.price = price; + } + + @Override + public String toString() { + return "end: " + end + " price: " + price; + } + + @Override + public int compareTo(Node n) { + return this.price - n.price; + } + } +} From f4860291f4c907ffaa291ec1a1c5a8619b078993 Mon Sep 17 00:00:00 2001 From: chang0_0 Date: Tue, 5 Dec 2023 14:58:46 +0900 Subject: [PATCH 822/822] =?UTF-8?q?PRG=2072413=20=ED=95=A9=EC=8A=B9=20?= =?UTF-8?q?=ED=83=9D=EC=8B=9C=20=EC=9A=94=EA=B8=88=20Solve=20with=20Java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\213\234_\354\232\224\352\270\210.java" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "2023/12.04/\354\265\234\354\260\275\354\230\201/PRG_72413_\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" diff --git "a/2023/12.04/\354\265\234\354\260\275\354\230\201/PRG_72413_\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" "b/2023/12.04/\354\265\234\354\260\275\354\230\201/PRG_72413_\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" new file mode 100644 index 0000000..c45081f --- /dev/null +++ "b/2023/12.04/\354\265\234\354\260\275\354\230\201/PRG_72413_\355\225\251\354\212\271_\355\203\235\354\213\234_\354\232\224\352\270\210.java" @@ -0,0 +1,85 @@ +package PRG_72413; + +import java.util.*; + +class Solution { + static int INF = Integer.MAX_VALUE / 4; + static int N, A, S, B; + static List> adjList; + + static class Node implements Comparable { + int num; + int weight; + + public Node(int num, int weight) { + this.num = num; + this.weight = weight; + } // End of Node() + + @Override + public String toString() { + return "[num : " + num + ", " + "weight : " + weight + "]"; + } + + @Override + public int compareTo(Node o) { + return weight - o.weight; + } + } // End of Node class + + public int solution(int n, int s, int a, int b, int[][] fares) { + int ans = INF; + + input(n, s, a, b, fares); + + // 1. 택시를 타고 간다고 했을 때 가장 싸게 갈 수 있는 출발지를 찾는다. + for(int i=1; i<=N; i++) { + if(adjList.get(i).isEmpty()) continue; + ans = Math.min(ans, dijkstra(i)); + } + + return ans; + } // End of solution() + + public int dijkstra(int start) { + int[] dist = new int[N + 1]; + Arrays.fill(dist, INF); + dist[start] = 0; + + PriorityQueue pQ = new PriorityQueue<>(); + pQ.offer(new Node(start, 0)); + + while(!pQ.isEmpty()) { + Node now = pQ.poll(); + + if(dist[now.num] < now.weight) continue; + + for(Node next : adjList.get(now.num)) { + if(dist[next.num] > dist[now.num] + next.weight ) { + dist[next.num] = dist[now.num] + next.weight; + pQ.offer(new Node(next.num, dist[next.num])); + } + } + } + + int sum = dist[S] + dist[A] + dist[B]; + return sum; + } // End of dijkstra() + + public void input(int n, int s, int a, int b, int[][] fares) { + A = a; + B = b; + S = s; + N = n; + + adjList = new ArrayList<>(); + for(int i=0; i<=N; i++) { + adjList.add(new ArrayList<>()); + } + + for(int[] t : fares) { + adjList.get(t[0]).add(new Node(t[1], t[2])); + adjList.get(t[1]).add(new Node(t[0], t[2])); + } + } // End of input() +} // End of Solution class \ No newline at end of file