Skip to content

Commit 0c2503c

Browse files
committed
feat: 4월 3주차 발제 자료 업로드
1 parent 2f7766e commit 0c2503c

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
N = int(input())
2+
sol = list(map(int, input().split()))
3+
sol.sort()
4+
5+
result = [1000000000, 1000000000, 1000000000]
6+
for k in range(N):
7+
i = k + 1
8+
j = N - 1
9+
while i < j:
10+
if abs(sol[i] + sol[j] + sol[k]) < abs(sum(result)):
11+
result = [sol[k], sol[i], sol[j]]
12+
13+
if sol[i] + sol[j] + sol[k] > 0:
14+
j -= 1
15+
elif sol[i] + sol[j] + sol[k] < 0:
16+
i += 1
17+
else:
18+
break
19+
20+
print(*result)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## 🚀4월 3주차 (4/21) 스터디 발제 주제: Two Pointer, Binary Search
2+
> 발제자: 조윤상 (@YoonYn9915)
3+
4+
> [!NOTE]
5+
> 주제: Two Pointer, Binary Search
6+
7+
### 🗂️ 스터디 자료
8+
- PDF: [바로가기
9+
](Study_BOJ_2240.pdf)
10+
11+
### 📖 문제
12+
- [백준 #2240. 두 용액](https://www.acmicpc.net/problem/2240): Two Pointer, Binary Search / 골드 5
13+
- 정답 코드: [Study_BOJ_2240_두 용액.py](Study_BOJ_1759_암호만들기.py)
14+
15+
### 💻 과제
16+
- [백준 #2473. 세 용액](https://www.acmicpc.net/problem/2473): Two Pointer, Binary Search / 골드 3
17+
- 정답 코드: [Assignment_BOJ_2473_세 용액.py](Assignment_BOJ_2473_세 용액.py)
389 KB
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
3+
N = int(sys.stdin.readline())
4+
arr = sorted(map(int, sys.stdin.readline().split()))
5+
6+
left = 0
7+
right = N - 1
8+
9+
answer = (arr[left], arr[right], abs(arr[left] + arr[right]))
10+
11+
# 투 포인터 사용해서 절대값이 0에 가장 가까운 두 값 찾기
12+
while left < right:
13+
total = arr[left] + arr[right]
14+
abs_total = abs(total)
15+
16+
if abs_total < answer[2]:
17+
answer = (arr[left], arr[right], abs_total)
18+
if abs_total == 0:
19+
break
20+
# 두 용액의 값이 0보다 크면 right를 줄여서 합을 작게 만든다
21+
if total > 0:
22+
right -= 1
23+
else:
24+
# 두 용액의 값이 0보다 작으면 left를 늘려서 합을 크게 만든다
25+
left += 1
26+
27+
print(f"{answer[0]} {answer[1]}")

0 commit comments

Comments
 (0)