首页 > 代码库 > 卫星照片

卫星照片

#include<stdio.h>
#include<string.h>
char x[76][76];
int r,c,z[5]={1,0,-1,0,1},ans1,ans2,p0,m,n;
int xmin,xmax,ymin,ymax;
void search(int a,int b)
{
	for(int t=0;t<=4;t++)
	   if(a+z[t]>-1 && a+z[t]<r && b+z[t+1]>-1 && b+z[t+1]<c && x[a+z[t]][b+z[t+1]]=='#')
	     {x[a+z[t]][b+z[t+1]]='.';search(a+z[t],b+z[t+1]);p0++;}
	if(a>xmax)xmax=a;
	if(b>ymax)ymax=b;
	if(a<xmin)xmin=a;
	if(b<ymin)ymin=b;
}
int main()
{	scanf("%d%d\n",&r,&c);
	for(int i=0;i<r;i++)
	   gets(x[i]);
	ans1=0;ans2=0;
	for(int i=0;i<r;i++) 
	   for(int j=0;j<c;j++)
	      if(x[i][j]=='#')
		     {
		     	xmin=ymin=1000;
		     	xmax=ymax=-1;
		     	p0=1;
		     	x[i][j]='.';
		     	search(i,j);
		     	if((xmax-xmin+1)*(ymax-ymin+1)==p0)
		     	   ans1++;
		     	else ans2++;
		     }   
	printf("%d\n%d",ans1,ans2);
	return 0;
}


卫星照片