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
- Java
- 알고리즘
- 백준
- BOJ
- DP
- SWEA
- 자바
- 코테
- 문제풀이
- greedy
- math
- oracle
- 건강
- 러닝일지
- BFS
- db
- 이분탐색
- 시뮬레이션
- priorityqueue
- 문제해결
- SQL
- 운동기록
- 코딩테스트
- 문자열
- 프로그래머스
- COS PRO
- dfs
- MySQL
- 투포인터
- binary search
Archives
- Today
- Total
슈콩
[BOJ] 백준 2110 공유기 설치 본문
[문제]
https://www.acmicpc.net/problem/2110
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n,c;
static int[] home;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());
home = new int[n];
for(int i=0;i<n;i++) {
home[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(home);
int start = 0;
int end = home[n-1] - home[0];
while(start<=end) {
int mid = (start+end) / 2;
if(can(mid)) {
start = mid + 1;
}
else {
end = mid - 1;
}
}
System.out.println(end);
}
private static boolean can(int mid) {
int cnt = 1;
int origin = home[0];
for(int i=1;i<n;i++) {
if(home[i]-origin >= mid) {
cnt++;
origin = home[i];
}
}
if(cnt>=c) {
return true;
}
return false;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 14503 로봇 청소기 (2) | 2025.09.22 |
|---|---|
| [BOJ] 백준 2143 두 배열의 합 (2) | 2025.09.21 |
| [BOJ] 백준 18869 멀티버스 Ⅱ (0) | 2025.09.20 |
| [BOJ] 백주 1822 차집합 (0) | 2025.09.19 |
| [BOJ] 백준 14502 연구소 (2) | 2025.09.19 |