http://acm.pku.edu.cn/JudgeOnline/problem?id=3051
很简单的floodfill
Source Code
Problem: 3051 |
|
User: lovecanon |
Memory: 284K |
|
Time: 47MS |
Language: C |
|
Result: Accepted |
-
#include<stdio.h>
char a[1001][81];
int R,C,sum,max=0;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
void solve(int r,int c)
{
int i,nextr,nextc;
a[r][c]='.';sum++;
for(i=0;i<4;i++)
{
nextr=r+dx[i];
nextc=c+dy[i];
if(nextr>=0&&nextr<R&&nextc>=0&&nextc<C&&a[nextr][nextc]=='*')
solve(nextr,nextc);
}
return ;
}
int main()
{
int i,j;
scanf("%d%d",&C,&R);getchar();
for(i=0;i<R;i++)
{
for(j=0;j<C;j++)
a[i][j]=getchar();
getchar();
}
for(i=0;i<R;i++)
for(j=0;j<C;j++)
{
if(a[i][j]=='*')
{
sum=0;solve(i,j);
if(sum>max) max=sum;
}
}
printf("%d\n",max);
return 0;
}