티스토리 뷰

1206. [S/W 문제해결 기본] 1일차 - View

swexpertacademy.com/main/code/problem/problemDetail.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

// 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) 가장 값이 조망이 확보된 수다.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
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
글 보관함