1 // ConsoleApplication4.cpp : 定义控制台应用程序的入口点。 2 // 3 #include "stdafx.h" 4 #include <iostream> 5 #include <string> 6 7 8 using namespace std; 9 10 int N = 4; 11 int M = 4; 12 int a[4][4] = { {0, 0, 0, 0}, 13 {1, 1, 1, 1}, 14 {1, 1, 1, 1}, 15 {0, 1, 1, 1} }; 16 17 18 int max = 0; 19 int L = 0; 20 21 22 int main(void) 23 { 24 for (int i = 0; i < N; ++i) 25 { 26 for (int j = 0; j < M; ++j) 27 { 28 L = 0; 29 for (int n = i; n < N; ++n) 30 { 31 if (n - i>L) 32 { 33 break; 34 } 35 for (int m = j; m < M; ++m) 36 { 37 if (a[n][m] == 0) 38 { 39 if (m == j) 40 { 41 int temp = ((n - i )>(m - j)) ? (m - j) : (n - i); 42 L = ((n - i)>(m - j)) ? (n - i) : (m - j); 43 if (temp>max) 44 max = temp; 45 break; 46 } 47 else 48 { 49 int temp = ((n - i + 1)>(m - j)) ? (m - j) : (n - i + 1); 50 L = ((n - i + 1) > (m - j)) ? (n - i + 1) : (m - j); 51 if (temp>max) 52 max = temp; 53 break; 54 } 55 56 } 57 else if (m == M - 1) 58 { 59 int temp = ((n - i + 1) > (m - j + 1)) ? (m - j + 1) : (n - i + 1); 60 L = ((n - i + 1) > (m - j + 1)) ? (n - i + 1) : (m - j + 1); 61 if (temp>max) 62 max = temp; 63 break; 64 } 65 } 66 } 67 } 68 } 69 cout << max << endl; 70 71 return 0; 72 }