Start: Dec, 04, 2016 12:00:00
杭州师范大学第十届程序设计竞赛—正式
End: Dec, 04, 2016 17:00:00
Time elapsed:
Time remaining:

Problem_ID: J
Result: Accepted
Time: 2ms
Memory: 1728kB
In contest: 1075

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int judge(int x, int y, int n, int m, char d[101][101]);
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	char d[101][101];
	for(int i=0; i<n; i++)
	{
		getchar();
		for(int j=0; j<m; j++)
		{
			scanf("%c", &d[i][j]);
		}
	}
	int num=0;
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<m; j++)
		{
			if(d[i][j]=='.')
				num+=judge(i, j, n, m, d);
		}
	}
	printf("%d\n", num);
	
	
}
int judge(int x, int y, int n, int m, char d[101][101]){
	int num=0, a=1,b=1,c=1,e=1;
	if(y!=0&&x!=0&&x!=n-1&&y!=m-1)
	{
		d[x][y]='*';
		if(d[x-1][y]=='*' &&d[x][y-1]=='*' && d[x+1][y]=='*' && d[x][y+1]=='*')
		{
			num++;
		}
		if(d[x-1][y]!='*'){
			a=0;
			a=judge(x-1, y, n, m, d);
		}
		if(d[x+1][y]!='*'){
			b=0;
			b=judge(x+1, y, n, m, d);
		}
		if(d[x][y-1]!='*'){
			c=0;
			c=judge(x, y-1, n, m, d);
		}
		if(d[x][y+1]!='*'){
			e=0;
			e=judge(x, y+1, n, m, d);
		}
		if(a==1&&b==1&&c==1&&e==1)
			num=1;
	}
	return num;
}