File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed
Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ """
3+ https://www.acmicpc.net/problem/1253
4+ [조건]
5+ - 배열 내 다른 원소들의 합으로 나타낼 수 있음
6+ - 유형 : two pointer
7+ -> Answer = a+b
8+ - 정렬
9+ - a, b < Answer => 음수일 경우에는 아님
10+ - left_point , right_point
11+ 예외
12+ 1. 중복 원소 존재할 경우
13+ 6
14+ 1 3 2 1 4 4
15+ - 2,3, 4, 4
16+ 2. 1개
17+ 1
18+ 3
19+ -> 0
20+ 3. A = 0 일떄
21+ 3
22+ 0 0 0
23+
24+ 2
25+ 0 0
26+ 4.
27+ 3
28+ 1 1 1
29+
30+ 6
31+ 1 1 2 2 3 6
32+ -> 2,2,3
33+
34+ # 음수요 ?
35+ 4
36+ -1 1 2 3
37+ 2
38+ # 유형 : 이분분할 , two pointer ,
39+ # 알아야 하는 사실
40+ # 이분 탐색은 target에 대해 작을때 , 클때 , 같을떄 처리 과정을 다르게 둬야 함
41+
42+ """
43+
44+ import sys
45+
46+ n = int (sys .stdin .readline ())
47+ # 조합 재료들 배열로 입력 받기 & 오름 차순 정렬
48+ board = sorted (list (map (int ,sys .stdin .readline ().split ())))
49+ good = 0 # 좋은 수 개수
50+ #1. two pointer - 양쪽 끝에서 시작
51+ for i in range (n ) :
52+ target = board [i ]
53+ left = 0 ; right = n - 1
54+ while left < right : # 서로 다른 수를 가르킨다
55+ if target == (board [left ] + board [right ]) :
56+ # left 와 right 가 각각 target을 가르킬때 -> 각자 진행 방향으로 이동
57+ if left == i :
58+ left += 1
59+ elif right == i :
60+ right -= 1
61+ else :
62+ good += 1
63+ break
64+ elif target < (board [left ] + board [right ]) : # target이 합보다 작을떄
65+ right -= 1
66+ else : # target이 합보다 클때
67+ left += 1
68+ print (good )
You can’t perform that action at this time.
0 commit comments