Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8bbad4

Browse files
issue sowon-dev#44 2565 전깃줄
1 parent 58fa9a6 commit f8bbad4

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎src/backjoon/_2565.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/2565
3+
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.util.Arrays;
8+
import java.util.Comparator;
9+
import java.util.StringTokenizer;
10+
11+
public class _2565 {
12+
public static void main(String[] args) throws IOException {
13+
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
int N = Integer.parseInt(br.readLine());
16+
17+
int[][] firstWire = new int[N][2];
18+
int[] dp = new int[N];
19+
20+
StringTokenizer st;
21+
for(int i = 0; i < firstWire.length; i++) {
22+
st = new StringTokenizer(br.readLine()," ");
23+
firstWire[i][0] = Integer.parseInt(st.nextToken());
24+
firstWire[i][1] = Integer.parseInt(st.nextToken());
25+
}
26+
27+
// 왼쪽 전봇대를 기준으로 2차원 배열 정렬
28+
Arrays.sort(firstWire, new Comparator <int[]>() {
29+
@Override
30+
public int compare(int[] o1, int[] o2) {
31+
return o1[0] - o2[0];
32+
}
33+
});
34+
35+
for(int i=0; i<dp.length; i++){
36+
dp[i] = 1;
37+
for(int j=0; j<i; j++){
38+
if(firstWire[i][1] > firstWire[j][1]){
39+
dp[i] = Math.max(dp[i], dp[j]+1);
40+
}
41+
}
42+
}
43+
44+
int max = 0;
45+
for(int i=0; i<N; i++){
46+
max = Math.max(max, dp[i]);
47+
}
48+
49+
// 전체 전선 개수 - 최대 설치가능 개수 = 최소 철거가능 개수
50+
System.out.println(N-max);
51+
}
52+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /