SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
www.swexpertacademy.com
#include <iostream>
#include <ios>
#include <algorithm>
using namespace std;
int T, N, M, result;
int map[15][15];
int getResult();
int getFliesCnt(int startY, int startX);
int main() {
cin.tie(0); ios::sync_with_stdio(0);
cin >> T;
for (int testCase = 1; testCase <= T; testCase++) {
result = 0;
cin >> N >> M;
for (int y = 0; y < N; y++) {
for (int x = 0; x < N; x++) {
cin >> map[y][x];
}
}
cout << '#' << testCase << ' ' << getResult() << "\n";
}
return 0;
}
int getResult() {
for (int y = 0; y <= N - M; y++) {
for (int x = 0; x <= N - M; x++) {
result = max(result, getFliesCnt(y, x));
}
}
return result;
}
int getFliesCnt(int startY, int startX) {
int fliesCnt = 0;
for (int y = startY; y < startY + M; y++) {
for (int x = startX; x < startX + M; x++) {
fliesCnt += map[y][x];
}
}
return fliesCnt;
}
'알고리즘 > SWEA' 카테고리의 다른 글
[SWEA] 1954. 달팽이 숫자 (0) | 2019.04.21 |
---|---|
[SWEA] 1926. 간단한 369게임 (0) | 2019.04.17 |
[SWEA] 2005. 파스칼의 삼각형 (0) | 2019.04.17 |
[SWEA] 1940. 가랏! RC카! (0) | 2019.04.17 |
[SWEA] 1961. 숫자 배열 회전 (0) | 2019.04.16 |
댓글