https://swexpertacademy.com/main/solvingProblem/solvingProblem.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
public class Solution {
private static int n;
private static int m;
private static int[][] fly;
private static int[][] result;
public static int flyNum (int i, int j) {
int sum = 0;
for (int x = i; x < m + i; x++) {
for (int y = j; y < m + j; y++)
sum += fly[x][y];
}
return sum;
}
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for (int t = 1; t <= T; t++) {
n = scanner.nextInt(); // 파리가 있는 영역
m = scanner.nextInt(); // 파리채 크기
fly = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
fly[i][j] = scanner.nextInt();
}
}
result = new int[n-m+1][n-m+1];
int max = 0;
for (int i = 0; i < n-m+1; i++) {
for (int j = 0; j < n-m+1; j++) {
result[i][j] = flyNum(i, j);
if (result[i][j] > max)
max = result[i][j];
}
}
System.out.println("#" + t + " " + max);
}
scanner.close();
}
}'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
| [Algorithm] 백준 2493 탑 (0) | 2021.08.05 |
|---|---|
| [Algorithm] 백준 5622 다이얼 (0) | 2021.08.04 |
| [Algorithm] SWEA 1873 상호의 배틀필드 (0) | 2021.08.04 |
| [Algorithm] SWEA 1208 Flatten (0) | 2021.08.04 |
| [Algorithm] SWEA 1289 원재의 메모리 복구하기 (0) | 2021.08.04 |