#include <iostream> #include <cstring> #include <queue> using namespace std; int row,col; int vis[1000][1000],farm[1000][1000]; int dir[8][2] = { {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1} };//移动的方向 struct Position { int x, y; int grass; }; bool is_legal(Position a)//判断这个位置是否合法 { return (!vis[a.x][a.y] && a.x >=0 && a.x < row && a.y >=0 && a.y < col); } int bfs(Position p) { int grass = 0; queue<Position> q; q.push(p); while(!q.empty()) { Position cur = q.front(); q.pop(); for(int i = 0; i < 8;i++)//尝试这8个点,如果合法,则压入队列 { Position temp; temp.x = cur.x+dir[i][0]; temp.y = cur.y+dir[i][1]; if(is_legal(temp) && farm[temp.x][temp.y]) { grass++; vis[temp.x][temp.y] = 1; q.push(temp); } } } return grass; } int main() { int i, j,max = -1; memset(vis,0,sizeof(vis)); memset(farm,0,sizeof(farm)); cin>>col>>row; for(i = 0;i < row;i++) for(j = 0;j < col;j++) { char temp; cin>>temp; farm[i][j] = (temp == '.') ? 1 : 0; } for(i = 0;i < row;i++) //对整个草地各个点进行广搜,求出grass最大值 for(j = 0;j < col;j++) { if(!vis[i][j] && farm[i][j]) { Position p; p.x = i; p.y = j; p.grass = bfs(p); max = (p.grass > max) ? p.grass : max; } } cout<<max<<endl; return 0; }