From e5d9c178369fe939e9c2435beb23b78d441d6bbf Mon Sep 17 00:00:00 2001 From: hangyeol Date: Mon, 10 Mar 2025 20:02:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?90=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "live8/test90/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" diff --git "a/live8/test90/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" "b/live8/test90/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..6737e6e5 --- /dev/null +++ "b/live8/test90/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,30 @@ +def main(): + n = int(input()) + + array = list(map(int, input().strip().split()))[:n] + + x = int(input()) + + array.sort() + + count = 0 + left, right = 0, n - 1 + + while left < right: + sum = array[left] + array[right] + + if sum == x: + count += 1 + left += 1 + right -= 1 + elif sum < x: + left += 1 + else: + right -= 1 + + + print(count) + + +if __name__ == '__main__': + main() \ No newline at end of file From b9b0c6cbcfb65007f1fe8bcb31d8ce847fd3808e Mon Sep 17 00:00:00 2001 From: hangyeol Date: Mon, 10 Mar 2025 20:03:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?90=EC=B0=A8=203=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "live8/test90/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" diff --git "a/live8/test90/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" "b/live8/test90/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..0ac15efd --- /dev/null +++ "b/live8/test90/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,17 @@ +def solution(n, computers): + visited = [False] * n + + def dfs(v): + visited[v] = True + for i in range(n): + if computers[v][i] == 1 and not visited[i]: + dfs(i) + + count = 0 + + for i in range(n): + if not visited[i]: + dfs(i) + count += 1 + + return count \ No newline at end of file From 0a7269380984690c5b1b594bcac2a4d8d48aa7e5 Mon Sep 17 00:00:00 2001 From: hangyeol Date: Tue, 11 Mar 2025 23:13:26 +0900 Subject: [PATCH 3/3] =?UTF-8?q?90=EC=B0=A8=202=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "live8/test90/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" diff --git "a/live8/test90/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" "b/live8/test90/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..69c60906 --- /dev/null +++ "b/live8/test90/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,27 @@ +from itertools import * + + +def main(): + + # 백트래킹을 이용한 방법 + N, M = map(int, input().split()) + + def backtrack(start, sequence): + if len(sequence) == M: + print(' '.join(map(str, sequence))) + return + + for i in range(start, N+1): + backtrack(i+1, sequence+[i]) + + backtrack(1, []) + + # combinations를 이용한 방법 + N, M = map(int, input().split()) + + for c in combinations(range(1, N+1), M): + print(' '.join(map(str, c))) + + +if __name__ == '__main__': + main() \ No newline at end of file