본문 바로가기
Java/SW Expert Academy

2001. 파리퇴치

by GLOWWW 2021. 1. 5.
package oSWExpertAcademy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//파리퇴치 
public class D2_04 {
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int tcase = Integer.parseInt(br.readLine());
            for(int i=1; i<=tcase; i++) {
                String[] arr = br.readLine().split(" ");
                int N = Integer.parseInt(arr[0]);
                int M = Integer.parseInt(arr[1]);
                int max = 0;
                int[][] area = new int[N][N];
                //area에 파리갯수 넣기 
                for(int x = 0; x<N; x++) {
                    String[] flys = br.readLine().split(" ");
                    for(int y=0; y<N; y++) {
                        area[x][y] = Integer.parseInt(flys[y]);
                    }
                }
                for(int x=0; x<=N-M; x++) {
                    for(int y=0; y<=N-M; y++) {
                        //죽은 파리의 수 합 
                        int sum = 0;
                        for(int a=x; a<x+M; a++) {
                            for(int b=y; b<y+M; b++) {
                                sum += area[a][b];
                            }
                        }
                        if(max < sum) {
                            max = sum;
                        }
                    }
                }
                System.out.println("#"+i+" "+max);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

'Java > SW Expert Academy' 카테고리의 다른 글

2029. 몫과 나머지 출력하기  (0) 2021.01.05
2043. 서랍의 비밀번호  (0) 2021.01.05
2005. 파스칼의 삼각형  (0) 2021.01.05
1926. 간단한 369게임  (0) 2021.01.05
2063. 중간값 찾기  (0) 2021.01.05

댓글