Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 코딩테스트
- 프로그래머스
- DP
- 건강
- oracle
- 알고리즘
- dfs
- 자바
- COS PRO
- 문제풀이
- 투포인터
- 문제해결
- SQL
- SWEA
- Java
- greedy
- binary search
- 이분탐색
- 백준
- 문자열
- db
- BFS
- 운동기록
- priorityqueue
- 러닝일지
- 시뮬레이션
- BOJ
- 코테
- math
- MySQL
Archives
- Today
- Total
슈콩
[BOJ] 백준 2295 세 수의 합 본문
Collections함수 binarySearch 사용: 시간 단축 용도
[문제]
https://www.acmicpc.net/problem/2295
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
for(int i=0;i<n;i++) {
arr[i] = Integer.parseInt(br.readLine());
}
List<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
list.add(arr[i] + arr[j]);
}
}
Arrays.sort(arr);
Collections.sort(list);
for(int i=n-1;i>=0;i--) {
for(int j=n-1;j>=0;j--) {
int diff = arr[i] - arr[j];
if(Collections.binarySearch(list,diff)>=0) {
System.out.println(arr[i]);
return;
}
}
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 10815 숫자 카드 (0) | 2025.09.16 |
|---|---|
| [BOJ] 백준 1654 랜선 자르기 (0) | 2025.09.16 |
| [BOJ] 백준 18870 좌표 압축 (0) | 2025.09.16 |
| [BOJ] 백준 10816 숫자 카드 2 (0) | 2025.09.16 |
| [BOJ] 백준 1920 수 찾기 (0) | 2025.09.16 |