⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2119786_ac_30ms_408k.c

📁 北大大牛代码 1240道题的原代码 超级权威
💻 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 + -