Skip to content

Commit ba0aea2

Browse files
Merge pull request #621 from baekhangyeol/main
[백한결] 90차 라이브 코테 제출
2 parents bcea050 + 0a72693 commit ba0aea2

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

live8/test90/문제1/백한결.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def main():
2+
n = int(input())
3+
4+
array = list(map(int, input().strip().split()))[:n]
5+
6+
x = int(input())
7+
8+
array.sort()
9+
10+
count = 0
11+
left, right = 0, n - 1
12+
13+
while left < right:
14+
sum = array[left] + array[right]
15+
16+
if sum == x:
17+
count += 1
18+
left += 1
19+
right -= 1
20+
elif sum < x:
21+
left += 1
22+
else:
23+
right -= 1
24+
25+
26+
print(count)
27+
28+
29+
if __name__ == '__main__':
30+
main()

live8/test90/문제2/백한결.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from itertools import *
2+
3+
4+
def main():
5+
6+
# 백트래킹을 이용한 방법
7+
N, M = map(int, input().split())
8+
9+
def backtrack(start, sequence):
10+
if len(sequence) == M:
11+
print(' '.join(map(str, sequence)))
12+
return
13+
14+
for i in range(start, N+1):
15+
backtrack(i+1, sequence+[i])
16+
17+
backtrack(1, [])
18+
19+
# combinations를 이용한 방법
20+
N, M = map(int, input().split())
21+
22+
for c in combinations(range(1, N+1), M):
23+
print(' '.join(map(str, c)))
24+
25+
26+
if __name__ == '__main__':
27+
main()

live8/test90/문제3/백한결.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(n, computers):
2+
visited = [False] * n
3+
4+
def dfs(v):
5+
visited[v] = True
6+
for i in range(n):
7+
if computers[v][i] == 1 and not visited[i]:
8+
dfs(i)
9+
10+
count = 0
11+
12+
for i in range(n):
13+
if not visited[i]:
14+
dfs(i)
15+
count += 1
16+
17+
return count

0 commit comments

Comments
 (0)