哞加密
#include<iostream>
using namespace std;
char s[55][55];
bool t[55][55];
int n, m;
int ans = 0;
int dx[8] = {1, 0, 1, 1, 0, -1, -1, -1};
int dy[8] = {0, 1, 1, -1, -1, 0, -1, 1};
int find(char a, char b)
{
int res = 0;
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m; j ++)
{
for(int k = 0; k < 8; k ++)
{
int x = dx[k] + i, y = dy[k] + j;
int xx = dx[k] * 2 + i, yy = dy[k] * 2 + j;
if( x >= 1 && x <= n && y >= 1 && y <= m && xx >= 1 && xx <= n && yy >= 1 && yy <= m)
{
if(s[i][j] == a && s[x][y] == b && s[x][y] == s[xx][yy] && s[x][y] != s[i][j])res ++;
}
}
}
}
return res;
}
int main()
{
cin >> n >>m;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)cin >>s[i][j];
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m; j ++)
{
for(int k = 0; k < 8; k ++)
{
int x = dx[k] + i, y = dy[k] + j;
int xx = dx[k] * 2 + i, yy = dy[k] * 2 + j;
if( x >= 1 && x <= n && y >= 1 && y <= m && xx >= 1 && xx <= n && yy >= 1 && yy <= m)
{
if(s[xx][yy] == s[x][y] && s[x][y] != s[i][j] && s[i][j] != 'M' && s[x][y] != 'O')
{
ans = max(ans, find(s[i][j],s[x][y]));
// if(ans != 0)cout << i << " "<<j<<endl;
}
}
}
}
}
cout << ans <<endl;
return 0;
}
注意没有字母是映射自身的