-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1027.java
More file actions
63 lines (56 loc) · 2.11 KB
/
Copy path1027.java
File metadata and controls
63 lines (56 loc) · 2.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
https://www.acmicpc.net/submit/1027/68560215
백준 1027 고층 건물
빌딩의 갯수 n과 각 빌딩의 높이가 배열로 주어졌을 때 (빌딩은 거리를 따라 일자로 지어져있다.)
옥상에서 볼 수 있는 빌딩의 최대 갯수를 출력하는 문제
빌딩a에서 b빌딩이 보이려면 둘 사이의 건물들은 두 빌딩을 잇는 선분을 넘지 않아야 한다.
n은 최대 50개 이다. 반복문을 사용해서 각 건물을 확인하면 된다.
선분을 정의하고 (ax + b) 두빌딩 사이의 모든 건물에대해 height < ax + b를 만족하는지 확인
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(scan.readLine());
StringBuilder sb = new StringBuilder();
// input
int n = Integer.parseInt(st.nextToken());
int[] building = new int[n];
st = new StringTokenizer(scan.readLine());
for(int i=0; i<n; i++){
building[i] = Integer.parseInt(st.nextToken());
}
// solution
int[] count = new int[n];
double a, b; // y = ax + b
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(j == i) continue;
a = (double)(building[i] - building[j]) / (i - j);
b = building[i] - a*i;
boolean visable = true;
int k = (i < j ? i : j);
int end = (i > j ? i : j);
while(k != end-1){
k++;
if(building[k] >= a*k+b){
visable = false;
break;
}
}
if(visable) {
count[i]++;
}
}
}
// output
int max = count[0];
for(int i=1; i<n; i++)
if(count[i] > max) max = count[i];
System.out.println(max);
}
}