https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWuSgKpqmooDFASy
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken()); // 부먹 왕국의 도시 수
int D = Integer.parseInt(st.nextToken()); // 이동 제한 거리
int[] kingdom = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++)
kingdom[i] = Integer.parseInt(st.nextToken());
int count = 0; // 이동거리 체크
int fix = 0; // 설치할 차원관문 개수
for (int i = 0; i < N; i++) {
count++;
if (kingdom[i] == 1 || count >= D) { // 차원관문이 있거나 최대 이동거리를 만족한 경우
if (count >= D && kingdom[i] != 1)
fix += 1;
count = 0;
continue;
}
}
System.out.println(fix);
}
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] 정올 1037 오류교정 (0) | 2021.08.28 |
---|---|
[Algorithm] SWEA 6485 삼성시의 버스 노선 (0) | 2021.08.28 |
[Algorithm] SWEA 5356 의석이의 세로로 말해요 (0) | 2021.08.27 |
[Algorithm] 백준 12927 배수 스위치 (0) | 2021.08.27 |
[Algorithm] SWEA 7236 저수지의 물의 총 깊이 구하기 (0) | 2021.08.26 |