Butterfly
#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxn = 2005;
char map[maxn][maxn];
int len1[maxn][maxn], len2[maxn][maxn];
int len3[maxn][maxn];
int main() {
int n, m;
int i, j;
char ch;
scanf("%d%d", &n, &m);
ch = getchar();
while (ch != '\n')
ch = getchar();
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
scanf("%c", &map[i][j]);
if (map[i][j] == 'X') {
len1[i][j] = len1[i - 1][j - 1] + 1;
len2[i][j] = len2[i - 1][j + 1] + 1;
len3[i][j] = len3[i - 1][j] + 1;
}
}
ch = getchar();
while (ch != '\n')
ch = getchar();
}
int d, k;
int ans = 0;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
d = min(len3[i][j], len1[i][j]);
if (d % 2 == 0)
d--;
for (k = d; k > 0 && k > ans; k -= 2) {
int tmp;
tmp = j - k + 1;
if (len3[i][tmp] >= k && len2[i][tmp] >= k) {
ans = k;
break;
}
}
}
}
printf("%d\n", ans);
return 0;
}
题解:用dp算出当前点的左上总共有几个X,算出右上总共有几个X,算出上方总共有几个X,然后暴力枚举题解链接