📄 2119786_ac_30ms_408k.c
字号:
# include <stdio.h>
# include <string.h>
int W, H;
int ans, max;
char photo[1001][81];
int mark[1001][81];
void input()
{
int i;
scanf("%d%d",&W,&H);
for(i = 0; i < H; i++)
scanf("%s",photo[i]);
}
void dfs(int h,int w)
{
mark[h][w] = 1;
ans++;
if(h>0&&photo[h-1][w]=='*'&&!mark[h-1][w])
dfs(h-1,w);
if(h<H-1&&photo[h+1][w]=='*'&&!mark[h+1][w])
dfs(h+1,w);
if(w>0&&photo[h][w-1]=='*'&&!mark[h][w-1])
dfs(h,w-1);
if(w<W-1&&photo[h][w+1]=='*'&&!mark[h][w+1])
dfs(h,w+1);
}
void solve()
{
int i, j;
max = -1;
memset(mark,0,sizeof(mark));
for(i = 0; i < H; i++)
for(j = 0; j < W; j++)
if(photo[i][j]=='*')
{
ans = 0;
dfs(i,j);
if(ans>max)
max = ans;
}
printf("%d\n",max);
}
int main()
{
input();
solve();
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -