题意:有一个图上全是'.',现在会放一些矩形上去,每个矩形都由'A'~'Z'组成,且不会重复,一些矩形会被另一些矩形覆盖,问位于最上方的不被覆盖的矩形是哪些,输出组成字母。按字典序输出,每个矩形长宽不少于3。
题解:直接暴力,比较矩形的对应的长和宽是否相等,需要注意最上方矩形内部一定都是'.'。
#include <stdio.h>
const int N = 105;
char m[N][N];
int r, c;
bool judge(int la) {
char ch = la + 'A';
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++)
if (m[i][j] == ch) {
int len1 = 1, len2 = 1, len3 = 1, len4 = 1;
for (int k = j + 1; k < c; k++)
if (m[i][k] == ch)
len1++;
else
break;
if (len1 < 3)
return false;
for (int k = i + 1; k < r; k++)
if (m[k][j] == ch)
len2++;
else
break;
if (len2 < 3)
return false;
for (int k = j + 1; k < c; k++)
if (m[i + len2 - 1][k] == ch)
len3++;
else
break;
if (len3 != len1)
return false;
for (int k = i + 1; k < r; k++)
if (m[k][j + len1 - 1] == ch)
len4++;
else
break;
if (len4 != len2)
return false;
for (int k1 = i + 1; k1 < i + len2 - 1; k1++)
for (int k2 = j + 1; k2 < j + len1 - 1; k2++)
if (m[k1][k2] != '.')
return false;
return true;
}
return false;
}
int main() {
while (scanf("%d%d", &r, &c) && r) {
for (int i = 0; i < r; i++)
scanf("%s", m[i]);
for (int i = 0; i < 26; i++)
if (judge(i))
printf("%c", i + 'A');
printf("\n");
}
return 0;
}