Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package study;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SE2001 {
  6.  
  7.     static int testCaseCnt;//testcase 개수
  8.     static int n;//map크기
  9.     static int m;//파리채 크기
  10.     static int[][] map = new int[15][15];//최대 맵 크기로 고정
  11.     static int answer;//최대 파리합
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner in = new Scanner(System.in);
  15.  
  16.         testCaseCnt = in.nextInt();//testcase 개수 입력
  17.  
  18.         for (int testCase = 1; testCase <= testCaseCnt; testCase++) {
  19.            
  20.             init();//변수 초기화
  21.  
  22.             n = in.nextInt();//map 크기 입력
  23.             m = in.nextInt();//파리채 크기 입력
  24.  
  25.             //map 입력
  26.             for (int i = 0; i < n; i++) {
  27.                 for(int j = 0; j < n; j++){
  28.                     map[i][j] = in.nextInt();
  29.                 }
  30.             }
  31.            
  32.             execute();//실행
  33.            
  34.             System.out.println("#" + testCase + " " + answer);
  35.         }
  36.     }
  37.  
  38.     public static void init() {
  39.         n = 0;
  40.         m = 0;
  41.         answer = 0;
  42.     }
  43.  
  44.     public static void execute() {
  45.         //파리채 크기가 map 밖으로 나가지 않게 인덱스 조절하면서 i, j 이동
  46.         for(int i = 0; i < n - m + 1; i++){
  47.             for(int j = 0; j < n - m + 1; j++){
  48.                 int sum = 0;//파리합 변수
  49.                
  50.                 //파리채 크기만큼 더하기
  51.                 //i, j 가 위치한 곳에서 파리채 크기만큼 누적합을 구한다
  52.                 for(int p = i; p < i + m; p++){
  53.                     for(int q = j; q < j + m; q++){
  54.                         sum += map[p][q];//파리 누적합
  55.                     }
  56.                 }
  57.                
  58.                 //max 값 갱신
  59.                 answer = Math.max(answer, sum);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement