티스토리 뷰
1206. [S/W 문제해결 기본] 1일차 - View
swexpertacademy.com/main/code/problem/problemDetail.do
// 210204
import java.io.*;
import java.util.*;
public class Solution_D3_1206_View {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int tc=1; tc<=10; tc++) {
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
Integer[] arr = new Integer[N];
for(int i=0; i<N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int sum = 0;
for (int i=2; i<N-2; i++) {
int min = 255;
int l1 = arr[i]-arr[i-2];
if (l1 <= 0) continue;
else if (min > l1) min=l1;
int l2 = arr[i]-arr[i-1];
if (l2 <= 0) continue;
else if (min > l2) min=l2;
int r1 = arr[i]-arr[i+1];
if (r1 <= 0) continue;
else if (min > r1) min=r1;
int r2 = arr[i]-arr[i+2];
if (r2 <= 0) continue;
else if (min > r2) min=r2;
sum += min;
}
System.out.println("#" + tc + " " + sum);
}
}
}
1. 양 옆의 건물들과의 높이 차이가 모두 양수일 때
2. 그 차이 (4개)들 중 가장 값이 조망이 확보된 층 수다.
'코딩테스트 > SW Expert' 카테고리의 다른 글
[SWEA] 5432. 쇠막대기 자르기 (0) | 2021.02.04 |
---|---|
[SWEA] 1218. [S/W 문제해결 기본] 4일차 - 괄호 짝짓기 (0) | 2021.02.04 |
[SWEA] 1210. [S/W 문제해결 기본] 2일차 - Ladder1 (0) | 2021.02.04 |
[SWEA] 1983. 조교의 성적 매기기 (0) | 2021.02.01 |
[SWEA] 1289. 원재의 메모리 복구하기 (0) | 2021.02.01 |
댓글