Skip to content

Commit 0dabfac

Browse files
committed
[Gold IV] Title: 고층 건물, Time: 100 ms, Memory: 14300 KB -BaekjoonHub
1 parent b6b9f66 commit 0dabfac

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [Gold IV] 고층 건물 - 1027
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1027)
4+
5+
### 성능 요약
6+
7+
메모리: 14300 KB, 시간: 100 ms
8+
9+
### 분류
10+
11+
수학, 브루트포스 알고리즘, 기하학
12+
13+
### 제출 일자
14+
15+
2025년 11월 16일 14:09:56
16+
17+
### 문제 설명
18+
19+
<p>세준시에는 고층 빌딩이 많다. 세준시의 서민 김지민은 가장 많은 고층 빌딩이 보이는 고층 빌딩을 찾으려고 한다. 빌딩은 총 N개가 있는데, 빌딩은 선분으로 나타낸다. i번째 빌딩 (1부터 시작)은 (i,0)부터 (i,높이)의 선분으로 나타낼 수 있다. 고층 빌딩 A에서 다른 고층 빌딩 B가 볼 수 있는 빌딩이 되려면, 두 지붕을 잇는 선분이 A와 B를 제외한 다른 고층 빌딩을 지나거나 접하지 않아야 한다. 가장 많은 고층 빌딩이 보이는 빌딩을 구하고, 거기서 보이는 빌딩의 수를 출력하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 빌딩의 수 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에 1번 빌딩부터 그 높이가 주어진다. 높이는 1,000,000,000보다 작거나 같은 자연수이다.</p>
24+
25+
### 출력
26+
27+
<p>첫째 줄에 문제의 정답을 출력한다.</p>
28+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws Exception {
6+
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
9+
int N = Integer.parseInt(br.readLine());
10+
11+
int arr[] = new int[N];
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
for(int i =0; i<N; i++) {
14+
arr[i] = Integer.parseInt(st.nextToken());
15+
}
16+
17+
int answer = 0;
18+
for(int i =0; i<N; i++) {
19+
int cnt = 0;
20+
double lean = Double.NEGATIVE_INFINITY;
21+
for(int j = i+1; j<N; j++) {
22+
double x = j-i;
23+
double y = arr[j] - arr[i];
24+
25+
double tempLean = y/x;
26+
27+
if(tempLean > lean) {
28+
lean = tempLean;
29+
cnt+=1;
30+
}
31+
}
32+
33+
lean = Double.POSITIVE_INFINITY;
34+
35+
for(int j = i-1; j>=0; j--) {
36+
double x = j-i;
37+
double y = arr[j] - arr[i];
38+
39+
double tempLean = y/x;
40+
41+
if(tempLean < lean) {
42+
lean = tempLean;
43+
cnt+=1;
44+
}
45+
}
46+
answer = Math.max(answer, cnt);
47+
}
48+
System.out.println(answer);
49+
}
50+
}
51+
52+
/*
53+
* 1 5 3 2 6 3 2 6 4 2 5 7 3 1 5
54+
*
55+
*/

0 commit comments

Comments
 (0)