Skip to content

Commit 08829fe

Browse files
committed
1028
1 parent 8bf5256 commit 08829fe

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BOJ/gold/BOJ13023/src/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

22
import java.io.IOException;
33
import java.util.ArrayList;
4-
import java.util.List;
54
import java.util.Scanner;
6-
import java.util.Stack;
5+
76

87

98
public class Main {

BOJ/gold/BOJ2110/BOJ2110.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

BOJ/gold/BOJ2110/src/Main.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.Arrays;
2+
import java.util.Scanner;
3+
4+
public class Main {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
int N= sc.nextInt();
8+
int C=sc.nextInt();
9+
int [] house=new int[N];
10+
for (int i = 0; i < N ; i++) {
11+
house[i]= sc.nextInt();
12+
}
13+
Arrays.sort(house);
14+
//지점간의 거리 최소와 최대 설정
15+
int left=1;
16+
int right=house[house.length-1]-house[0];
17+
int answer=0;
18+
while (left<=right){
19+
int mid = (left+right)/2;
20+
int prev=house[0];
21+
int Setting=1;
22+
23+
//Setting가 1인 이유
24+
//https://www.acmicpc.net/board/view/31633
25+
//직전에 설치했던 집과의 거리를 측정해나가므로
26+
//두 공유기 사이의 최대 거리가 커질수록
27+
//설치할 수 있는 공유기의 갯수가 작아진다는 것이다
28+
//최대한 왼쪽에 설치할수록, 그 다음 공유기는 왼쪽에 설치할 수 있고,
29+
//더 많이 설치할 수 있게 됩니다.
30+
31+
for (int i = 1; i < house.length; i++) {
32+
if(mid<=house[i]-prev) {
33+
Setting++;
34+
prev=house[i];
35+
}
36+
37+
38+
}
39+
if(Setting>=C){
40+
answer=Math.max(answer,mid);
41+
left=mid+1;
42+
}else{
43+
right=mid-1;
44+
}
45+
}
46+
System.out.println(answer);
47+
}
48+
}

0 commit comments

Comments
 (0)