Advertisement
hwanil

Untitled

Jan 12th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<memory.h>
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int arr[21][21];
  7. int N, M;
  8.  
  9. int oper(int k) {
  10.     return (k*k) + (k - 1)*(k - 1);
  11. }
  12. int main() {
  13.  
  14.     int T;
  15.  
  16.     scanf("%d", &T);
  17.  
  18.     for (int test = 1; test <= T; test++) {
  19.         memset(arr, 0, sizeof(arr));
  20.         scanf("%d %d", &N, &M);
  21.         for (int i = 0; i < N; i++) {
  22.             for (int j = 0; j < N; j++) {
  23.                 scanf("%d", &arr[i][j]);
  24.             }
  25.         }
  26.  
  27.         int cnt;
  28.         int maxnum = -1;
  29.         int ans = -1;
  30.         for (int i = 0; i < N; i++) {
  31.             for (int j = 0; j < N; j++) {
  32.                 for (int k = 1; k <= 2 * N; k++) {
  33.                     cnt = 0;
  34.                     for (int y = 0; y < N; y++) {
  35.                         for (int x = 0; x < N; x++) {
  36.  
  37.                             //집 개수
  38.                             if (arr[y][x] == 1 && abs(i - y) + abs(j - x) < k) {
  39.                                 cnt++;
  40.                             }
  41.                         }
  42.                     }
  43.                     if (cnt*M >= oper(k) && ans < cnt) {
  44.                         ans = cnt;
  45.                     }
  46.                    
  47.                 }
  48.             }
  49.         }
  50.         printf("#%d %d\n",test,ans);
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement