반응형
2470
https://www.acmicpc.net/problem/2470
[정답]
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <algorithm>
using namespace std;
#define ABS(a) ((a) <0? -(a):(a))
int n;
int s, e;
int a[100001] = { 0, };
int res = (int)21e8;
int ansA, ansB;
void input() {
scanf("%d", &n);
s = 0;
e = n - 1;
for (int i = 0; i < n; i++) scanf("%d", a + i);
sort(a, a + n);
}
int main(void) {
int temp;
input();
while (s < e) {
temp = a[s] + a[e];
if (ABS(temp) < res) {
res = ABS(temp);
ansA = a[s];
ansB = a[e];
}
if (res == 0) break;
else if (temp < 0) s++;
else e--;
}
cout << ansA << " " << ansB;
return 0;
}
|
cs |
.
.
.
[풀이]
투포인터 문제다.
p.s.
오랜만에 글을 올린다.
백준 문제풀이는 계속 해왔고, 이전에 푼 문제들을 꾸준히 올려보겠다.
C++ 전문이 되어버렸다만..
반응형
'백준 문제풀이' 카테고리의 다른 글
| [백준 : 11195] C++ : Peragrams (0) | 2025.10.21 |
|---|---|
| [백준 : 18111] C++ : 마인크래프트 (0) | 2025.10.20 |
| [백준 : 10699] 파이썬 : 오늘 날짜 (0) | 2022.03.21 |
| [백준 2530] 파이썬 : 인공지능 시계 (0) | 2022.03.18 |
| [백준 1158] 파이썬 : 요세푸스 문제 (0) | 2022.03.16 |